NAME
MooseX::LexicalRoleApplication - Apply roles for a lexical scope only
VERSION
version 0.03
SYNOPSIS
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
DESCRIPTION
This module allows applying a role for the duration of a lexical scope only.
CAVEATS
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);
}
METHODS
apply ($role, $instance, \%rebless_params, \%application_options)
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.
AUTHOR
Florian Ragwitz <rafl@debian.org>
COPYRIGHT AND LICENSE
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.