7
# # ok( not( defined undef ), 'undef is undefined' );
8
# # ok( defined 1, '1 is defined' );
9
# # ok( defined '...', '"..." is defined' );
10
# # ok( defined [], '[] is defined' );
12
# # sub X1::defined {1}
13
# # sub X2::defined {0}
14
# # ok( defined( bless [], 'X1' ), 'X1 is defined because ->defined is true' );
15
# # ok( not( defined bless [], 'X2' ),
16
# # 'X2 is not defined because ->defined is false' );
18
# # sub Y::defined { }
19
# # ok( not( defined bless [], 'Y' ),
20
# # 'Y is not defined because ->defined returned empty' );
22
# # sub Z::defined { return ( 0, 0 ) }
23
# # ok( not( defined bless [], 'Z' ), q[Z returned (0,0) so it is undefined] );
25
# # ok( defined( bless [], 'A' ), 'A has no ->defined method so it is fine' );
30
# This test must occur before UNIVERSAL::ref is compiled.
32
local $TODO = q[Impossible using current technology.];
34
# Fixing this requires peeking at the optrees being used by yylex
35
# that haven't been fed to newATTRSUB yet. Is there some ultra
36
# sneaky way to get access to these ops uh... without going
37
# through a CV's ROOT?
40
is( ref( bless [], 'PAST' ), 'lie', 'I even fix the past' );
57
# Validate that ref() lies for us.
58
is( CORE::ref( bless [], 'LIAR' ), 'lie', 'Lying 101' );
64
eval q[use Data::Dumper 'Dumper'];
65
skip( q[Don't have Data::Dumper], 1 )
66
if not defined &Dumper;
68
like( Dumper( bless [], 'LIAR' ), qr/LIAR/,
69
'Data::Dumper is unpeturbed' );
75
eval q[use Data::Dump::Streamer 'Dump'];
76
skip( q[Don't have Data::Dump::Streamer], 1 )
79
like( Dump( bless [], 'LIAR' )->Out,
80
qr/LIAR/, 'Data::Dump::Streamer is ok' );
86
# Validate that ref() works as normal for non-hooked things.
87
is( ref(''), '', 'Ordinary things are ordinary 1' );
88
is( ref( [] ), 'ARRAY', 'Ordinary things are ordinary 2' );
89
is( ref( bless [], 'A1' ), 'A1', 'Ordinary things are ordinary 3' );
97
sub ref {'blah blah blah'}
98
sub myself { CORE::ref $_[0] }
101
is( ref( bless( [], 'DELUSION' ) ), 'blah blah blah', 'Self delusion 1' );
102
is( bless( [], 'DELUSION' )->myself, 'DELUSION', 'Self delusion 2' );
106
BEGIN { $TESTS += 2 }
109
sub ref { warn; 'NOT-OVERLOADED' }
110
use overload 'bool' => sub () {'FALSE'};
114
my $obj = bless [], 'OVERLOADED';
115
ok( overload::Overloaded($obj),
116
'Overloaded objects still look overloaded' );
118
overload::StrVal($obj),
119
qr/\A\QOVERLOADED=ARRAY(0x\E[\da-fA-F]+\)\z/,
120
'Overloaded objects stringify normally too'
124
BEGIN { plan('no_plan') }