Commit | Line | Data |
df491f72 |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | |
5 | use Test::More; |
6 | use Test::Exception; |
7 | |
7f427a8a |
8 | BEGIN { |
9 | if (eval { require MooseX::Method::Signatures }) { |
10 | plan tests => 2; |
11 | } else { |
12 | plan skip_all => 'This test needs MooseX::Method::Signatures'; |
13 | } |
14 | } |
df491f72 |
15 | |
16 | { |
17 | package MyClass; |
18 | use Moose; |
19 | use MooseX::Method::Signatures; |
20 | use MooseX::AlwaysCoerce; |
21 | use Moose::Util::TypeConstraints; |
22 | |
23 | BEGIN { |
24 | subtype 'MyType', as 'Int'; |
25 | coerce 'MyType', from 'Str', via { length $_ }; |
26 | |
27 | subtype 'Uncoerced', as 'Int'; |
28 | } |
29 | |
30 | method foo (MyType :$foo, Uncoerced :$bar) { |
31 | return "$foo $bar"; |
32 | } |
33 | } |
34 | |
35 | ok( (my $instance = MyClass->new), 'instance' ); |
36 | |
37 | lives_and { |
38 | is $instance->foo(foo => "text", bar => 42), '4 42'; |
39 | } 'method called with coerced and uncoerced parameters'; |