[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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