From: Shawn M Moore Date: Sun, 9 Nov 2008 05:31:10 +0000 (+0000) Subject: Add a new role metaclass for roles that have been parameterized X-Git-Tag: 0.05~93 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8f9a5c92edf885c6598110b9729cc51edc4d8097;p=gitmo%2FMooseX-Role-Parameterized.git Add a new role metaclass for roles that have been parameterized --- diff --git a/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm b/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm index 8664ba7..9fd9b76 100644 --- a/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm +++ b/lib/MooseX/Role/Parameterized/Meta/Role/Parameterizable.pm @@ -3,6 +3,7 @@ package MooseX::Role::Parameterized::Meta::Role::Parameterizable; use Moose; extends 'Moose::Meta::Role'; +use MooseX::Role::Parameterized::Meta::Role::Parameterized; use MooseX::Role::Parameterized::Parameters; has parameter_metaclass => ( @@ -39,12 +40,14 @@ sub generate_role { confess "A role generator is required to generate roles" unless $self->has_role_generator; + my $parameters = $self->construct_parameters(%args); + my $metaclass = Moose::Meta::Class->create_anon_class( - superclasses => ['Moose::Meta::Role'], + superclasses => ['MooseX::Role::Parameterized::Meta::Role::Parameterized'], + ); + my $role = $metaclass->construct_instance( + parameters => $parameters, ); - my $role = $metaclass->construct_instance; - - my $parameters = $self->construct_parameters(%args); local $MooseX::Role::Parameterized::CURRENT_METACLASS = $role; $self->role_generator->($parameters, diff --git a/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm b/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm new file mode 100644 index 0000000..a1a3b94 --- /dev/null +++ b/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +package MooseX::Role::Parameterized::Meta::Role::Parameterized; +use Moose; +extends 'Moose::Meta::Role'; + +has parameters => ( + is => 'rw', + isa => 'MooseX::Role::Parameterized::Parameters', + required => 1, +); + +__PACKAGE__->meta->make_immutable; + +1; +