X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FRole.pm;h=9b4aec5c9320d0b2875bde8dbd52399af9184a5b;hb=a02698f11a62bdf881c1a00651c2426b95095b29;hp=f04dd188527ba6d303133b352ee23fe03f9d0193;hpb=513854c70d1a49d9c09c9f406cc30fd33fe95e59;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm index f04dd18..9b4aec5 100644 --- a/lib/Mouse/Meta/Role.pm +++ b/lib/Mouse/Meta/Role.pm @@ -27,10 +27,35 @@ sub new { my $class = shift; my %args = @_; + $args{attributes} ||= {}; + bless \%args, $class; } sub name { $_[0]->{name} } +sub add_attribute { + my $self = shift; + my $name = shift; + 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 apply { + my $self = shift; + my $class = shift; + my $pkg = $class->name; + + for my $name ($self->get_attribute_list) { + next if $class->has_attribute($name); + my $spec = $self->get_attribute($name); + Mouse::Meta::Attribute->create($pkg, $name, %$spec); + } +} + 1;