Skip Menu |

This queue is for tickets about the Test-MockObject CPAN distribution.

Report information
The Basics
Id: 24716
Status: resolved
Priority: 0/
Queue: Test-MockObject

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 1.07
Fixed in: (no value)



Subject: Please do not use UNIVERSAL::can and UNIVERSAL::isa
My test suite suddenly started spewing out this... Called UNIVERSAL::can() as a function, not a method at /usr/lib/perl5/site_perl/5.8.0/Class/DBI.pm line 265 Which is true, but its a warning I'd never seen before. Oddly enough, this was only showing up during testing. I couldn't reproduce that warning in production. I couldn't get the warning with something like this: perl -wle 'UNIVERSAL::can("foo", "bar"); Took me some time to track down where it was coming from... the UNIVERSAL::can module called inside Test::MockObject! UNIVERSAL::can and isa do not appear to be important to the functionality of MockObject. I can stub them out and all the tests pass fine. MockObject is infecting my entire test suite with universal, non-critical, annoying functionality. Its causing warnings in code not under my direct control. While I understand the reasons why one should not call UNIVERSAL::can and isa as functions, its not MockObject's job to Spread The Good Word.
As discussed on perl-qa, if the intention of using UNIVERSAL::isa/can is to warn the user about code which does not honor mocked objects then MockObject should only warn if UNIVERSAL::isa/can is called on a mocked object. Something like this: my $real_isa = \&UNIVERSAL::isa; *UNIVERSAL::isa = sub { my $obj = shift; my $class = shift; local $SIG{__DIE__}; if( ref $obj and eval { $obj->$real_isa("Test::MockObject") } ) { warn "OMG UNIVERSAL::isa() called as a function on a mocked object, lusr! Turning it into a method call."; return $obj->isa($class); } else { # retain the original functionality. return $real_isa->($obj, $class); } };
Resolved in the newest versions of U::c and U::i.