diff options
Diffstat (limited to 'cpan/JSON-PP/t/113_overloaded_eq.t')
-rw-r--r-- | cpan/JSON-PP/t/113_overloaded_eq.t | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/cpan/JSON-PP/t/113_overloaded_eq.t b/cpan/JSON-PP/t/113_overloaded_eq.t new file mode 100644 index 0000000000..4d2ddce410 --- /dev/null +++ b/cpan/JSON-PP/t/113_overloaded_eq.t @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +use strict; +use Test::More tests => 2; + +BEGIN { + $ENV{ PERL_JSON_BACKEND } = 0; +} + +use JSON::PP; + +my $obj = OverloadedObject->new( 'foo' ); + +ok( $obj eq 'foo' ); + +my $json = JSON::PP->new->convert_blessed; + +is( $json->encode( [ $obj ] ), q{["foo"]} ); + + + +package OverloadedObject; + +use overload 'eq' => sub { $_[0]->{v} eq $_[1] }, '""' => sub { $_[0]->{v} }, fallback => 1; + + +sub new { + bless { v => $_[1] }, $_[0]; +} + + +sub TO_JSON { "$_[0]"; } + |