[Nagiosplug-devel] Nagios:Plugin feedback
Gavin Carr
gavin at openfusion.com.au
Fri Jan 19 07:08:06 CET 2007
On Fri, Jan 19, 2007 at 12:09:51AM -0500, Thomas Guyot-Sionnest wrote:
> Oh BTW I meant :
>
> check => &$namecheck
You meant: check => \&namecheck
> Though I think you can also do this (right?):
>
> check => sub { yada yada yada; if true return 1; return 0 }
Right.
> I'm not good at that kind of Perl programming, but can you check
> whenever you get a scalar or an array?
Sure.
> A good compromise would be:
>
> if $failure is a scalar, then just test the sub ($check). if test fails
> (return 0) exit with $failure text.
>
> if $failure is an array, test the sub ($ret being the return code). If
> $failure[$ret] is defined, exit with failure[$ret] text
>
> I.e.:
>
> $p->add_arg(
> spec => 'name|n=s',
> help => qq{-n, --name=<name>)
> check => sub { if bad return 1; if invalid return 2; return 0 },
> failure => (undef, 'Bad name', 'Invalid name'),
> );
>
> What do you think? Do you have a better idea?
I guess I'm not sure this actually adds much. Why not just do your checks
after the argument parsing:
die "Bad name\n" if bad($p->name);
die "Invalid name\n" if invalid($p->name);
etc.?
Cheers,
Gavin
--
Gavin Carr
- http://www.openfusion.com.au - Linux, Perl, and Web Consulting
- http://www.xool.com.au - Xool, Australian property search engine
* Fashion is a variable, but style is a constant - Programming Perl
More information about the Devel
mailing list