From: Florian Ragwitz Date: Tue, 14 Jul 2009 17:11:47 +0000 (+0200) Subject: Make the RoleSummation role application class an attribute of the composite metarole. X-Git-Tag: 0.90~41 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7071e2cbb253e6c9ede2055d1309614590616c7f;p=gitmo%2FMoose.git Make the RoleSummation role application class an attribute of the composite metarole. --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index e743023..f3363bf 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -514,7 +514,6 @@ sub apply { sub combine { my ($class, @role_specs) = @_; - require Moose::Meta::Role::Application::RoleSummation; require Moose::Meta::Role::Composite; my (@roles, %role_params); @@ -530,11 +529,7 @@ sub combine { } my $c = Moose::Meta::Role::Composite->new(roles => \@roles); - Moose::Meta::Role::Application::RoleSummation->new( - role_params => \%role_params - )->apply($c); - - return $c; + return $c->apply_params(\%role_params); } sub _role_for_combination { diff --git a/lib/Moose/Meta/Role/Composite.pm b/lib/Moose/Meta/Role/Composite.pm index 5c10037..c7329d4 100644 --- a/lib/Moose/Meta/Role/Composite.pm +++ b/lib/Moose/Meta/Role/Composite.pm @@ -30,6 +30,12 @@ __PACKAGE__->meta->add_attribute('methods' => ( default => sub { {} } )); +__PACKAGE__->meta->add_attribute( + 'application_role_summation_class', + reader => 'application_role_summation_class', + default => 'Moose::Meta::Role::Application::RoleSummation', +); + sub new { my ($class, %params) = @_; # the roles param is required ... @@ -74,6 +80,17 @@ sub add_method { $self->get_method_map->{$method_name} = $method; } +sub apply_params { + my ($self, $role_params) = @_; + Class::MOP::load_class($self->application_role_summation_class); + + $self->application_role_summation_class->new( + role_params => $role_params, + )->apply($self); + + return $self; +} + 1; __END__ @@ -115,6 +132,13 @@ L object. This is a required option. If a name is not given, one is generated from the roles provided. +=item * apply_params(\%role_params) + +Creates a new RoleSummation role application with C<%role_params> and applies +the composite role to it. The RoleSummation role application class used is +determined by the composite role's C +attribute. + =back =back diff --git a/xt/author/pod_spell.t b/xt/author/pod_spell.t index 2954753..6d2b98d 100644 --- a/xt/author/pod_spell.t +++ b/xt/author/pod_spell.t @@ -111,6 +111,7 @@ PosInt PositiveInt ro rw +RoleSummation Str TypeContraints