Why am I not able to call testmethod of parent using child object in the following code?
use strict;
use Data::Dumper;
my $a = C::Main->new('Email');
$a->testmethod();
package C::Main;
sub new {
my $class = shift;
my $type = shift;
$class .= "::" . $type;
my $fmgr = bless {}, $class;
$fmgr->init(@_);
return $fmgr;
}
sub init {
my $fmgr = shift;
$fmgr;
}
sub testmethod {
print "SSS";
}
package C::Main::Email;
use Net::FTP;
@C::Main::Email::ISA = qw( C::Main );
sub init {
my $fmgr = shift;
my $ftp = $fmgr->{ftp} = Net::FTP->new( $_[0] );
$fmgr;
}
package C::Main::FTP;
use strict;
use Net::FTP;
@C::Main::Email::FTP = qw( C::Main );
sub init {
my $fmgr = shift;
$fmgr;
}
use strict;in each package. Sincestrictis a lexically scoped pragma, it is in effect until the current scope ends. Package declarations do not create a scope, so ifuse strict;is placed at the top of a file, it is in scope for the entire file.