I have a method, let's call it "foo" defined in a Moo Role.
package 'MyRole'; use Moo::Role; sub foo { return 'blah'; }
In a consuming class, I have some behavior implemented in an "around" modifier:
package MyClass; use Moo; with 'MyRole'; around foo => sub { my ($self, $orig) = @_; if ($self->$orig eq 'baz') { return 'bak'; } return $self->$orig; }
I would like to test this behavior, but I can't figure out how to mock MyRole::foo. If I mock MyClass::foo, the around() modifier isn't called. How do I test this around() behavior?
Here's what I'm trying:
use MyClass; use Test::Most; use Test::MockModule; my $mock = Test::MockModule->new('MyRole'); $mock->mock('foo' => sub { return 'baz' }); my $obj = MyClass->new; # Does not work is $obj->foo, 'bak', 'Foo is what it oughtta be';
In reply to Mocking a method defined in a Moo Role by PopeFelix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |