[monitoring-plugin-perl] Change arg() param type detect to key exists check

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


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

Change arg() param type detect to key exists check

Use the parameter label definitions from commit c1046ba to simplify the
block of code that checks whether the first argument passed to arg() is
one of the known param keys, rather than using a regular expression with
alternating expression.

This is more compact, may be marginally faster, and will make adding new
parameters to this method more straightforward in future, avoiding the
situation corrected in commit 4aa2aee.

---

 lib/Monitoring/Plugin/Getopt.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/Monitoring/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm
index ca1cb61..feee002 100644
--- a/lib/Monitoring/Plugin/Getopt.pm
+++ b/lib/Monitoring/Plugin/Getopt.pm
@@ -392,7 +392,7 @@ sub arg
   );
 
   # Named args
-  if ($_[0] =~ m/^(spec|help|required|default|label)$/ && scalar(@_) % 2 == 0) {
+  if (exists $params{$_[0]} && scalar(@_) % 2 == 0) {
     %args = validate( @_, { %params });
   }
 



More information about the Commits mailing list