Subject: | Module's ->can can't use SUPER w/o unending recursion |
SUPER calls a module's own ->can() method while dispatching the
$obj->SUPER call. This means a module can't use SUPER inside of its own
->can method without triggering an infinite loop.
The attached test fails when a simple ->can redispatches. SUPER should
detect that it's already handling ->can and avoid starting the infinite
loop.
The find_method method should avoid using ->can on a module that is
already using SUPER for it's ->can.
Subject: | can.t |
#!perl
use Test::More tests => 2;
use Test::Exception;
use strict;
package Mars;
sub rock_out { return 'Rrraaawwwr!'; }
package Venus;
use SUPER;
@VENUS::isa = 'Mars';
sub new {
# A generic constructor.
my $class = shift @_;
return bless [], $class;
}
sub can {
my $obj = shift @_;
# Delegate and make damn sure that accidental infinite
# recursion is deadly for purposes of these tests.
use warnings FATAL => 'recursion';
$obj->SUPER;
}
package main;
my $obj = Venus->new;
lives_ok { $obj->can('rock_out') } q[No deep recursion];
eval { is( Venus->can('rock_out'), \&Mars::rock_out, '$Class->can worked' ); };
if ($@) {
fail('$Class->can worked');
}