X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FUtil%2FMetaRole.pm;h=1b29b60985e285d3fee5355b1bf026e35f1b984e;hp=21dc594e738713d8459def77f96c7e2d5acbca1c;hb=add53fbe34ef5360a8474ac4a1aa6914217abe56;hpb=733f404b1631c344ec33fc9b23a90558cf06d781 diff --git a/lib/Mouse/Util/MetaRole.pm b/lib/Mouse/Util/MetaRole.pm index 21dc594..1b29b60 100644 --- a/lib/Mouse/Util/MetaRole.pm +++ b/lib/Mouse/Util/MetaRole.pm @@ -16,6 +16,10 @@ sub apply_metaroles { ? $args{for} : Mouse::Util::get_metaclass_by_name( $args{for} ); + if(!$for){ + Carp::confess("You must pass an initialized class, but '$args{for}' has no metaclass"); + } + if ( Mouse::Util::is_a_metarole($for) ) { return _make_new_metaclass( $for, $args{role_metaroles}, 'role' ); } @@ -161,22 +165,24 @@ Mouse::Util::MetaRole - Apply roles to any metaclass, as well as the object base sub init_meta { shift; - my %options = @_; + my %args = @_; - Mouse->init_meta(%options); + Mouse->init_meta(%args); - Mouse::Util::MetaRole::apply_metaclass_roles( - for_class => $options{for_class}, - metaclass_roles => ['MyApp::Role::Meta::Class'], - constructor_class_roles => ['MyApp::Role::Meta::Method::Constructor'], + Mouse::Util::MetaRole::apply_metaroles( + for => $args{for_class}, + class_metaroles => { + class => ['MyApp::Role::Meta::Class'], + constructor => ['MyApp::Role::Meta::Method::Constructor'], + }, ); Mouse::Util::MetaRole::apply_base_class_roles( - for_class => $options{for_class}, - roles => ['MyApp::Role::Object'], + for => $args{for_class}, + roles => ['MyApp::Role::Object'], ); - return $options{for_class}->meta(); + return $args{for_class}->meta(); } =head1 DESCRIPTION @@ -207,34 +213,60 @@ method for you, and make sure it is called when imported. This module provides two functions. -=head2 apply_metaclass_roles( ... ) +=head2 apply_metaroles( ... ) This function will apply roles to one or more metaclasses for the specified class. It accepts the following parameters: =over 4 -=item * for_class => $name +=item * for => $name + +This specifies the class or for which to alter the meta classes. This can be a +package name, or an appropriate meta-object (a L or +L). + +=item * class_metaroles => \%roles + +This is a hash reference specifying which metaroles will be applied to the +class metaclass and its contained metaclasses and helper classes. + +Each key should in turn point to an array reference of role names. + +It accepts the following keys: + +=over 8 -This specifies the class for which to alter the meta classes. +=item class -=item * metaclass_roles => \@roles +=item attribute -=item * attribute_metaclass_roles => \@roles +=item method -=item * method_metaclass_roles => \@roles +=item constructor -=item * constructor_class_roles => \@roles +=item destructor -=item * destructor_class_roles => \@roles +=back + +=item * role_metaroles => \%roles + +This is a hash reference specifying which metaroles will be applied to the +role metaclass and its contained metaclasses and helper classes. + +It accepts the following keys: -These parameter all specify one or more roles to be applied to the -specified metaclass. You can pass any or all of these parameters at -once. +=over 8 + +=item role + +=item method + +=back =back -=head2 apply_base_class_roles( for_class => $class, roles => \@roles ) +=head2 apply_base_class_roles( for => $class, roles => \@roles ) This function will apply the specified roles to the object's base class.