in reply to Re: Altering Package Subs and Running In To Problems
in thread Altering Package Subs and Running In To Problems
You should probably use @ISA and SUPER when you want to override methods from existing modules. Something like:
If you do it this way the whole system becomes extensible - you'll note that I never mention Sybase::DBlib in the package itself - only in the @ISA - and this lets perl decide at run-time what methods to call based on the inheritance tree.package My::Db; use Sybase::DBlib; our @ISA=qw(Sybase::DBlib); # new() is only needed if you need to do additional # stuff - otherwise Sybase::DBlib's new() is called # automatically sub new { my $package = shift; my $dbh = $package::SUPER->new(@_); # do something with $dbh here .... return $dbh; } # Override dbnextrow() to allow ad-hoc processing sub dbnextrow { my $self = shift; # Call the real dbnextrow() my @row = $self::SUPER->dbnextrow(@_); # and now do some magic with @row before # returning it... .... return @row; }
Michael
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Altering Package Subs and Running In To Problems
by aufflick (Deacon) on Nov 12, 2004 at 13:39 UTC | |
by mpeppler (Vicar) on Nov 12, 2004 at 13:44 UTC | |
by aufflick (Deacon) on Jan 11, 2005 at 00:19 UTC |