make coerce => 0 work for class_has
[gitmo/MooseX-AlwaysCoerce.git] / t / 01-basic.t
CommitLineData
ad1917d7 1#!/usr/bin/env perl
2use strict;
3use warnings;
4
44b44091 5use Test::More tests => 4;
ad1917d7 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');
44b44091 19
20 class_has baz => (is => 'rw', isa => 'MyType', coerce => 0);
ad1917d7 21}
22
23ok( (my $instance = MyClass->new), 'instance' );
24
25eval { $instance->foo('bar') };
26ok( (!$@), 'attribute coercion ran' );
27
28eval { $instance->bar('baz') };
29ok( (!$@), 'class attribute coercion ran' );
44b44091 30
31eval { $instance->baz('quux') };
32ok( $@, 'class attribute coercion did not run with coerce => 0' );