X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole%2FComposite.pm;h=e3a6d570b09c7c410c1a5702ba170d53ff2fba7c;hb=462bdc732ebe32abf5b9f3cd40033540a5f1388f;hp=4c6b13e54e0117976e7380979996389b60d7d84f;hpb=12d8c847e0189d0708f9fa3bedd7ec2ebe6e506b;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role/Composite.pm b/lib/Moose/Meta/Role/Composite.pm index 4c6b13e..e3a6d57 100644 --- a/lib/Moose/Meta/Role/Composite.pm +++ b/lib/Moose/Meta/Role/Composite.pm @@ -6,10 +6,6 @@ use metaclass; use Scalar::Util 'blessed'; -our $VERSION = '0.89_02'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - use base 'Moose::Meta::Role'; # NOTE: @@ -25,8 +21,8 @@ __PACKAGE__->meta->add_attribute('name' => (reader => 'name')); # package to store our methods in, # we use a HASH ref instead. # - SL -__PACKAGE__->meta->add_attribute('methods' => ( - reader => 'get_method_map', +__PACKAGE__->meta->add_attribute('_methods' => ( + reader => '_method_map', default => sub { {} } )); @@ -48,9 +44,7 @@ sub new { } my @composition_roles = map { - $_->has_composition_class_roles - ? @{ $_->composition_class_roles } - : () + $_->composition_class_roles } @{ $params{roles} }; if (@composition_roles) { @@ -59,7 +53,6 @@ sub new { roles => [ @composition_roles ], cache => 1, ); - $meta->add_method(meta => sub { $meta }); $class = $meta->name; } @@ -95,7 +88,29 @@ sub add_method { $method = $self->wrap_method_body( body => $body, name => $method_name ); } - $self->get_method_map->{$method_name} = $method; + $self->_method_map->{$method_name} = $method; +} + +sub get_method_list { + my $self = shift; + return keys %{ $self->_method_map }; +} + +sub _get_local_methods { + my $self = shift; + return values %{ $self->_method_map }; +} + +sub has_method { + my ($self, $method_name) = @_; + + return exists $self->_method_map->{$method_name}; +} + +sub get_method { + my ($self, $method_name) = @_; + + return $self->_method_map->{$method_name}; } sub apply_params { @@ -109,16 +124,30 @@ sub apply_params { return $self; } +sub reinitialize { + my ( $class, $old_meta, @args ) = @_; + + Moose->throw_error( + 'Moose::Meta::Role::Composite instances can only be reinitialized from an existing metaclass instance' + ) + if !blessed $old_meta + || !$old_meta->isa('Moose::Meta::Role::Composite'); + + my %existing_classes = map { $_ => $old_meta->$_() } qw( + application_role_summation_class + ); + + return $old_meta->meta->clone_object( $old_meta, %existing_classes, @args ); +} + 1; +# ABSTRACT: An object to represent the set of roles + __END__ =pod -=head1 NAME - -Moose::Meta::Role::Composite - An object to represent the set of roles - =head1 DESCRIPTION A composite is a role that consists of a set of two or more roles. @@ -157,27 +186,17 @@ the composite role to it. The RoleSummation role application class used is determined by the composite role's C attribute. +=item * reinitialize($metaclass) + +Like C<< Class::MOP::Package->reinitialize >>, but doesn't allow passing a +string with the package name, as there is no real package for composite roles. + =back =back =head1 BUGS -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Stevan Little Estevan@iinteractive.comE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006-2009 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. +See L for details on reporting bugs. =cut