Skip to content

Commit dc94a6b

Browse files
tevfik1903rurban
authored andcommitted
Overload ne operator for JSON::PP::Boolean (#107)
to provide consistency with eq operator currently: . $true eq "true" evaluates to true . $true ne "true" also evaluates to true which is confusing
1 parent cb349af commit dc94a6b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

XS.pm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,6 +2224,10 @@ BEGIN {
22242224
return $obj ? 1 == $op : 0 == $op;
22252225
}
22262226
},
2227+
'ne' => sub {
2228+
my ($obj, $op) = ref ($_[0]) ? ($_[0], $_[1]) : ($_[1], $_[0]);
2229+
return !($obj eq $op);
2230+
},
22272231
fallback => 1);
22282232
}
22292233

t/03_types.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
BEGIN { $| = 1; print "1..86\n"; }
1+
BEGIN { $| = 1; print "1..87\n"; }
22
use utf8;
33
use Cpanel::JSON::XS;
44

@@ -19,6 +19,7 @@ ok ($false == !$true);
1919
ok (Cpanel::JSON::XS::is_bool $false);
2020
ok ($false eq "0", "false: eq $false");
2121
ok ($true eq "true", "true: eq $true");
22+
ok (!($true ne "true"), "ne operator test for !(true: ne $true)");
2223
ok ("$false" eq "0", "false: stringified $false eq 0");
2324
#ok ("$false" eq "false", "false: stringified $false eq false");
2425
#ok ("$true" eq "1", "true: stringified $true eq 1");

0 commit comments

Comments
 (0)