Package: libtest-mockmodule-perl Version: 0.05-2 Severity: normal Tags: upstream Forwarded: https://rt.cpan.org/Ticket/Display.html?id=77439
When unmocking a method that was not originally defined in the mocked module, but rather inherited from a parent class, unmock() will install a copy of the inherited method in the child class. This will subtly break if the parent method ever changes, such as illustrated in the attached example. I think that mock() should not bother with can() if &{$sub_name} does not exist, and merely store undef. (OTOH, it may be argued that original() should returned the inherited method. Hmm.) -- System Information: Debian Release: wheezy/sid APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (x86_64) Kernel: Linux 3.2.0-2-amd64 (SMP w/3 CPU cores) Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages libtest-mockmodule-perl depends on: ii perl 5.14.2-10 libtest-mockmodule-perl recommends no packages. libtest-mockmodule-perl suggests no packages. -- no debconf information
#!/usr/bin/perl use 5.10.0; use Test::MockModule; @Bar::ISA = 'Foo'; @Baz::ISA = 'Bar'; sub Foo::motto { 'Foo!' }; say Foo->motto(), Bar->motto(), Baz->motto(); { my $mock_bar = new Test::MockModule('Bar', no_auto => 1); $mock_bar->mock('motto', sub { 'Bar!' }); my $mock_baz = new Test::MockModule('Baz', no_auto => 1); $mock_baz->mock('motto', sub { 'Baz!' }); say Foo->motto(), Bar->motto(), Baz->motto(); } say Foo->motto(), Bar->motto(), Baz->motto();