X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Ftype_constraints%2Fclass_type_constraint.t;h=419ab589c27bb5373d818cbff1a1d80fb563b418;hb=0f9a0b95605b8f5d8bec1c42bc84dad667c4a0ed;hp=082f7f948f7a6a615315e8fcffa4fb13297e8f79;hpb=1ebf2c009f0d1009cb0bef0179b297ba043c47e9;p=gitmo%2FMoose.git diff --git a/t/type_constraints/class_type_constraint.t b/t/type_constraints/class_type_constraint.t index 082f7f9..419ab58 100644 --- a/t/type_constraints/class_type_constraint.t +++ b/t/type_constraints/class_type_constraint.t @@ -92,4 +92,25 @@ ok( $type->is_subtype_of(Moose::Meta::TypeConstraint::Class->new( name => "__ANO ok($child->is_subtype_of($parent)); } +{ + my $type; + is( exception { $type = class_type 'MyExampleClass' }, undef, 'Make initial class_type' ); + coerce 'MyExampleClass', from 'Str', via { bless {}, 'MyExampleClass' }; + # We test class_type keeping the existing type (not making a new one) here. + is( exception { is(class_type('MyExampleClass'), $type, 're-running class_type gives same type') }, undef, 'No exception making duplicate class_type' );; + + # Next define a class which needs this type and it's original coercion + # Note this has to be after the 2nd class_type call to test the bug as M::M::Attribute grabs + # the type constraint which is there at the time the attribute decleration runs. + { + package HoldsExample; + use Moose; + + has foo => ( isa => 'MyExampleClass', is => 'ro', coerce => 1, required => 1 ); + no Moose; + } + + is( exception { isa_ok(HoldsExample->new(foo => "bar")->foo, 'MyExampleClass') }, undef, 'class_type coercion works' ); +} + done_testing;