http://www.perlmonks.org?node_id=459039

the_slycer has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, we've recently run into a problem in our testing environment.. to make a long story shorter, we have a whack of crons that run. We have finally setup a test cron server. Problem is that half of the crons are FTP'ing data somewhere. This brings up a big problem, in that we can't properly test the crons because we're ftp'ing data to "live" servers.

So, one of the ideas that we've kicked around, and seems to be a simple solution, is to build a wrapper/proxy class around the Net::FTP module, and on connection (and login), overwrite the passed options with our test ftp server information.

The problem is, I can't seem to get this to work quite right, here's what I've got so far:
package Custom::FTP; use Net::FTP; @ISA = ('Net::FTP'); #proxy module for Net::FTP - allows us to change hostname etc for test +ing purposes sub new { my $class = shift; my $self = {}; bless $self, $class; my $remote_host = shift; #check to see where we are if ( _not_prod() ) { $remote_host = 'our.test.host'; } $self->{parent} = Net::FTP->new($remote_host, @_); return $self; } sub login { my $self = shift; my @opts = @_; if ( _not_prod() ) { $opts[0] = 'testuser'; $opts[1] = 'testpassword'; } my $parent = $self->{parent}; return $parent->login(@opts); } sub _not_prod { #more code }
Which seems to work fine, however, calling a $ftp->ls() on the returned object does not quite do what I need, I get an error stating Not a GLOB reference at /usr/lib/perl5/site_perl/5.6.0/Net/FTP.pm line 905. Looking into the Net::FTP module, I can see why this is happening, the module is being called with a class of Custom::FTP rather than Net::FTP, which means that the variable passed in as the "object" is the Custom::FTP object rather than the parent object.. and the GLOB on line 905 is accessing an undef'd value.

So, one way around this is to write a custom ls subroutine in the Custom::FTP module, but this seems to be "wrong" in that it's not inheritance of any kind, rather it's overriding every routine in the Net::FTP module to simply call the parent class's routine..

Is there some other way to handle this? Am I not inheriting correctly? And before anybody makes the suggestion, I'd love to rewrite all our crap to include proper test flags etc, but the lack of time to do so is a big factor in finding another way..