MooseX::LexicalRoleApplication - Apply roles for a lexical scope only


MooseX-LexicalRoleApplication documentation  | view source Contained in the MooseX-LexicalRoleApplication distribution.

Index


NAME

Top

MooseX::LexicalRoleApplication - Apply roles for a lexical scope only

VERSION

Top

version 0.03

SYNOPSIS

Top

  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

Top

This module allows applying a role for the duration of a lexical scope only.

CAVEATS

Top

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

Top

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

Top

Florian Ragwitz <rafl@debian.org>

COPYRIGHT AND LICENSE

Top


MooseX-LexicalRoleApplication documentation  | view source Contained in the MooseX-LexicalRoleApplication distribution.