PerlOnTheWay has asked for the wisdom of the Perl Monks concerning the following question:
Father.pm#! /usr/bin/perl use strict; use warnings; use Test::MockModule; my $father = Test::MockModule->new('Father'); $father->mock(alert => sub { print 'replaced by try' . $/; }); do 'Son.pm';
Son.pm:package Father; sub alert { print 'father' . $/; } 1
package Son; use base Father; sub new { bless {}, Son; *{'Father::alert'} = sub { print 'son' . $/; }; } Son->new->alert();
When I run try.t,nothing is outputed
But if I delete the typeglob operation in Son.pm, I can get something outputed
why?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why mock doesn't work in this case?
by tobyink (Canon) on Jan 06, 2012 at 10:05 UTC |