doh, I missed a hardcoded version in the pod
[gitmo/MooseX-AlwaysCoerce.git] / t / 04-parameterized-roles.t
CommitLineData
a193e05d 1#!/usr/bin/env perl
13005566 2
a193e05d 3use strict;
4use warnings;
a193e05d 5use Test::More;
dfab7c8b 6use Test::Fatal;
a193e05d 7
73760f48 8use Test::Requires {
9 'MooseX::Role::Parameterized' => 0.01,
10};
a193e05d 11
13005566 12eval <<'EOF';
a193e05d 13 package Role;
14 use MooseX::Role::Parameterized;
f2dec73d 15 use MooseX::ClassAttribute;
a193e05d 16 use MooseX::AlwaysCoerce;
17 use Moose::Util::TypeConstraints;
18
f2dec73d 19 role {
20 subtype 'MyType', as 'Int';
21 coerce 'MyType', from 'Str', via { length $_ };
a193e05d 22
f2dec73d 23 subtype 'Uncoerced', as 'Int';
a193e05d 24
f2dec73d 25 has foo => (is => 'rw', isa => 'MyType');
a193e05d 26
f2dec73d 27 class_has bar => (is => 'rw', isa => 'MyType');
a193e05d 28
f2dec73d 29 class_has baz => (is => 'rw', isa => 'MyType', coerce => 0);
a193e05d 30
f2dec73d 31 has quux => (is => 'rw', isa => 'MyType', coerce => 0);
a193e05d 32
f2dec73d 33 has uncoerced_attr => (is => 'rw', isa => 'Uncoerced');
a193e05d 34
f2dec73d 35 class_has uncoerced_class_attr => (is => 'rw', isa => 'Uncoerced');
a193e05d 36
f2dec73d 37 has untyped_attr => (is => 'rw');
a193e05d 38
f2dec73d 39 class_has untyped_class_attr => (is => 'rw');
40 };
bb7cca58 41
f2dec73d 42 package MyClass;
a193e05d 43 use Moose;
44 with 'Role';
13005566 45EOF
46
a193e05d 47
dfab7c8b 48plan tests => 12;
13005566 49eval 'use Test::NoWarnings';
a193e05d 50
51ok( (my $instance = MyClass->new), 'instance' );
52
0a64dac6 53{
54 local $TODO = 'waiting on Moose changes for role support, and ClassAttribute changes for paramterized role support';
55
dfab7c8b 56 is( exception {
bb7cca58 57 $instance->foo('bar');
58 is $instance->foo, 3;
dfab7c8b 59 }, undef, 'attribute coercion ran' );
a193e05d 60
dfab7c8b 61 is( exception {
f2dec73d 62 $instance->bar('baz');
63 is $instance->bar, 3;
dfab7c8b 64 }, undef, 'class attribute coercion ran' );
a193e05d 65
dfab7c8b 66 isnt( exception { $instance->baz('quux') }, undef, 'class attribute coercion did not run with coerce => 0' );
a193e05d 67
dfab7c8b 68 isnt( exception { $instance->quux('mtfnpy') }, undef, 'attribute coercion did not run with coerce => 0' );
a193e05d 69
dfab7c8b 70 is( exception {
f2dec73d 71 $instance->uncoerced_attr(10);
72 is $instance->uncoerced_attr(10), 10;
dfab7c8b 73 }, undef, 'set attribute having type with no coercion and no coerce=0' );
bb7cca58 74
dfab7c8b 75 is( exception {
f2dec73d 76 $instance->uncoerced_class_attr(10);
77 is $instance->uncoerced_class_attr(10), 10;
dfab7c8b 78 }, undef, 'set class attribute having type with no coercion and no coerce=0' );
bb7cca58 79
dfab7c8b 80 is( exception {
f2dec73d 81 $instance->untyped_attr(10);
82 is $instance->untyped_attr, 10;
dfab7c8b 83 }, undef, 'set untyped attribute' );
bb7cca58 84
dfab7c8b 85 is( exception {
f2dec73d 86 $instance->untyped_class_attr(10);
87 is $instance->untyped_class_attr, 10;
dfab7c8b 88 }, undef, 'set untyped class attribute' );
f2dec73d 89}