in reply to Re: Mocking a method defined in a Moo Role
in thread Mocking a method defined in a Moo Role
use strict; use warnings; package MyRole; use Moo::Role; sub call { my $self = shift; return undef; } package MyClass; use Moo; with 'MyRole'; around call => sub { my ($orig, $self) = @_; my $document = $self->$orig; unless ($document) { die 'Error'; } return $document; }; package main; use Test::More; no strict 'refs'; no warnings qw/redefine once/; *MyClass::call = sub { "tada!" }; ok my $class = MyClass->new(); ok $class->call(); done_testing;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Mocking a method defined in a Moo Role
by choroba (Cardinal) on Jun 29, 2016 at 15:35 UTC |