Subject: | JSON:NotString needs 'eq' overloading |
Date: | Thu, 3 May 2007 13:37:54 -0700 |
To: | <bug-JSON [...] rt.cpan.org> |
From: | "Ryan Morris" <ryan.morris [...] sensage.com> |
Greetings,
I have ran into a case where some Perl code of mine was failing because it was
unable to perform an 'eq' comparison on a JSON:NotString Object. I fixed it in
my version by doing the following:
Show quoted text
>>Paser.pm
package JSON::NotString;
use overload (
'""' => sub { $_[0]->{value} },
'bool' => sub {
! defined $_[0]->{value} ? undef
: $_[0]->{value} eq 'false' ? 0 : 1;
},
# Added eq
'eq' => sub {
if (ref($_[1]) eq 'JSON::NotString') {
return $_[0]->{value} eq $_[1]->{value};
} else {
return $_[0]->{value} eq $_[1];
}
},
);
I was wondering if you would consider fixing this in the main build?
----------
Ryan Morris
Engineering - Apps