1#!perl -w
2use Test2::Util qw/CAN_THREAD/;
3
4BEGIN {
5    if( $ENV{PERL_CORE} ) {
6        chdir 't';
7        @INC = ('../lib', 'lib');
8    }
9    else {
10        unshift @INC, 't/lib';
11    }
12}
13chdir 't';
14
15BEGIN {
16    # There was a bug with overloaded objects and threads.
17    # See rt.cpan.org 4218
18    eval { require threads; 'threads'->import; 1; } if CAN_THREAD;
19}
20
21use Test::More;
22
23plan skip_all => "known to crash on $]" if $] le "5.006002";
24
25plan tests => 5;
26
27
28package Overloaded;
29
30use overload
31  q{""} => sub { $_[0]->{string} };
32
33sub new {
34    my $class = shift;
35    bless { string => shift }, $class;
36}
37
38
39package main;
40
41my $warnings = '';
42local $SIG{__WARN__} = sub { $warnings = join '', @_ };
43
44# overloaded object as name
45my $obj = Overloaded->new('foo');
46ok( 1, $obj );
47
48# overloaded object which returns undef as name
49my $undef = Overloaded->new(undef);
50pass( $undef );
51
52is( $warnings, '' );
53
54
55TODO: {
56    my $obj = Overloaded->new('not really todo, testing overloaded reason');
57    local $TODO = $obj;
58    fail("Just checking todo as an overloaded value");
59}
60
61
62SKIP: {
63    my $obj = Overloaded->new('not really skipped, testing overloaded reason');
64    skip $obj, 1;
65}
66