rewritten using metaroles, the Moose way
[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;
ad1917d7 10 use MooseX::AlwaysCoerce;
11 use Moose::Util::TypeConstraints;
12
13 subtype 'MyType', as 'Int';
14 coerce 'MyType', from 'Str', via { length $_ };
15
16 has foo => (is => 'rw', isa => 'MyType');
17
18 class_has bar => (is => 'rw', isa => 'MyType');
19}
20
21ok( (my $instance = MyClass->new), 'instance' );
22
23eval { $instance->foo('bar') };
24ok( (!$@), 'attribute coercion ran' );
25
26eval { $instance->bar('baz') };
27ok( (!$@), 'class attribute coercion ran' );