remove WebGUI::Utility::scalarEquals

This commit is contained in:
Graham Knop 2010-08-20 12:54:34 -05:00
parent a0a26da3bc
commit ff70751bc5
3 changed files with 4 additions and 64 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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');