From: Shawn M Moore Date: Sun, 9 Nov 2008 04:21:47 +0000 (+0000) Subject: First stab at generate_role; metas within metas.. X-Git-Tag: 0.05~104 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4534bdce16577d6b282b7a711de58248caa42d2c;p=gitmo%2FMooseX-Role-Parameterized.git First stab at generate_role; metas within metas.. --- diff --git a/lib/MooseX/Role/Parameterized.pm b/lib/MooseX/Role/Parameterized.pm index d2e40ad..f1fc28e 100644 --- a/lib/MooseX/Role/Parameterized.pm +++ b/lib/MooseX/Role/Parameterized.pm @@ -6,6 +6,8 @@ extends 'Moose::Exporter'; use MooseX::Role::Parameterized::Meta::Role; +our $CURRENT_ROLE; + __PACKAGE__->setup_import_methods( with_caller => ['parameter', 'role'], ); diff --git a/lib/MooseX/Role/Parameterized/Meta/Role.pm b/lib/MooseX/Role/Parameterized/Meta/Role.pm index 522c6ab..74f24e0 100644 --- a/lib/MooseX/Role/Parameterized/Meta/Role.pm +++ b/lib/MooseX/Role/Parameterized/Meta/Role.pm @@ -32,6 +32,25 @@ sub construct_parameters { $self->parameter_metaclass->construct_instance(@_); } +sub generate_role { + my $self = shift; + my %args = @_; + + confess "A role generator is required to generate roles" + unless $self->has_role_generator; + + my $role = Moose::Meta::Class->create_anon_class( + superclasses => ['Moose::Meta::Role'], + ); + + my $parameters = $self->construct_parameters(%args); + + local $MooseX::Role::Parameterized::CURRENT_ROLE = $role; + $self->role_generator->($parameters, $role); + + return $role->construct_instance; +} + __PACKAGE__->meta->make_immutable; no Moose;