From: gfx Date: Tue, 15 Sep 2009 05:30:45 +0000 (+0900) Subject: Support is => 'bare' for compatibility X-Git-Tag: 0.32~54^2~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=11d415286701d3b51e517cb6826138808967cb89 Support is => 'bare' for compatibility --- diff --git a/Changes b/Changes index 7ea8e3a..0ae2f73 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ Revision history for Mouse 0.29 + * Support is => 'bare', and you must pass the 'is' option (gfx) + * Make generator methods private (gfx) 0.28 Wed Sep 8 20:00:06 2009 * Alter Makefile.PL so in author mode we generate lib/Mouse/Tiny.pm on diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 0312a56..65d6daf 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -1,7 +1,6 @@ package Mouse::Meta::Attribute; use strict; use warnings; -require overload; use Carp 'confess'; use Scalar::Util (); @@ -239,10 +238,15 @@ sub create { $class->add_attribute($attribute); + my $associated_methods = 0; + + my $is_metadata = $attribute->_is_metadata || ''; + # install an accessor - if ($attribute->_is_metadata eq 'rw' || $attribute->_is_metadata eq 'ro') { + if ($is_metadata eq 'rw' || $is_metadata eq 'ro') { my $code = $attribute->_generate_accessor(); $class->add_method($name => $code); + $associated_methods++; } for my $method (qw/predicate clearer/) { @@ -251,6 +255,7 @@ sub create { my $generator = "_generate_$method"; my $coderef = $attribute->$generator; $class->add_method($attribute->$method => $coderef); + $associated_methods++; } } @@ -258,9 +263,14 @@ sub create { my $method_map = $attribute->_generate_handles; for my $method_name (keys %$method_map) { $class->add_method($method_name => $method_map->{$method_name}); + $associated_methods++; } } + if($associated_methods == 0 && $is_metadata ne 'bare'){ + confess(qq{Attribute ($name) of class }.$class->name.qq{ has no associated methods (did you mean to provide an "is" argument?)}); + } + return $attribute; } diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm index 709c3f9..2ea38e2 100644 --- a/lib/Mouse/Meta/Role.pm +++ b/lib/Mouse/Meta/Role.pm @@ -2,6 +2,8 @@ package Mouse::Meta::Role; use strict; use warnings; use Carp 'confess'; + +use Mouse::Meta::Attribute; use Mouse::Util qw(version authority identifier); do { @@ -49,7 +51,7 @@ sub add_attribute { my $self = shift; my $name = shift; my $spec = shift; - $self->{attributes}->{$name} = $spec; + $self->{attributes}->{$name} = Mouse::Meta::Attribute->new($name, %$spec); } sub has_attribute { exists $_[0]->{attributes}->{$_[1]} } diff --git a/t/000-recipes/001_point.t b/t/000-recipes/001_point.t index 1f52f0f..90b989b 100644 --- a/t/000-recipes/001_point.t +++ b/t/000-recipes/001_point.t @@ -36,7 +36,7 @@ use Test::Exception; extends 'Point'; - has 'z' => (isa => 'Int'); + has 'z' => (isa => 'Int', is => 'bare'); after 'clear' => sub { my $self = shift; diff --git a/t/007-attributes.t b/t/007-attributes.t index 4316e25..fdb3ed3 100644 --- a/t/007-attributes.t +++ b/t/007-attributes.t @@ -8,7 +8,9 @@ do { package Class; use Mouse; - has 'x'; + has 'x' => ( + is => 'bare', + ); has 'y' => ( is => 'ro', diff --git a/t/010-required.t b/t/010-required.t index 161717c..e6a6990 100644 --- a/t/010-required.t +++ b/t/010-required.t @@ -9,15 +9,18 @@ do { use Mouse; has foo => ( + is => 'bare', required => 1, ); has bar => ( + is => 'bare', required => 1, default => 50, ); has baz => ( + is => 'bare', required => 1, default => sub { 10 }, ); diff --git a/t/025-more-isa.t b/t/025-more-isa.t index 576d5e1..022c89c 100755 --- a/t/025-more-isa.t +++ b/t/025-more-isa.t @@ -54,6 +54,7 @@ do { use Mouse; has oops => ( + is => 'bare', isa => 'Int', default => "yikes", ); diff --git a/t/029-new.t b/t/029-new.t index 4e642eb..fe660a1 100644 --- a/t/029-new.t +++ b/t/029-new.t @@ -8,7 +8,9 @@ do { package Class; use Mouse; - has 'x'; + has x => ( + is => 'bare', + ); has y => ( is => 'ro', diff --git a/t/030_roles/002_role.t b/t/030_roles/002_role.t index afbe34e..4deb2ec 100755 --- a/t/030_roles/002_role.t +++ b/t/030_roles/002_role.t @@ -85,16 +85,13 @@ is_deeply( ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute'); -is_deeply( - $foo_role->get_attribute('bar'), - { is => 'rw', isa => 'Foo' }, - '... got the correct description of the bar attribute'); +is $foo_role->get_attribute('bar')->name, 'bar', '... got the correct description of the bar attribute'; ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute'); -is_deeply( - $foo_role->get_attribute('baz'), - { is => 'ro' }, +is( + $foo_role->get_attribute('baz')->name, + 'baz', '... got the correct description of the baz attribute'); # method modifiers diff --git a/t/402-attribute-application.t b/t/402-attribute-application.t index fbb400d..cfd0256 100644 --- a/t/402-attribute-application.t +++ b/t/402-attribute-application.t @@ -9,13 +9,14 @@ do { use Mouse::Role; has 'attr' => ( + is => 'bare', default => 'Role', ); no Mouse::Role; }; -is_deeply(Role->meta->get_attribute('attr'), {default => 'Role'}); +is(Role->meta->get_attribute('attr')->default, 'Role'); do { package Class; @@ -33,6 +34,7 @@ do { use Mouse::Role; has 'attr' => ( + is => 'bare', default => 'Role2', ); @@ -55,6 +57,7 @@ lives_ok { with 'Role'; has attr => ( + is => 'bare', default => 'Class3', ); }; @@ -66,6 +69,7 @@ lives_ok { use Mouse; has attr => ( + is => 'bare', default => 'Class::Parent', ); };