[Omaha.pm] Hey OO Perl 5: Do my base classes thing plus my thing

Jay Hannah jhannah at omnihotels.com
Thu Sep 15 13:58:09 PDT 2005


Project: 

Build 2 classes, A and B. B inherits to A. B->go() should do whatever
A->go() does plus some other stuff.



Solution:

$ cat j.pl
use vars qw( @ISA );

package A;
sub go {
   print "Perl "
}

package B;
@ISA = ("A");
sub new { return bless {} }
sub go {
   my ($self) = @_;
   $self->SUPER::go;
   print "Rulz!\n";
}

package main;
my $obj = B->new();
$obj->go;



In action:

$ perl j.pl
Perl Rulz!



HTH,

j


More information about the Omaha-pm mailing list