f056dd94ef4a8b78b0b16f207c1d5ba8b2487cab
[gitmo/MooseX-AlwaysCoerce.git] / t / 01-basic.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 3;
6
7 {
8     package MyClass;
9     use Moose;
10     use MooseX::ClassAttribute;
11     use MooseX::AlwaysCoerce;
12     use Moose::Util::TypeConstraints;
13
14     subtype 'MyType', as 'Int';
15     coerce 'MyType', from 'Str', via { length $_ };
16
17     has foo => (is => 'rw', isa => 'MyType');
18
19     class_has bar => (is => 'rw', isa => 'MyType');
20 }
21
22 ok( (my $instance = MyClass->new), 'instance' );
23
24 eval { $instance->foo('bar') };
25 ok( (!$@), 'attribute coercion ran' );
26
27 eval { $instance->bar('baz') };
28 ok( (!$@), 'class attribute coercion ran' );