in reply to Re^3: Mocking a method defined in a Moo Role
in thread Mocking a method defined in a Moo Role
Thanks to mst on #moose:
package MyClass; use Moo; use FindBin qw($Bin); use lib $Bin; with 'MyRole'; around foo => sub { my ($orig, $self) = @_; return 'Wrapped ' . $self->$orig; };
use 5.016; use FindBin qw($Bin); use lib qq($Bin); require MyRole; our $orig = MyRole->can('foo'); no warnings 'redefine'; *MyRole::foo = sub { goto &$orig }; { local $orig = sub {'baz'}; require MyClass; my $obj = MyClass->new; my $res = $obj->foo; if ( $res =~ /baz$/ ) { say qq{OK, got $res}; } else { say qq{Not OK, got $res}; } }
|
|---|