From: Shawn M Moore Date: Wed, 12 Aug 2009 00:51:19 +0000 (-0400) Subject: Roles can now accept attributes named 0 and "" X-Git-Tag: 0.89~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=52ac1d4a4961feee7a54e3b018fe1e609f1fe8a1;p=gitmo%2FMoose.git Roles can now accept attributes named 0 and "" Fix up tests too.. --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index adf7c12..0a6f56d 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -165,7 +165,7 @@ $META->add_attribute( sub add_attribute { my $self = shift; my $name = shift; - unless ( defined $name && $name ) { + unless ( defined $name ) { require Moose; Moose->throw_error("You must provide a name for the attribute"); } diff --git a/t/020_attributes/023_attribute_names.t b/t/020_attributes/023_attribute_names.t index f63b948..9656e47 100644 --- a/t/020_attributes/023_attribute_names.t +++ b/t/020_attributes/023_attribute_names.t @@ -5,25 +5,54 @@ use warnings; use Test::More tests => 8; use Test::Exception; -# note: not sure about "" and 0 being illegal attribute names -# but I'm just copying what Class::MOP::Attribute does - my $exception_regex = qr/You must provide a name for the attribute/; { package My::Role; use Moose::Role; - ::throws_ok{ has; } $exception_regex, 'has; fails'; - ::throws_ok{ has undef; } $exception_regex, 'has undef; fails'; - ::throws_ok{ has ""; } $exception_regex, 'has ""; fails'; - ::throws_ok{ has 0; } $exception_regex, 'has 0; fails'; + + ::throws_ok { + has; + } $exception_regex, 'has; fails'; + + ::throws_ok { + has undef; + } $exception_regex, 'has undef; fails'; + + ::lives_ok { + has "" => ( + is => 'bare', + ); + } 'has ""; works now'; + + ::lives_ok { + has 0 => ( + is => 'bare', + ); + } 'has 0; works now'; } { package My::Class; use Moose; - ::throws_ok{ has; } $exception_regex, 'has; fails'; - ::throws_ok{ has undef; } $exception_regex, 'has undef; fails'; - ::throws_ok{ has ""; } $exception_regex, 'has ""; fails'; - ::throws_ok{ has 0; } $exception_regex, 'has 0; fails'; + + ::throws_ok { + has; + } $exception_regex, 'has; fails'; + + ::throws_ok { + has undef; + } $exception_regex, 'has undef; fails'; + + ::lives_ok { + has "" => ( + is => 'bare', + ); + } 'has ""; works now'; + + ::lives_ok { + has 0 => ( + is => 'bare', + ); + } 'has 0; works now'; }