X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FRole.pm;h=ec08a5bddf4c3568fd0c957325a41b0967f4f06f;hp=48e1b81a1089bc83e7d996547ee7fbbbc0fc4a49;hb=01afd8ffba9b9783e84c6cfc8ba45e11a0f5d8f4;hpb=7a50b45027c9f7baad76cfce7f78c822bd38f0a7 diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm index 48e1b81..ec08a5b 100644 --- a/lib/Mouse/Meta/Role.pm +++ b/lib/Mouse/Meta/Role.pm @@ -2,12 +2,13 @@ package Mouse::Meta::Role; use strict; use warnings; -use Mouse::Util qw(not_supported english_list); -use base qw(Mouse::Meta::Module); +use Mouse::Util qw(:meta not_supported english_list get_code_info); +use Mouse::Meta::Module; +our @ISA = qw(Mouse::Meta::Module); sub method_metaclass(){ 'Mouse::Meta::Role::Method' } # required for get_method() -sub _new { +sub _construct_meta { my $class = shift; my %args = @_; @@ -20,7 +21,7 @@ sub _new { # return Mouse::Meta::Class->initialize($class)->new_object(%args) # if $class ne __PACKAGE__; - return bless \%args, $class; + return bless \%args, ref($class) || $class; } sub create_anon_role{ @@ -39,8 +40,7 @@ sub get_required_method_list{ } sub add_required_methods { - my $self = shift; - my @methods = @_; + my($self, @methods) = @_; push @{$self->{required_methods}}, @methods; } @@ -179,15 +179,7 @@ sub _apply_attributes{ my $spec = $role->get_attribute($attr_name); - my $attr_metaclass = 'Mouse::Meta::Attribute'; - if ( my $metaclass_name = $spec->{metaclass} ) { - $attr_metaclass = Mouse::Util::resolve_metaclass_alias( - 'Attribute', - $metaclass_name - ); - } - - $attr_metaclass->create($class, $attr_name => %$spec); + $class->add_attribute($attr_name => %{$spec}); } } elsif($args->{_to} eq 'role'){ @@ -286,7 +278,7 @@ sub combine_apply { my $attr = $role->get_attribute($attr_name); my $c = $attr_provided{$attr_name}; if($c && $c != $attr){ - $class->throw_error("We have encountered an attribute conflict with '$attr_name' " + $class->throw_error("We have encountered an attribute conflict with '$attr_name' " . "during composition. This is fatal error and cannot be disambiguated.") } else{ @@ -299,8 +291,8 @@ sub combine_apply { my $override = $role->get_override_method_modifier($method_name); my $c = $override_provided{$method_name}; if($c && $c != $override){ - $class->throw_error( "We have encountered an 'override' method conflict with '$method_name' during " - . "composition (Two 'override' methods of the same name encountered). " + $class->throw_error( "We have encountered an 'override' method conflict with '$method_name' during " + . "composition (Two 'override' methods of the same name encountered). " . "This is fatal error.") } else{ @@ -380,7 +372,7 @@ sub add_override_method_modifier{ if($self->has_method($method_name)){ # This error happens in the override keyword or during role composition, # so I added a message, "A local method of ...", only for compatibility (gfx) - $self->throw_error("Cannot add an override of method '$method_name' " + $self->throw_error("Cannot add an override of method '$method_name' " . "because there is a local version of '$method_name'" . "(A local method of the same name as been found)"); } @@ -388,14 +380,14 @@ sub add_override_method_modifier{ $self->{override_method_modifiers}->{$method_name} = $method; } -sub has_override_method_modifier { - my ($self, $method_name) = @_; - return exists $self->{override_method_modifiers}->{$method_name}; -} - -sub get_override_method_modifier { - my ($self, $method_name) = @_; - return $self->{override_method_modifiers}->{$method_name}; +sub has_override_method_modifier { + my ($self, $method_name) = @_; + return exists $self->{override_method_modifiers}->{$method_name}; +} + +sub get_override_method_modifier { + my ($self, $method_name) = @_; + return $self->{override_method_modifiers}->{$method_name}; } sub get_method_modifier_list { @@ -423,3 +415,14 @@ sub does_role { 1; +__END__ + +=head1 NAME + +Mouse::Meta::Role - The Mouse Role metaclass + +=head1 SEE ALSO + +L + +=cut