X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole.pm;h=3669b873d469316e1762090df176ec119d7b801f;hb=68efb0148447f7c638d4278e2d002bc3bb13cfbb;hp=3343dbd802ea48f4b23c071aee000f23ba5b9ba0;hpb=d7c045596ea4a7bb623051f00fd99b0d95411910;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 3343dbd..3669b87 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -13,14 +13,9 @@ use Moose::Meta::Class; our $VERSION = '0.04'; -## Attributes - -## the meta for the role package +use base 'Class::MOP::Module'; -__PACKAGE__->meta->add_attribute('_role_meta' => ( - reader => '_role_meta', - init_arg => ':role_meta' -)); +## Attributes ## roles @@ -52,17 +47,7 @@ __PACKAGE__->meta->add_attribute('required_methods' => ( ## Methods -sub new { - my $class = shift; - my %options = @_; - $options{':role_meta'} = Moose::Meta::Class->initialize( - $options{role_name}, - ':method_metaclass' => 'Moose::Meta::Role::Method' - ) unless defined $options{':role_meta'} && - $options{':role_meta'}->isa('Moose::Meta::Class'); - my $self = $class->meta->new_object(%options); - return $self; -} +sub method_metaclass { 'Moose::Meta::Role::Method' } ## subroles @@ -141,19 +126,10 @@ sub _clean_up_required_methods { ## methods -# NOTE: -# we delegate to some role_meta methods for convience here -# the Moose::Meta::Role is meant to be a read-only interface -# to the underlying role package, if you want to manipulate -# that, just use ->role_meta - -sub name { (shift)->_role_meta->name } -sub version { (shift)->_role_meta->version } - -sub get_method { (shift)->_role_meta->get_method(@_) } -sub find_method_by_name { (shift)->_role_meta->find_method_by_name(@_) } -sub has_method { (shift)->_role_meta->has_method(@_) } -sub alias_method { (shift)->_role_meta->alias_method(@_) } +sub get_method { (shift)->Moose::Meta::Class::get_method(@_) } +sub find_method_by_name { (shift)->Moose::Meta::Class::find_method_by_name(@_) } +sub has_method { (shift)->Moose::Meta::Class::has_method(@_) } +sub alias_method { (shift)->Moose::Meta::Class::alias_method(@_) } sub get_method_list { my ($self) = @_; grep { @@ -163,7 +139,7 @@ sub get_method_list { # but they do, so we need to switch Moose::Role # and Moose to use Sub::Exporter to prevent this !/^(meta|has|extends|blessed|confess|augment|inner|override|super|before|after|around|with|requires)$/ - } $self->_role_meta->get_method_list; + } $self->Moose::Meta::Class::get_method_list; } # ... however the items in statis (attributes & method modifiers) @@ -298,8 +274,8 @@ sub _apply_methods { # is probably fairly safe to assume that # anon classes will only be used internally # or by people who know what they are doing - $other->_role_meta->remove_method($method_name) - if $other->_role_meta->name =~ /__ANON__/; + $other->Moose::Meta::Class::remove_method($method_name) + if $other->name =~ /__ANON__/; } else { next; @@ -330,12 +306,16 @@ sub apply { $other->add_role($self); } +my $anon_counter = 0; + sub combine { my ($class, @roles) = @_; - my $combined = $class->new( - ':role_meta' => Moose::Meta::Class->create_anon_class() - ); + my $pkg_name = __PACKAGE__ . "::__ANON__::" . $anon_counter++; + eval "package " . $pkg_name . "; our \$VERSION = '0.00';"; + die $@ if $@; + + my $combined = $class->initialize($pkg_name); foreach my $role (@roles) { $role->apply($combined); @@ -422,6 +402,8 @@ probably not that much really). =over 4 +=item B + =item B =item B