4 if( $ENV{PERL_CORE} ) {
6 @INC = ('../lib', 'lib');
14 use Test::More tests => 19;
20 q{eq} => sub { $_[0]->{string} eq $_[1] },
21 q{==} => sub { $_[0]->{num} == $_[1] },
22 q{""} => sub { $_[0]->{stringify}++; $_[0]->{string} },
23 q{0+} => sub { $_[0]->{numify}++; $_[0]->{num} }
39 local $SIG{__DIE__} = sub {
40 my($call_file, $call_line) = (caller)[1,2];
41 fail("SIGDIE accidentally called");
42 diag("From $call_file at $call_line");
45 my $obj = Overloaded->new('foo', 42);
46 isa_ok $obj, 'Overloaded';
48 cmp_ok $obj, 'eq', 'foo', 'cmp_ok() eq';
49 is $obj->{stringify}, 0, ' does not stringify';
50 is $obj, 'foo', 'is() with string overloading';
51 cmp_ok $obj, '==', 42, 'cmp_ok() with number overloading';
52 is $obj->{numify}, 0, ' does not numify';
54 is_deeply [$obj], ['foo'], 'is_deeply with string overloading';
55 ok eq_array([$obj], ['foo']), 'eq_array ...';
56 ok eq_hash({foo => $obj}, {foo => 'foo'}), 'eq_hash ...';
59 is_deeply $obj, 'foo', 'is_deeply with string overloading at the top';
61 Test::More->builder->is_num($obj, 42);
62 Test::More->builder->is_eq ($obj, "foo");
68 use overload q{""} => sub { ::fail("This should not be called") };
71 ::is_deeply(['TestPackage'], ['TestPackage']);
72 ::is_deeply({'TestPackage' => 'TestPackage'},
73 {'TestPackage' => 'TestPackage'});
74 ::is_deeply('TestPackage', 'TestPackage');
78 # Make sure 0 isn't a special case. [rt.cpan.org 41109]
80 my $obj = Overloaded->new('0', 42);
81 isa_ok $obj, 'Overloaded';
83 cmp_ok $obj, 'eq', '0', 'cmp_ok() eq';
84 is $obj->{stringify}, 0, ' does not stringify';
85 is $obj, '0', 'is() with string overloading';