Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Mixing subclasses
December 29, 2006, 11:39 pm
rate this thread
Quick question: I am using module Net::FTP::Recursive successfully,
however am having problems when the ftp server terminates a connection.
Note that a different module, Net::FTP::AutoReconnect, has a reconnect
feature to re-establish dropped ftp connections. These two modules were
written by different authors.
Because both modules are subclassses of Net::FTP, is it possible to use
them both? i.e. use Net::FTP::Recursive along with
Net::FTP::AutoReconnect , so the Recursive module has the AutoReconnect
capability? If so, what is the Perl syntax to make this happen in a
Re: Mixing subclasses
possible to create a class which inherits from both of these classes.
If you can manage to do that, you could then create an object of your
new class and use that to connect.
Net::FTP::Recursive creates five new methods: rget, rput, rls, rdir,
and rdelete. Net::FTP::AutoReconnect does its work by creating new
methods with the same name as the Net::FTP methods, and wrapping them
in its own _autoreconnect() subroutine. From what I can tell, you
would have to create a class that inherits from both classes, and
redefines Net::FTP::Recursive's five methods the way
Net::FTP::AutoReconnect redefines Net::FTP's.
You would also have to implement a constructor that does the
functionality of both modules' new() methods.
While none of this is exactly trivial, I think it should be possible.
To get you started, you need to read up on classes and inheritance.
The basic syntax you'll want to start your new class will look
something like this:
our @ISA = qw(Net::FTP::AutoReconnect Net::FTP::Recursive);
Hope this helps,