6 use Test::More tests => 14 + 6;
9 package Lexical::Types::Test::LTT;
12 $_[1] = (caller(0))[2];
13 Test::More::is($_[2], 'LTT', 'original type is ok');
22 package Lexical::Types::Test::LTT2;
24 sub TYPEDSCALAR { 1 .. 2 }
28 package Lexical::Types::Test::LTT3;
30 sub TYPEDSCALAR { die 'coconut' }
37 *ts = \&Lexical::Types::Test::LTT::TYPEDSCALAR
41 use Lexical::Types as => 'Lexical::Types::Test';
43 is $x, __LINE__-1, 'as => string, without trailing ::';
47 is $y, undef, 'after no';
51 use Lexical::Types as => 'Lexical::Types::Test::';
53 is $x, __LINE__-1, 'as => string, with trailing ::';
57 use Lexical::Types as => sub { return };
59 is $x, undef, 'as => code, returning nothing';
63 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT' };
65 is $x, __LINE__-1, 'as => code, returning package name';
69 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT', undef };
71 is $x, __LINE__-1, 'as => code, returning package name and undef';
75 use Lexical::Types as => sub { undef, 'ts' };
77 is $x, __LINE__-1, 'as => code, returning undef and method name';
81 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT', 'TS' };
83 is $x, __LINE__-1, 'as => code, returning package and method name';
87 my $expect = qr/^Invalid ARRAY reference/;
90 use Lexical::Types as => [ qw/a b c/ ];
93 like $@, $expect, 'as => array';
97 my $expect = qr/^Lexical::Types mangler should return zero, one or two scalars, but got 3/;
98 diag 'This will throw two warnings' if $] >= 5.008008 and $] < 5.009;
101 use Lexical::Types as => sub { qw/a b c/ };
104 like $@, $expect, 'as => code, returning three scalars';
108 my $expect = qr/^Typed scalar initializer method should return zero or one scalar, but got 2/;
111 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT2' };
114 like $@, $expect, 'as => code, initializing by returning two scalars';
118 my $expect = qr/^banana at \(eval \d+\) line 2/;
119 diag 'This will throw two more warnings' if $] >= 5.008008 and $] < 5.009;
122 use Lexical::Types as => sub { die 'banana' };
125 like $@, $expect, 'as => sub { die }';
129 my $expect = qr/^coconut at \Q$0\E line 30/;
133 my Lexical::Types::Test::LTT3 $x;
135 like $@, $expect, 'die in TYPEDSCALAR';
139 is $x, undef, 'out of scope';