first release
[gitmo/MooseX-AlwaysCoerce.git] / t / 01-basic.t
CommitLineData
ad1917d7 1#!/usr/bin/env perl
2use strict;
3use warnings;
4
5use 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
22ok( (my $instance = MyClass->new), 'instance' );
23
24eval { $instance->foo('bar') };
25ok( (!$@), 'attribute coercion ran' );
26
27eval { $instance->bar('baz') };
28ok( (!$@), 'class attribute coercion ran' );