From c3f2a7cd7313868166ba205e9eff2b8be6a36ea4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 16 Dec 2017 13:25:34 +1300 Subject: 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 -- cgit v1.2.3-74-g34f1