From 5ec30de8e5bd87b15c90047f5040df9a6ba1de81 Mon Sep 17 00:00:00 2001 From: Nigel Horne Date: Fri, 25 Oct 2024 13:46:04 -0400 Subject: [PATCH] new(): Use Scalar::Util to verify it's an object --- Changes | 1 + Makefile.PL | 3 ++- lib/CGI/Info.pm | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index ac437d9..8f73fe5 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Revision history for CGI-Info 0.85 Send back HTTP code 422 when argument fails "allow" Added come comments and small optimisations + new(): Use Scalar::Util to verify it's an object 0.84 Fri Oct 18 08:21:05 EDT 2024 Intercept SQL Injection diff --git a/Makefile.PL b/Makefile.PL index 423c510..6632733 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -51,6 +51,7 @@ WriteMakefile( 'Tie::Filehandle::Preempt::Stdin' => 0, }, PREREQ_PM => { 'Carp' => 0, + 'Scalar::Util' => 0, 'URI::Heuristic' => 0, # 'Sub::Private' => 0, 'Sys::Hostname' => 0, @@ -66,7 +67,7 @@ WriteMakefile( # 'String::EscapeCage' => 0.02, 'Class::Autouse' => 0, 'namespace::clean' => 0, - 'Sys::Path' => 0, + 'Sys::Path' => 0 }, dist => $dist, clean => { FILES => 'CGI-Info-*' }, # META_ADD => { diff --git a/lib/CGI/Info.pm b/lib/CGI/Info.pm index e814dc1..0d2f61c 100644 --- a/lib/CGI/Info.pm +++ b/lib/CGI/Info.pm @@ -7,6 +7,7 @@ use warnings; use strict; use Carp; use File::Spec; +use Scalar::Util; use Socket; # For AF_INET use 5.008; use Log::Any qw($log); @@ -101,7 +102,7 @@ sub new # FIXME: this only works when no arguments are given $class = __PACKAGE__; - } elsif(ref($class)) { + } elsif(Scalar::Util::blessed($class)) { # If $class is an object, clone it with new arguments return bless { %{$class}, %args }, ref($class); } @@ -918,7 +919,7 @@ sub _get_params my $num_args = scalar @_; # Populate %rc based on the number and type of arguments - if($num_args == 1 && defined $default) { + if(($num_args == 1) && (defined $default)) { %rc = ($default => shift); } elsif(($num_args % 2) == 0) { %rc = @_;