4 if( $ENV{PERL_CORE} ) {
6 @INC = ('../lib', 'lib');
17 if( !eval "require overload" ) {
18 plan skip_all => "needs overload.pm";
29 q{""} => sub { $_[0]->{string} },
30 q{0+} => sub { $_[0]->{num} };
34 bless { string => shift, num => shift }, $class;
40 local $SIG{__DIE__} = sub {
41 my($call_file, $call_line) = (caller)[1,2];
42 fail("SIGDIE accidentally called");
43 diag("From $call_file at $call_line");
46 my $obj = Overloaded->new('foo', 42);
47 isa_ok $obj, 'Overloaded';
49 is $obj, 'foo', 'is() with string overloading';
50 cmp_ok $obj, 'eq', 'foo', 'cmp_ok() ...';
51 cmp_ok $obj, '==', 42, 'cmp_ok() with number overloading';
53 is_deeply [$obj], ['foo'], 'is_deeply with string overloading';
54 ok eq_array([$obj], ['foo']), 'eq_array ...';
55 ok eq_hash({foo => $obj}, {foo => 'foo'}), 'eq_hash ...';
58 is_deeply $obj, 'foo', 'is_deeply with string overloading at the top';
60 Test::More->builder->is_num($obj, 42);
61 Test::More->builder->is_eq ($obj, "foo");
67 use overload q{""} => sub { ::fail("This should not be called") };
70 ::is_deeply(['TestPackage'], ['TestPackage']);
71 ::is_deeply({'TestPackage' => 'TestPackage'},
72 {'TestPackage' => 'TestPackage'});
73 ::is_deeply('TestPackage', 'TestPackage');