in reply to Role::Tiny: When to use apply_roles_to_object?
Hi kgb,
I use that function in two ways.
For example:
use Test::Most 'die'; use Role::Tiny; package MyClass { # standing in for the real consumer of the role, # which is expensive to instantiate in some way ... use Moo; }; package MyRole { use Moo::Role; sub foo { 42 } }; subtest 'Applying' => sub { my $o = MyClass->new; is( ref $o, 'MyClass', 'object instantiated' ); ok( Role::Tiny->apply_roles_to_object($o, 'MyRole'), 'role applied +' ); is( $o->foo, 42, 'method in Role works!' ); }; done_testing;
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Role::Tiny: When to use apply_roles_to_object?
by karlgoethebier (Abbot) on May 02, 2019 at 16:55 UTC |