Friday, January 26, 2007

Perl オブジェクト指向 Class 継承

HogeA.pm
package HogeA;
use strict;
sub new {
my $class = shift;
my $self = bless {}, $class;
return $self;
}
sub hoge {
my $self = shift;
print "Hoge::hoge\n";
}
1;


HogeB.pm
package HogeB;
use strict;
use base qw(HogeA);
sub new {
my $class = shift;
my $self = bless {}, $class;
return $self;
}
sub hogehoge{
print "hogehoge\n";
}
1;

---sample.pl
use strict;
use HogeB;
my $b = HogeB->new();
$b->hoge;

ISAも使えます。

No comments: