From ff70751bc5de752fed795c14f343c439e6daa257 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Fri, 20 Aug 2010 12:54:34 -0500 Subject: [PATCH] remove WebGUI::Utility::scalarEquals --- lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm | 6 ++-- lib/WebGUI/Utility.pm | 28 +-------------- t/Utility.t | 34 ------------------- 3 files changed, 4 insertions(+), 64 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm index bb139e387..4a2c5a3dc 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm @@ -659,19 +659,19 @@ sub compress { my $newA = {}; while (my($key, $value) = each %$a) { next if ref $value; - $newA->{$key} = $value unless WebGUI::Utility::scalarEquals($value, $amold->{$key}); + $newA->{$key} = $value unless $value eq $amold->{$key}; } push @{$newQ->{answers}}, $newA; } while (my($key, $value) = each %$q) { next if ref $value; - $newQ->{$key} = $value unless WebGUI::Utility::scalarEquals($value, $qmold->{$key}); + $newQ->{$key} = $value unless $value eq $qmold->{$key}; } push @{$newS->{questions}}, $newQ; } while (my($key, $value) = each %$s) { next if ref $value; - $newS->{$key} = $value unless WebGUI::Utility::scalarEquals($value, $smold->{$key}); + $newS->{$key} = $value unless $value eq $smold->{$key}; } push @sections, $newS; } diff --git a/lib/WebGUI/Utility.pm b/lib/WebGUI/Utility.pm index 776b9f6b9..5efd1ff0a 100644 --- a/lib/WebGUI/Utility.pm +++ b/lib/WebGUI/Utility.pm @@ -23,7 +23,7 @@ use Net::CIDR::Lite; our @ISA = qw(Exporter); our @EXPORT = qw(&isInSubnet - &sortHash &isIn &randint &round &scalarEquals + &sortHash &isIn &randint &round ); @@ -164,32 +164,6 @@ sub round { #------------------------------------------------------------------- -=head2 scalarEquals ( $a, $b, .. ) - -Checks an arbitrary number of scalars for strict equality. - -Lets perl do all the work for us, via clever use of hash keys. - -Credit goes to davido on perlmonks: http://www.perlmonks.org/?node_id=525349 - -Be aware that this may actually be more strict than you want. See Utility.t -for the full list of scalars that are considered equal and not equal. - -=cut - -sub scalarEquals { - # False when < 2 defined args - return 0 if ( grep { defined($_) } @_ ) < 2; - - # Use args as hash keys, all equal if we end up with only 1 key - no warnings qw/uninitialized/; - my %gadget; - @gadget{@_} = (); - return scalar keys %gadget == 1 ? 1 : 0; -} - -#------------------------------------------------------------------- - =head2 sortHash ( hash ) Sorts a hash by its values. Returns a Tie::IxHash. You must assign this to diff --git a/t/Utility.t b/t/Utility.t index 0eac303de..39bf6aa39 100644 --- a/t/Utility.t +++ b/t/Utility.t @@ -50,40 +50,6 @@ is(WebGUI::Utility::round(47.6, 0), 48, 'round() - rounds up, too'); is_deeply([keys %hash2], [qw/e c b d a/], 'sortHash'); } -##################################################################### -# -# scalarEquals -# -##################################################################### -{ - my %eq = ( - 0 => 0, - "0" => "0", - 0.1 => 0.1, - "0.1" => "0.1", - "0 but true" => "0 but true", - "string" => "string", - ); - while (my($a, $b) = each %eq) { - ok(WebGUI::Utility::scalarEquals($a, $b), "scalarEquals($a, $b) truthy"); - } - - my %ne = ( - 0 => "0", - "0.0" => "0", - "0.1" => "0.10", - "0" => "0 but true", - "1" => "0 but true", - 0 => "0 but true", - 1 => "0 but true", - ); - while (my($a, $b) = each %ne) { - ok(!WebGUI::Utility::scalarEquals($a, $b), "scalarEquals($a, $b) falsy"); - } - ok(!WebGUI::Utility::scalarEquals(), "scalarEquals() falsy when no args"); - ok(!WebGUI::Utility::scalarEquals(1), "falsy for 1 arg"); - ok(!WebGUI::Utility::scalarEquals(1, undef, 1), "falsy for 3 args"); -} # isInSubnets is(WebGUI::Utility::isInSubnet('192.168.0.1', []), 0, 'isInSubnet: comparing against an empty array ref');