blob: 5b57cf80852b6f2af66fafc3b9a6bc14687767f7 (
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
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 3;
{
package MyClass;
use Moose;
use MooseX::AlwaysCoerce;
use Moose::Util::TypeConstraints;
subtype 'MyType', as 'Int';
coerce 'MyType', from 'Str', via { length $_ };
has foo => (is => 'rw', isa => 'MyType');
class_has bar => (is => 'rw', isa => 'MyType');
}
ok( (my $instance = MyClass->new), 'instance' );
eval { $instance->foo('bar') };
ok( (!$@), 'attribute coercion ran' );
eval { $instance->bar('baz') };
ok( (!$@), 'class attribute coercion ran' );
|