in reply to Mocking a method defined in a Moo Role

I don't have a precise answer, but saw Chad Granum's YAPC 2016 presentation on Test2, and saw there are some flexible tools for mocking that may be worth investigating. Chad showed a link to the Test2 manual, but it was too fine a font to read on the video. Perhaps someone else can include it.
  • Comment on Re: Mocking a method defined in a Moo Role

Replies are listed 'Best First'.
Re^2: Mocking a method defined in a Moo Role
by Anonymous Monk on Jun 29, 2016 at 15:22 UTC
    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;
      Which part of the code mocks the MyRole's call ?

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,