[monitoring-plugin-perl] Refactor positional arg parsing for Getopt::arg()

Tom Ryder git at monitoring-plugins.org
Fri Dec 22 11:50:07 CET 2017


 Module: monitoring-plugin-perl
 Branch: master
 Commit: c3f2a7cd7313868166ba205e9eff2b8be6a36ea4
 Author: Tom Ryder <tom at sanctum.geek.nz>
   Date: Sat Dec 16 13:25:34 2017 +1300
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugin-perl/commit/?id=c3f2a7c

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.

---

 lib/Monitoring/Plugin/Getopt.pm | 10 ++--------
 1 file 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
 
   # Positional args
   else {
-    my @args = validate_pos(@_, 1, 1, 0, 0, 0);
-    %args = (
-      spec      => $args[0],
-      help      => $args[1],
-      default   => $args[2],
-      required  => $args[3],
-      label     => $args[4],
-    );
+    my @order = qw(spec help default required label);
+    @args{@order} = validate_pos(@_, @params{@order});
   }
 
   # Add to private args arrayref



More information about the Commits mailing list