| MooseX-LexicalRoleApplication documentation | view source | Contained in the MooseX-LexicalRoleApplication distribution. |
MooseX::LexicalRoleApplication - Apply roles for a lexical scope only
version 0.03
my $obj = SomeClass->new;
$obj->method_from_role; # fails
{
my $guard = MooseX::LexicalRoleApplication->apply(SomeRole->meta, $obj);
$obj->method_from_role; # works
}
$obj->method_from_role; # fails
This module allows applying a role for the duration of a lexical scope only.
Actual lexical role application isn't quite supported yet. The following example won't do what it's supposed to just yet:
{
my $guard = MooseX::LexicalRoleApplication->apply($role, $obj);
$other_role->apply($obj);
}
Will apply $role to $instance. %rebless_params will be passed to
rebless_instance in Class::MOP::Class. %application_options will be passed
to apply in Moose::Meta::Role.
A Scope::Guard will be returned. Keep it around as long as you
want $role to be applied to $instance. You can cancel role removal by
calling dismiss on the returned scope guard. If you want to remove the role
immediately, you can simply undef the guard.
Florian Ragwitz <rafl@debian.org>
This software is copyright (c) 2010 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
| MooseX-LexicalRoleApplication documentation | view source | Contained in the MooseX-LexicalRoleApplication distribution. |