* Roles can now override methods from other roles they consume directly,
without needing to manually exclude them (just like classes can). (mst)
+ * The has() sub exported by Moose no longer checks whether it received an
+ even number of arguments (after the name). Instead, this is checked by
+ Moose::Meta::Attribute->interpolate_class_and_new.
+
[BUG FIXES]
* Fix false positive when checking for circular references for modules that
my $meta = shift;
my $name = shift;
- Moose->throw_error('Usage: has \'name\' => ( key => value, ... )')
- if @_ % 2 == 1;
-
my %context = Moose::Util::_caller_info;
$context{context} = 'has declaration';
$context{type} = 'class';
- my %options = ( definition_context => \%context, @_ );
+
+ my @options = ( definition_context => \%context, @_ );
my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ];
- $meta->add_attribute( $_, %options ) for @$attrs;
+ $meta->add_attribute( $_, @options ) for @$attrs;
}
sub before {
}
sub interpolate_class_and_new {
- my ($class, $name, %args) = @_;
+ my ($class, $name, @args) = @_;
+ $class->throw_error('Defining an attribute requires a hash of options')
+ if @args % 2;
+
+ my %args = @args;
my ( $new_class, @traits ) = $class->interpolate_class(\%args);
$new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) );
{
- {
- package Foo;
- use Moose;
-
- ::like( ::exception { has 'foo' => ( 'ro', isa => 'Str' ) }, qr/^Usage/, 'has throws error with odd number of attribute options' );
- }
+ package Foo;
+ use Moose;
+ ::like(
+ ::exception{ has 'foo' => ( 'ro', isa => 'Str' ) },
+ qr/^Defining an attribute/,
+ 'has throws error with odd number of attribute options'
+ );
}
done_testing;