in reply to Re^2: GLOB reference problem
in thread GLOB reference problem
When you want to extend an existing class, you have two options: inheritance and aggregation. If you go the inheritance route your new method would look something like this:
use base qw(Net::FTP); #5.8 #or for 5.10 and up #use parent qw(Net::FTP); sub new { my ($pkg, $server, $user, $timeout, @args) = @_; # some special class specific stuff # ... is params for super class structure my $self = $pkg->SUPER::new(...); $self->server($server); $self->user($user); $self->timeout($timeout); $self->initialize(); # some special class specific stuff # if SUPER::new is well behaved, $self will be a member # of the $pkg class even though it was built by the # the super class. return $self; }
If you go the aggregation route you might do something like this:
sub new { my ($pkg, $server, $user, $timeout, @args) = @_; # some special class specific stuff # ... is params for super class structure my $ftp = Net::FTP->new(...); $ftp->server($server); $ftp->user($user); $ftp->timeout($timeout); $ftp->initialize(); my $self = { ftpHandle => $ftp }; return bless($self, $pkg); }
If you want your own class to be implemented using a hash, you would go with the aggregation approach since Net::FTP doesn't return a hash. If you want to return the same kind of implementation as Net::FTP, then you would follow the inheritance pattern. You might find the sections on inheritance and aggregation in perltoot worth a read.
Best, beth
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: GLOB reference problem
by jerryhone (Sexton) on Oct 05, 2009 at 11:12 UTC | |
by almut (Canon) on Oct 05, 2009 at 12:30 UTC | |
by ELISHEVA (Prior) on Oct 05, 2009 at 11:59 UTC |
In Section
Seekers of Perl Wisdom