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