Subject: | Applying role with modifier documentation |
Hi
I've found documentation about applying roles with modifiers to be incomplete in Moose::Meta::Role.pm:
"However, method modifiers are simply stored internally, and are not applied until the role itself is applied to a class."
I think it is worth to also mention that when role is applied to an INSTANCE of a class modifiers are also applied only to this instance.
===============
package A;
use Moose;
sub foo { print "foo" };
package Ar;
use Moose::Role;
package main;
my $a1 = A->new;
my $a2 = A->new;
Ar->meta->add_after_method_modifier("foo", sub {print "bar"});
Ar->meta->apply($a1); # apply on specific instance
$a1->foo; # will print "foobar"
$a2->foo; # will print "foo"
===============
This is DWIM behavior, not a bug. Just worth documenting as an reference for people asking "how to apply method modifiers only to specific class instances".