6 use Test::More tests => 12 + 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 }
31 *ts = \&Lexical::Types::Test::LTT::TYPEDSCALAR
35 use Lexical::Types as => 'Lexical::Types::Test';
37 is $x, __LINE__-1, 'as => string, without trailing ::';
41 is $y, undef, 'after no';
45 use Lexical::Types as => 'Lexical::Types::Test::';
47 is $x, __LINE__-1, 'as => string, with trailing ::';
51 use Lexical::Types as => sub { return };
53 is $x, undef, 'as => code, returning nothing';
57 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT' };
59 is $x, __LINE__-1, 'as => code, returning package name';
63 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT', undef };
65 is $x, __LINE__-1, 'as => code, returning package name and undef';
69 use Lexical::Types as => sub { undef, 'ts' };
71 is $x, __LINE__-1, 'as => code, returning undef and method name';
75 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT', 'TS' };
77 is $x, __LINE__-1, 'as => code, returning package and method name';
81 my $expect = qr/^Invalid ARRAY reference/;
84 use Lexical::Types as => [ qw/a b c/ ];
87 like $@, $expect, 'as => array';
91 my $expect = qr/^Lexical::Types mangler should return zero, one or two scalars, but got 3/;
92 diag 'This will throw two warnings' if $] >= 5.008008 and $] < 5.009;
95 use Lexical::Types as => sub { qw/a b c/ };
98 like $@, $expect, 'as => code, returning three scalars';
102 my $expect = qr/^Typed scalar initializer method should return zero or one scalar, but got 2/;
105 use Lexical::Types as => sub { 'Lexical::Types::Test::LTT2' };
108 like $@, $expect, 'as => code, initializing by returning two scalars';
112 is $x, undef, 'out of scope';