respect value of coerce not only if 0
[gitmo/MooseX-AlwaysCoerce.git] / t / 02-mx-m-s.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4
5 use Test::More;
6
7 BEGIN {
8     if (eval { require MooseX::Method::Signatures }) {
9         plan tests => 3;
10     } else {
11         plan skip_all => 'This test needs MooseX::Method::Signatures';
12     }
13 }
14
15 use Test::Exception;
16 use Test::NoWarnings;
17
18 {
19     package MyClass;
20     use Moose;
21     use MooseX::Method::Signatures;
22     use MooseX::AlwaysCoerce;
23     use Moose::Util::TypeConstraints;
24
25     BEGIN {
26         subtype 'MyType', as 'Int';
27         coerce 'MyType', from 'Str', via { length $_ };
28
29         subtype 'Uncoerced', as 'Int';
30     }
31
32     method foo (MyType :$foo, Uncoerced :$bar) {
33         return "$foo $bar";
34     }
35 }
36
37 ok( (my $instance = MyClass->new), 'instance' );
38
39 TODO: {
40     local $TODO = 'need rafl to help with implementation';
41
42     lives_and {
43         is $instance->foo(foo => "text", bar => 42), '4 42';
44     } 'method called with coerced and uncoerced parameters';
45 }