Moose::Util::MetaRole was used on the two corresponding
classes, then the difference in roles is reconciled for the
subclass's metaclass. (Dave Rolsky)
+ - Squashed an warning in _process_attribute (thepler)
+
+ * Moose::Meta::Role
+ - throw exceptions (sooner) for invalid attribute names (thepler)
+ - added tests for this (thepler)
0.57 Wed September 3, 2008
* Moose::Intro
@args = %{$args[0]} if scalar @args == 1 && ref($args[0]) eq 'HASH';
- if ($name =~ /^\+(.*)/) {
+ if (($name || '') =~ /^\+(.*)/) {
return $self->_process_inherited_attribute($1, @args);
}
else {
sub add_attribute {
my $self = shift;
my $name = shift;
+ (defined $name && $name)
+ || Moose->throw_error("You must provide a name for the attribute");
my $attr_desc;
if (scalar @_ == 1 && ref($_[0]) eq 'HASH') {
$attr_desc = $_[0];
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+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';
+}
+
+{
+ 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';
+}
+