X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole.pm;h=9c00815950106a9a9c98b492610aa551db8d219c;hb=74397c13ad55fc865db34721aed512d4f605fadf;hp=7738207078584068fc0a8b65bc0bf36b3de8b0a1;hpb=56d7c7453888ed2c684bcdb1d905841d8d03aeb1;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 7738207..9c00815 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -8,7 +8,7 @@ use metaclass; use Scalar::Util 'blessed'; use Carp 'confess'; -our $VERSION = '0.73'; +our $VERSION = '0.75_01'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -117,6 +117,12 @@ foreach my $action ( }) if exists $methods->{remove}; } +$META->add_attribute( + 'method_metaclass', + reader => 'method_metaclass', + default => 'Moose::Meta::Role::Method', +); + ## some things don't always fit, so they go here ... sub add_attribute { @@ -136,15 +142,6 @@ sub add_attribute { $self->get_attribute_map->{$name} = $attr_desc; } -# DEPRECATED -# sub _clean_up_required_methods { -# my $self = shift; -# foreach my $method ($self->get_required_method_list) { -# $self->remove_required_methods($method) -# if $self->has_method($method); -# } -# } - ## ------------------------------------------------------------------ ## method modifiers @@ -256,7 +253,7 @@ sub update_package_cache_flag { ## ------------------------------------------------------------------ ## subroles -__PACKAGE__->meta->add_attribute('roles' => ( +$META->add_attribute('roles' => ( reader => 'get_roles', default => sub { [] } )); @@ -295,8 +292,6 @@ sub does_role { ## ------------------------------------------------------------------ ## methods -sub method_metaclass { 'Moose::Meta::Role::Method' } - sub get_method_map { my $self = shift; @@ -323,18 +318,10 @@ sub get_method_map { $map->{$symbol}->body == $code; my ($pkg, $name) = Class::MOP::get_code_info($code); + my $meta = Class::MOP::class_of($pkg); - if ($pkg->can('meta') - # NOTE: - # we don't know what ->meta we are calling - # here, so we need to be careful cause it - # just might blow up at us, or just complain - # loudly (in the case of Curses.pm) so we - # just be a little overly cautious here. - # - SL - && eval { no warnings; blessed($pkg->meta) } # FIXME calls meta - && $pkg->meta->isa('Moose::Meta::Role')) { - my $role = $pkg->meta->name; + if ($meta && $meta->isa('Moose::Meta::Role')) { + my $role = $meta->name; next unless $self->does_role($role); } else { @@ -426,6 +413,8 @@ sub get_method_list { } sub alias_method { + Carp::cluck("The alias_method method is deprecated. Use add_method instead.\n"); + my $self = shift; $self->add_method(@_); @@ -464,7 +453,7 @@ sub combine { my (@roles, %role_params); while (@role_specs) { my ($role, $params) = @{ splice @role_specs, 0, 1 }; - push @roles => $role->meta; + push @roles => Class::MOP::class_of($role); next unless defined $params; $role_params{$role} = $params; } @@ -490,8 +479,6 @@ sub create { || confess "You must pass a HASH ref of methods" if exists $options{methods}; - $role->SUPER::create(%options); - my (%initialize_options) = %options; delete @initialize_options{qw( package @@ -503,6 +490,8 @@ sub create { my $meta = $role->initialize( $package_name => %initialize_options ); + $meta->_instantiate_module( $options{version}, $options{authority} ); + # FIXME totally lame $meta->add_method('meta' => sub { $role->initialize(ref($_[0]) || $_[0]); @@ -782,6 +771,10 @@ L, object, a L object, or a The options are passed directly to the constructor for the appropriate L subclass. +Note that this will apply the role even if the C<$thing> in question already +C this role. L is a convenient wrapper for +finding out if role application is necessary. + =back =head2 Roles and other roles