sub add_attribute {
my $self = shift;
my $name = shift;
- $self->{attributes}->{$name} = [ @_ ];
+ my $spec = shift;
+ $self->{attributes}->{$name} = $spec;
}
sub has_attribute { exists $_[0]->{attributes}->{$_[1]} }
sub get_attribute_list { keys %{ $_[0]->{attributes} } }
-sub get_attribute { $_->[0]->{attributes}->{$_[1]} }
+sub get_attribute { $_[0]->{attributes}->{$_[1]} }
sub apply {
my $self = shift;
for my $name ($self->get_attribute_list) {
my $spec = $self->get_attribute($name);
- Mouse::Meta::Attribute->create($pkg, $name, @$spec);
+ Mouse::Meta::Attribute->create($pkg, $name, %$spec);
}
}
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 1;
+use Test::More tests => 5;
+use Test::Exception;
do {
package Role;
use Mouse::Role;
- has 'attr';
+ has 'attr' => (
+ default => 'Role',
+ );
no Mouse::Role;
};
+is_deeply(Role->meta->get_attribute('attr'), {default => 'Role'});
+
do {
package Class;
use Mouse;
};
ok(Class->meta->has_attribute('attr'), "role application added the attribute");
+is(Class->meta->get_attribute('attr')->default, 'Role');
+
+do {
+ package Role2;
+ use Mouse::Role;
+
+ has 'attr' => (
+ default => 'Role2',
+ );
+
+ no Mouse::Role;
+};
+
+lives_ok {
+ package Class2;
+ use Mouse;
+ with 'Role';
+ with 'Role2';
+};
+
+TODO: {
+ local $TODO = "Moose prefers first definition, Mouse the last";
+ is(Class2->meta->get_attribute('attr')->default, 'Role');
+};