[Catalyst] [OT] Universal::CAN warning from TT?
Jonathan Rockway
jon at jrock.us
Wed Nov 22 16:45:32 GMT 2006
Daniel McBrearty wrote:
> Just an annoyance, but I'd like to lose it.
Yes, Test::MockObject loads a special UNIVERSAL::can that warns you when
you use UNIVERSAL::can incorrectly. The problem with calling
UNIVERSAL::can like:
UNIVERSAL::can($something, 'method')
is that $something doesn't have a chance to override the 'can' that it
inherits from UNIVERSAL. This obviously breaks Test::MockObject, since
instances are Mock Objects and not real ones (method calls are faked
with AUTOLOAD, which UNIVERSAL::can doesn't know how to deal with).
Here's a rough equivalent:
package A;
sub foo { ... }
package C;
sub new { bless {} => 'C' }
our @ISA = 'A';
package main;
my $bar = C->new;
C::foo($bar);
You would never call a class method directly like that (because it won't
work), so you shouldn't do that with UNIVERSAL::can or UNIVERSAL::isa.
I don't see this with my version of TT, though. If you're using the
latest version, change
UNIVERSAL::can($object, 'method')
to
blessed $object && $object->can('method')
and send in a patch. Much cleaner.
--
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;
More information about the Catalyst
mailing list