File: 1.t

package info (click to toggle)
libsuper-perl 1.20120705-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 132 kB
  • ctags: 9
  • sloc: perl: 424; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 831 bytes parent folder | download | duplicates (2)
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
#!perl
use strict;
use warnings;

use Test::More tests => 7;

package Daddy;

Test::More->import();

sub new { bless {}, shift }

sub foo
{
	my $self = shift;
	isa_ok( $self, "Kid" );
	is( $_[0], 123, "Arguments passed OK" );
}

package Kid;

Test::More->import();
@Kid::ISA = 'Daddy';

use SUPER;

sub foo
{
	my $self = shift;
	if ( $_[0] > 100 )
	{
		super;
	}
	else
	{
		is( $_[0], 50, "Arguments retained OK" )
	}
}

my $a = Kid->new();
$a->foo(123);
$a->foo(50);

is( $a->super( 'new' ), \&Daddy::new, 'Kid inherits new() from Daddy' );
is( $a->super( 'foo' ), \&Daddy::foo,
	'... as it does foo, even though it overrides it' );
is( SUPER->super( 'import' ),
	\&Exporter::import, "SUPER's import comes from Exporter" );
is( Test::Builder::Module->super( 'import' ),
	\&Exporter::import, '... as does Test::Builder::Module' );