1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#!perl
BEGIN
{
chdir 't' if -d 't';
}
use lib '../lib';
use strict;
use warnings;
use Test::More tests => 7;
# Being able to say SUPER() once is neat, but I want to super all
# the way back up to the root of the tree, passing different arguments
package Grandfather;
Test::More->import();
sub foo
{
my ($self, $from) = @_;
pass( 'Called on the Grandfather' );
is( $from, 'Father', '... from the father' );
return __PACKAGE__;
}
package Father;
Test::More->import();
use SUPER;
use base qw( Grandfather );
my $called;
sub foo
{
my ($self, $from) = @_;
die "Recursed on Father (should have called Grandfather)"
if ++$called > 1;
pass( 'Called on the Father' );
is( $from, 'Son', '... from the son' );
my $super_class = $self->SUPER( __PACKAGE__ );
is( $super_class, 'Grandfather', '... (whose parent is the grandfather)' );
return __PACKAGE__;
}
package Son;
Test::More->import();
use SUPER;
use base qw( Father );
sub foo
{
my $self = shift;
pass( 'Called on the Son' );
my $super_class = $self->SUPER( __PACKAGE__ );
is( $super_class, 'Father', '... (whose parent is the father)' );
}
package main;
Son->foo();
|