6 use Test::More tests => 14 + 6;
9 package Lexical::Types::Test::LTT;
12 $_[1] = (caller(0))[2];
13 local $Test::Builder::Level = $Test::Builder::Level + 1;
14 Test::More::is($_[2], 'LTT', 'original type is ok');
23 package Lexical::Types::Test::LTT2;
25 sub TYPEDSCALAR { 1 .. 2 }
29 package Lexical::Types::Test::LTT3;
31 sub TYPEDSCALAR { die 'coconut' }
38 *ts = \&Lexical::Types::Test::LTT::TYPEDSCALAR
42 use Lexical::Types as => 'Lexical::Types::Test';
44 is $x, __LINE__-1, 'as => string, without trailing ::';
48 is $y, undef, 'after no';
52 use Lexical::Types as => 'Lexical::Types::Test::';
54 is $x, __LINE__-1, 'as => string, with trailing ::';
58 use Lexical::Types as => sub { return };
60 is $x, undef, 'as => code, returning nothing';
64 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT' };
66 is $x, __LINE__-1, 'as => code, returning package name';
70 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT', undef };
72 is $x, __LINE__-1, 'as => code, returning package name and undef';
76 use Lexical::Types as => sub { undef, 'ts' };
78 is $x, __LINE__-1, 'as => code, returning undef and method name';
82 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT', 'TS' };
84 is $x, __LINE__-1, 'as => code, returning package and method name';
88 my $expect = qr/^Invalid ARRAY reference/;
91 use Lexical::Types as => [ qw<a b c> ];
94 like $@, $expect, 'as => array';
98 my $expect = qr/^Lexical::Types mangler should return zero, one or two scalars, but got 3/;
99 diag 'This will throw two warnings' if "$]" >= 5.008_008 and "$]" < 5.009;
102 use Lexical::Types as => sub { qw<a b c> };
105 like $@, $expect, 'as => code, returning three scalars';
109 my $expect = qr/^Typed scalar initializer method should return zero or one scalar, but got 2/;
112 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT2' };
115 like $@, $expect, 'as => code, initializing by returning two scalars';
119 my $expect = qr/^banana at \(eval \d+\) line 2/;
120 diag 'This will throw two more warnings' if "$]" >= 5.008_008 and "$]" < 5.009;
123 use Lexical::Types as => sub { die 'banana' };
126 like $@, $expect, 'as => sub { die }';
130 my $expect = qr/^coconut at \Q$0\E line 31/;
134 my Lexical::Types::Test::LTT3 $x;
136 like $@, $expect, 'die in TYPEDSCALAR';
140 is $x, undef, 'out of scope';