X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fforeign%2FMooseX-Method-Signatures%2Ftypes.t;fp=t%2Fforeign%2FMooseX-Method-Signatures%2Ftypes.t;h=12f007d946e03b4c3bf8390fe38c4fd08bec5ae5;hb=1a52f2db46f6d870454428a07bfae09e0359eeee;hp=0000000000000000000000000000000000000000;hpb=ff265988561375d3cf480004e29e3891094c0afb;p=p5sagit%2FFunction-Parameters.git diff --git a/t/foreign/MooseX-Method-Signatures/types.t b/t/foreign/MooseX-Method-Signatures/types.t new file mode 100644 index 0000000..12f007d --- /dev/null +++ b/t/foreign/MooseX-Method-Signatures/types.t @@ -0,0 +1,42 @@ +#!perl +use strict; +use warnings FATAL => 'all'; +use Test::More + eval { require Moose; require MooseX::Types } + ? (tests => 4) + : (skip_all => "Moose, MooseX::Types required for testing types") +; +use Test::Fatal; + +{ + package MyTypes; + use MooseX::Types::Moose qw/Str/; + use Moose::Util::TypeConstraints; + use MooseX::Types -declare => [qw/CustomType/]; + + BEGIN { + subtype CustomType, + as Str, + where { length($_) == 2 }; + } +} + +{ + package TestClass; + use Function::Parameters qw(:strict); + BEGIN { MyTypes->import('CustomType') }; + use MooseX::Types::Moose qw/ArrayRef/; + #use namespace::clean; + + method foo ((CustomType) $bar) { } + + method bar ((ArrayRef[CustomType]) $baz) { } +} + +my $o = bless {} => 'TestClass'; + +is(exception { $o->foo('42') }, undef); +ok(exception { $o->foo('bar') }); + +is(exception { $o->bar(['42', '23']) }, undef); +ok(exception { $o->bar(['foo', 'bar']) });