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