From: Fuji, Goro Date: Mon, 27 Sep 2010 12:25:04 +0000 (+0900) Subject: Duplicated role_type() and class_type() no longer throw the error X-Git-Tag: 0.76~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f1a8bff35c48b4e801e34859913ae388363a2ef4;p=gitmo%2FMouse.git Duplicated role_type() and class_type() no longer throw the error --- diff --git a/Moose-t-failing/020_attributes/005_attribute_does.t b/Moose-t-failing/020_attributes/005_attribute_does.t deleted file mode 100644 index e41a4d1..0000000 --- a/Moose-t-failing/020_attributes/005_attribute_does.t +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/perl -# This is automatically generated by author/import-moose-test.pl. -# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! -use t::lib::MooseCompat; - -use strict; -use warnings; - -use Test::More; -$TODO = q{Mouse is not yet completed}; -use Test::Exception; - - -{ - package Foo::Role; - use Mouse::Role; - use Mouse::Util::TypeConstraints; - - # if does() exists on its own, then - # we create a type constraint for - # it, just as we do for isa() - has 'bar' => (is => 'rw', does => 'Bar::Role'); - has 'baz' => ( - is => 'rw', - does => role_type('Bar::Role') - ); - - package Foo::Class; - use Mouse; - - with 'Foo::Role'; - - package Bar::Role; - use Mouse::Role; - - # if isa and does appear together, then see if Class->does(Role) - # if it does work... then the does() check is actually not needed - # since the isa() check will imply the does() check - has 'foo' => (is => 'rw', isa => 'Foo::Class', does => 'Foo::Role'); - - package Bar::Class; - use Mouse; - - with 'Bar::Role'; -} - -my $foo = Foo::Class->new; -isa_ok($foo, 'Foo::Class'); - -my $bar = Bar::Class->new; -isa_ok($bar, 'Bar::Class'); - -lives_ok { - $foo->bar($bar); -} '... bar passed the type constraint okay'; - -dies_ok { - $foo->bar($foo); -} '... foo did not pass the type constraint okay'; - -lives_ok { - $foo->baz($bar); -} '... baz passed the type constraint okay'; - -dies_ok { - $foo->baz($foo); -} '... foo did not pass the type constraint okay'; - -lives_ok { - $bar->foo($foo); -} '... foo passed the type constraint okay'; - - - -# some error conditions - -{ - package Baz::Class; - use Mouse; - - # if isa and does appear together, then see if Class->does(Role) - # if it does not,.. we have a conflict... so we die loudly - ::dies_ok { - has 'foo' => (isa => 'Foo::Class', does => 'Bar::Class'); - } '... cannot have a does() which is not done by the isa()'; -} - -{ - package Bling; - use strict; - use warnings; - - sub bling { 'Bling::bling' } - - package Bling::Bling; - use Mouse; - - # if isa and does appear together, then see if Class->does(Role) - # if it does not,.. we have a conflict... so we die loudly - ::dies_ok { - has 'foo' => (isa => 'Bling', does => 'Bar::Class'); - } '... cannot have a isa() which is cannot does()'; -} - -done_testing; diff --git a/lib/Mouse/Util/TypeConstraints.pm b/lib/Mouse/Util/TypeConstraints.pm index 0d0bf64..446cea2 100644 --- a/lib/Mouse/Util/TypeConstraints.pm +++ b/lib/Mouse/Util/TypeConstraints.pm @@ -149,7 +149,7 @@ sub _define_type { } } - if($TYPE{$name}){ + if(defined $TYPE{$name}){ my $that = $TYPE{$name}->{package_defined_in} || __PACKAGE__; if($this ne $that) { my $note = ''; @@ -202,7 +202,7 @@ sub class_type { my $class = $options->{class} || $name; # ClassType - return _define_type 1, $name => ( + return subtype $name => ( as => 'Object', optimized_as => Mouse::Util::generate_isa_predicate_for($class), class => $class, @@ -214,7 +214,7 @@ sub role_type { my $role = $options->{role} || $name; # RoleType - return _define_type 1, $name => ( + return subtype $name => ( as => 'Object', optimized_as => sub { return Scalar::Util::blessed($_[0]) diff --git a/t/020_attributes/005_attribute_does.t b/t/020_attributes/005_attribute_does.t index 267f98d..b4fec65 100644 --- a/t/020_attributes/005_attribute_does.t +++ b/t/020_attributes/005_attribute_does.t @@ -1,13 +1,15 @@ #!/usr/bin/perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; use strict; use warnings; -use Test::More tests => 9; +use Test::More; use Test::Exception; - { package Foo::Role; use Mouse::Role; @@ -19,27 +21,26 @@ use Test::Exception; has 'bar' => (is => 'rw', does => 'Bar::Role'); has 'baz' => ( is => 'rw', - does => 'Bar::Role' + does => role_type('Bar::Role') ); + package Foo::Class; + use Mouse; + + with 'Foo::Role'; + package Bar::Role; use Mouse::Role; # if isa and does appear together, then see if Class->does(Role) # if it does work... then the does() check is actually not needed # since the isa() check will imply the does() check - has 'foo' => (is => 'rw', isa => 'Foo::Class'); - - package Foo::Class; - use Mouse; - - with 'Foo::Role'; + has 'foo' => (is => 'rw', isa => 'Foo::Class', does => 'Foo::Role'); package Bar::Class; use Mouse; with 'Bar::Role'; - } my $foo = Foo::Class->new; @@ -74,13 +75,12 @@ lives_ok { { package Baz::Class; - use Test::More; use Mouse; # if isa and does appear together, then see if Class->does(Role) # if it does not,.. we have a conflict... so we die loudly ::dies_ok { - has 'foo' => (is => 'rw', isa => 'Foo::Class', does => 'Bar::Class'); + has 'foo' => (isa => 'Foo::Class', does => 'Bar::Class'); } '... cannot have a does() which is not done by the isa()'; } @@ -92,15 +92,13 @@ lives_ok { sub bling { 'Bling::bling' } package Bling::Bling; - use Test::More; use Mouse; # if isa and does appear together, then see if Class->does(Role) # if it does not,.. we have a conflict... so we die loudly ::dies_ok { - has 'foo' => (is => 'rw', isa => 'Bling', does => 'Bar::Class'); + has 'foo' => (isa => 'Bling', does => 'Bar::Class'); } '... cannot have a isa() which is cannot does()'; } - - +done_testing;