build_requires => {
'ExtUtils::MakeMaker' => 0,
'Test::More' => 0,
+ 'constant' => 0,
},
resources => {
bugtracker => "http://rt.cpan.org/NoAuth/ReportBug.html?Queue=$dist",
=head1 CAVEATS
-For C<perl> to be able to parse C<my Str $x>, the package C<Str> must be defined somewhere, and this even if you use the C<'as'> option to redirect to another package.
-It's unlikely to find a workaround, as this happens deep inside the lexer, far from the reach of an extension.
+For C<perl> to be able to parse C<my Str $x>, you need :
+
+=over 4
+
+=item *
+
+either the C<Str> package to be defined ;
+
+=item *
+
+or for C<Str> to be a constant sub returning a valid defined package.
+
+=back
+
+Those restrictions apply even if you use the C<'as'> option to redirect to another package, and are unlikely to find a workaround as this happens deep inside the lexer - far from the reach of an extension.
Only one mangler or prefix can be in use at the same time in a given scope.
Inspired by Ricardo Signes.
+Thanks Florian Ragwitz for suggesting the use of constants for types.
+
=head1 COPYRIGHT & LICENSE
Copyright 2009 Vincent Pit, all rights reserved.
--- /dev/null
+#!perl -T
+
+use strict;
+use warnings;
+
+use Test::More tests => 6;
+
+use constant Str => 'MyTypes::Str';
+use constant Int => 'MyTypes::Int';
+use constant Num => 'MyTypes::Num';
+
+sub MyTypes::Str::new { "str:$_[0]" }
+
+sub MyTypes::Int::new { "int:$_[0]" }
+
+{ package MyTypes::Num }
+
+{
+ use Lexical::Types as => sub { $_[0] =~ /(?:Str|Int)/ ? ($_[0], 'new') : () };
+
+ my Str $x;
+ is $x, "str:MyTypes::Str", 'my constant_type $x';
+
+ my Int ($y, $z);
+ is $y, "int:MyTypes::Int", 'my constant_type ($y,';
+ is $z, "int:MyTypes::Int", 'my constant_type $z)';
+
+ my Num $t;
+ is $t, undef, 'my constant_type_skipped $t';
+
+ my MyTypes::Str $u;
+ is $u, "str:MyTypes::Str", 'my MyTypes::Str $u';
+
+ my MyTypes::Num $v;
+ is $v, undef, 'my MyTypes::Num $v';
+}