SUPER.pl
#!/usr/local/bin/perl -w
# SUPER.pl -- Zeigt die Verwendung der Pseudoklasse SUPER
package Base;
sub new {
my $cn = shift;
my $data = shift;
my $self = { data => $data };
return bless $self, $cn;
}
sub mytype {
my $self = shift;
return ref($self);
}
package Derived1;
@ISA = qw(Base);
sub new {
my $cn = shift;
my $data = shift;
my $moredata = shift;
my $self = $cn->SUPER::new($data);
$self->{'moredata'} = $moredata;
return $self;
}
sub mytype {
my $self = shift;
return ref($self);
}
package main;
my $obj = Derived1->new("data1", "data2");
print "Type: ", $obj->mytype(), "\n";
print "Data1:", $obj->{'data'}, "\n";
print "Data2:", $obj->{'moredata'}, "\n";