1
use Contextual::Return;
11
HASHREF { { name => 'foo', value => 99} }
15
OBJREF { bless {}, 'Bar' }
31
use Test::More 'no_plan';
33
# We only need to test the scalar contexts, because LIST and VOID are
34
# optimized out by checks against wantarray().
36
my $CLASS = 'Contextual::Return::Value';
39
is ref($bool), $CLASS => 'Before usage, it is a C::R::V';
40
is do{ $bool ? 'true' : 'false' }, 'false' => 'BOOLEAN context';
41
isnt ref($bool), $CLASS => 'After usage, it is not a C::R::V';
44
is ref($num), $CLASS => 'Before usage, it is a C::R::V';
45
is $num+0, 42 => 'NUMERIC context';
46
isnt ref($num), $CLASS => 'After usage, it is not a C::R::V';
49
is ref($str), $CLASS => 'Before usage, it is a C::R::V';
50
is "".$str, 'forty-two' => 'STRING context';
51
isnt ref($str), $CLASS => 'After usage, it is not a C::R::V';
54
is ref($sref), $CLASS => 'Before usage, it is a C::R::V';
55
is ${$sref}, 7 => 'SCALARREF context';
56
isnt ref($sref), $CLASS => 'After usage, it is not a C::R::V';
59
is ref($sref2), $CLASS => 'Before usage, it is a C::R::V';
60
is ${$sref2}, 'forty-two' => 'SCALARREF context (no SCALARREF provided)';
61
isnt ref($sref2), $CLASS => 'After usage, it is not a C::R::V';
64
is ref($href), $CLASS => 'Before usage, it is a C::R::V';
66
{ name => 'foo', value => 99} => 'HASHREF context';
67
isnt ref($href), $CLASS => 'After usage, it is not a C::R::V';
70
is ref($aref), $CLASS => 'Before usage, it is a C::R::V';
71
is_deeply \@{$aref}, [3,2,1] => 'ARRAYREF context';
72
isnt ref($aref), $CLASS => 'After usage, it is not a C::R::V';
75
is ref($aref2), $CLASS => 'Before usage, it is a C::R::V';
76
is_deeply \@{$aref2}, [1,2,3] => 'ARRAYREF context (no ARRAYREF provided)';
77
isnt ref($aref2), $CLASS => 'After usage, it is not a C::R::V';
80
is ref($gref), $CLASS => 'Before usage, it is a C::R::V';
81
is \*{$gref}, \*STDERR => 'GLOBREF context';
82
isnt ref($gref), $CLASS => 'After usage, it is not a C::R::V';
85
is ref($cref), $CLASS => 'Before usage, it is a C::R::V';
86
is $cref->(), 'in baz' => 'CODEREF context';
87
isnt ref($cref), $CLASS => 'After usage, it is not a C::R::V';
90
is ref($oref), $CLASS => 'Before usage, it is a C::R::V';
91
is $oref->bar, "baaaaa!\n" => 'OBJREF context';
92
isnt ref($oref), $CLASS => 'After usage, it is not a C::R::V';
96
sub bar { return "baaaaa!\n"; }