diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-12-16 13:02:34 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-12-16 13:02:34 +1300 |
commit | c1046bab2e6681f5e4714178d6cc1cd16f067382 (patch) | |
tree | 13fa25350bf02e046e7e03cf0e546f428261ab81 | |
parent | 4aa2aee51b54cb8988d87a01d1a3b9a0d90bb8bf (diff) | |
download | monitoring-plugin-perl-c1046bab2e6681f5e4714178d6cc1cd16f067382.tar.gz |
Move Getopt param/reqd defs into dedicated hash
This shift and its comment makes what the values of the hashref passed
to the validate() methods mean clearer, and also allows the use of the
keys as a means of determining whether arg() was passed its definition
in the array or hash format in a separate commit.
-rw-r--r-- | lib/Monitoring/Plugin/Getopt.pm | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/Monitoring/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm index 262e3c8..ca1cb61 100644 --- a/lib/Monitoring/Plugin/Getopt.pm +++ b/lib/Monitoring/Plugin/Getopt.pm | |||
@@ -382,15 +382,18 @@ sub arg | |||
382 | my $self = shift; | 382 | my $self = shift; |
383 | my %args; | 383 | my %args; |
384 | 384 | ||
385 | # Param name to required boolean | ||
386 | my %params = ( | ||
387 | spec => 1, | ||
388 | help => 1, | ||
389 | default => 0, | ||
390 | required => 0, | ||
391 | label => 0, | ||
392 | ); | ||
393 | |||
385 | # Named args | 394 | # Named args |
386 | if ($_[0] =~ m/^(spec|help|required|default|label)$/ && scalar(@_) % 2 == 0) { | 395 | if ($_[0] =~ m/^(spec|help|required|default|label)$/ && scalar(@_) % 2 == 0) { |
387 | %args = validate( @_, { | 396 | %args = validate( @_, { %params }); |
388 | spec => 1, | ||
389 | help => 1, | ||
390 | default => 0, | ||
391 | required => 0, | ||
392 | label => 0, | ||
393 | }); | ||
394 | } | 397 | } |
395 | 398 | ||
396 | # Positional args | 399 | # Positional args |