15
     #!/usr/bin/perl -w

BEGIN {
    if( $ENV{PERL_CORE} ) {
        chdir 't';
        @INC = ('../lib', 'lib');
    }
    else {
        unshift @INC, 't/lib';
    }
}

use strict;
use Test::More tests => 19;


package Overloaded;

use overload
  q{eq}    => sub { $_[0]->{string} eq $_[1] },
  q{==}    => sub { $_[0]->{num} == $_[1] },
  q{""}    => sub { $_[0]->{stringify}++; $_[0]->{string} },
  q{0+}    => sub { $_[0]->{numify}++;   $_[0]->{num}    }
;

sub new {
    my $class = shift;
    bless {
        string  => shift,
        num     => shift,
        stringify       => 0,
        numify          => 0,
    }, $class;
}


package main;

local $SIG{__DIE__} = sub {
    my($call_file, $call_line) = (caller)[1,2];
    fail("SIGDIE accidentally called");
    diag("From $call_file at $call_line");
};

my $obj = Overloaded->new('foo', 42);
isa_ok $obj, 'Overloaded';

cmp_ok $obj, 'eq', 'foo',       'cmp_ok() eq';
is $obj->{stringify}, 0,        '  does not stringify';
is $obj, 'foo',                 'is() with string overloading';
cmp_ok $obj, '==', 42,          'cmp_ok() with number overloading';
is $obj->{numify}, 0,           '  does not numify';

is_deeply [$obj], ['foo'],                 'is_deeply with string overloading';
ok eq_array([$obj], ['foo']),              'eq_array ...';
ok eq_hash({foo => $obj}, {foo => 'foo'}), 'eq_hash ...';

# rt.cpan.org 13506
is_deeply $obj, 'foo',        'is_deeply with string overloading at the top';

Test::More->builder->is_num($obj, 42);
Test::More->builder->is_eq ($obj, "foo");


{
    # rt.cpan.org 14675
    package TestPackage;
    use overload q{""} => sub { ::fail("This should not be called") };

    package Foo;
    ::is_deeply(['TestPackage'], ['TestPackage']);
    ::is_deeply({'TestPackage' => 'TestPackage'}, 
                {'TestPackage' => 'TestPackage'});
    ::is_deeply('TestPackage', 'TestPackage');
}


# Make sure 0 isn't a special case. [rt.cpan.org 41109]
{
    my $obj = Overloaded->new('0', 42);
    isa_ok $obj, 'Overloaded';

    cmp_ok $obj, 'eq', '0',  'cmp_ok() eq';
    is $obj->{stringify}, 0, '  does not stringify';
    is $obj, '0',            'is() with string overloading';
}
  $   H403318_I|Mjq؂ <o >    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<p>Additionally, a 403 Forbidden
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
  !   	li~d
e8iLZ70      li~d
e8o0  !   315ai~d
e86Ҙo ;    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
  	   0      li~d
e8n6꘴o0  "   li~d
e8q	1hh      1
      N_I|Mdv &K<o     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /ALFA_DATA/alfasymlink/root/sys/devices/virtual/bdi/11:1/subsystem</title>
 </head>
 <body>
<h1>Index of /ALFA_DATA/alfasymlink/root/sys/devices/virtual/bdi/11:1/subsystem</h1>
  <table>
   <tr><th valign="top">&nbsp;</th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr>
   <tr><th colspan="5"><hr></th></tr>
<tr><td valign="top">&nbsp;</td><td><a href="/ALFA_DATA/alfasymlink/root/sys/devices/virtual/bdi/11:1/">Parent Directory</a>       </td><td>&nbsp;</td><td align="right">  - </td><td>&nbsp;</td></tr>
<tr><td valign="top">&nbsp;</td><td><a href="./11:0/">11:0/</a>                  </td><td align="right">2026-06-29 19:12  </td><td align="right">  - </td><td>&nbsp;</td></tr>
<tr><td valign="top">&nbsp;</t