From ca6e3454cc7887daf269a84539bb6403a4610890 Mon Sep 17 00:00:00 2001 From: Nigel Horne Date: Tue, 28 Jan 2025 08:03:50 -0500 Subject: [PATCH] Better error message when discarding argument --- Changes | 2 +- README | 2 +- README.md | 5 ++++- lib/CGI/Info.pm | 11 +++++++---- t/gv.t | 4 ++-- t/strict.t | 1 - 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Changes b/Changes index dc99e96..d210520 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,6 @@ Revision history for CGI-Info -0.89 +0.89 Tue Jan 14 15:45:16 EST 2025 Fix http://www.cpantesters.org/cpan/report/048c5109-6c77-1014-8029-e79fc7de0390 0.88 Mon Jan 13 09:33:24 EST 2025 diff --git a/README b/README index ee36fb5..0ee0ddc 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -CGI-Info Version 0.88 +CGI-Info Version 0.89 INSTALLATION diff --git a/README.md b/README.md index d8e3aa0..11c8d51 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +CGI-Info +======== + -[![Travis Status](https://travis-ci.org/nigelhorne/CGI-Info.svg?branch=master)](https://travis-ci.org/nigelhorne/CGI-Info) -[![Appveyor Status](https://ci.appveyor.com/api/projects/status/1t1yhvagx00c2qi8?svg=true)](https://ci.appveyor.com/project/nigelhorne/cgi-info) [![CircleCI](https://dl.circleci.com/status-badge/img/circleci/8CE7w65gte4YmSREC2GBgW/THucjGauwLPtHu1MMAueHj/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/circleci/8CE7w65gte4YmSREC2GBgW/THucjGauwLPtHu1MMAueHj/tree/main) @@ -15,7 +18,7 @@ CGI::Info gets information about the system that a CGI script is running on. # VERSION -Version 0.88 +Version 0.89 # SYNOPSIS diff --git a/lib/CGI/Info.pm b/lib/CGI/Info.pm index 497bb1b..3a51d3c 100644 --- a/lib/CGI/Info.pm +++ b/lib/CGI/Info.pm @@ -31,11 +31,11 @@ CGI::Info gets information about the system that a CGI script is running on. =head1 VERSION -Version 0.88 +Version 0.89 =cut -our $VERSION = '0.88'; +our $VERSION = '0.89'; =head1 SYNOPSIS @@ -96,10 +96,13 @@ sub new # Handle hash or hashref arguments my %args; if((@_ == 1) && (ref $_[0] eq 'HASH')) { + # If the first argument is a hash reference, dereference it %args = %{$_[0]}; } elsif((@_ % 2) == 0) { + # If there is an even number of arguments, treat them as key-value pairs %args = @_; } else { + # If there is an odd number of arguments, treat it as an error carp(__PACKAGE__, ': Invalid arguments passed to new()'); return; } @@ -745,7 +748,7 @@ sub params { if($self->{allow}) { # Is this a permitted argument? if(!exists($self->{allow}->{$key})) { - $self->_info("discard $key"); + $self->_info("Discard unallowed argument '$key'"); $self->status(422); next; } @@ -753,7 +756,7 @@ sub params { # Do we allow any value, or must it be validated? if(defined($self->{allow}->{$key})) { if($value !~ $self->{allow}->{$key}) { - $self->_info("block $key = $value"); + $self->_info("Block $key = $value"); $self->status(422); next; } diff --git a/t/gv.t b/t/gv.t index 92faec5..9b6b3a8 100644 --- a/t/gv.t +++ b/t/gv.t @@ -4,9 +4,9 @@ use strict; use warnings; use Test::DescribeMe qw(author); -use Test::More; +use Test::Most; use Test::Needs 'Test::GreaterVersion'; -Test::GreaterVersion::has_greater_version_than_cpan('CGI::Info'); +Test::GreaterVersion::has_greater_version_than_cpan('LWP::UserAgent::Throttled'); done_testing(); diff --git a/t/strict.t b/t/strict.t index 458516a..aa48d2f 100644 --- a/t/strict.t +++ b/t/strict.t @@ -4,7 +4,6 @@ use strict; use warnings; use Test::DescribeMe qw(author); -use Test::Most; use Test::Needs 'Test::Strict'; Test::Strict->import();