diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-12-16 13:25:34 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-12-16 13:25:34 +1300 |
commit | c3f2a7cd7313868166ba205e9eff2b8be6a36ea4 (patch) | |
tree | 018986888d2b8bee072c0341c62f126c5aa860f0 | |
parent | 40d5fbea30c310004233ef4cd3e570c351c54233 (diff) | |
download | monitoring-plugin-perl-c3f2a7c.tar.gz |
Refactor positional arg parsing for Getopt::arg()
Define the expected order of parameters by key in an array, and then
apply hash slices to validate and assign the arguments including their
required flags in one swoop, again hinging on the parameter definitions
established in c1046ba.
-rw-r--r-- | lib/Monitoring/Plugin/Getopt.pm | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/lib/Monitoring/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm index feee002..048b0ef 100644 --- a/lib/Monitoring/Plugin/Getopt.pm +++ b/lib/Monitoring/Plugin/Getopt.pm | |||
@@ -398,14 +398,8 @@ sub arg | |||
398 | 398 | ||
399 | # Positional args | 399 | # Positional args |
400 | else { | 400 | else { |
401 | my @args = validate_pos(@_, 1, 1, 0, 0, 0); | 401 | my @order = qw(spec help default required label); |
402 | %args = ( | 402 | @args{@order} = validate_pos(@_, @params{@order}); |
403 | spec => $args[0], | ||
404 | help => $args[1], | ||
405 | default => $args[2], | ||
406 | required => $args[3], | ||
407 | label => $args[4], | ||
408 | ); | ||
409 | } | 403 | } |
410 | 404 | ||
411 | # Add to private args arrayref | 405 | # Add to private args arrayref |