C
cyl
When an AUTOLOAD function is implemented, I can do something such as
delegating a nonexistent method to another package. I'm wondering if
there is a similar way to do this for variables exported by a module?
Here is my demonstration sample code
#### main.pl ####
use TestA;
use TestB;
TestB::FuncA();
print $TestB::VarA;
#### TestA.pm ####
package TestA;
@ISA = qw(Exporter);
@EXPORT = qw($VarA);
our $VarA = "VarA";
sub FuncA
{
print "TestA\n";
}
#### TestB.pm ####
package TestB;
#our $VarA = $TestA::VarA;
1;
sub AUTOLOAD
{
$AUTOLOAD =~ s/TestB/TestA/;
&$AUTOLOAD;
}
__END__
Running the script will get TestA::FuncA invoked but $TestB::VarA
undefined unless I remove the comment in TestB.pm. I want to know a
method that can do the transparent relay for a nonexistent variable in
TestB to TestA. Thanks.
delegating a nonexistent method to another package. I'm wondering if
there is a similar way to do this for variables exported by a module?
Here is my demonstration sample code
#### main.pl ####
use TestA;
use TestB;
TestB::FuncA();
print $TestB::VarA;
#### TestA.pm ####
package TestA;
@ISA = qw(Exporter);
@EXPORT = qw($VarA);
our $VarA = "VarA";
sub FuncA
{
print "TestA\n";
}
#### TestB.pm ####
package TestB;
#our $VarA = $TestA::VarA;
1;
sub AUTOLOAD
{
$AUTOLOAD =~ s/TestB/TestA/;
&$AUTOLOAD;
}
__END__
Running the script will get TestA::FuncA invoked but $TestB::VarA
undefined unless I remove the comment in TestB.pm. I want to know a
method that can do the transparent relay for a nonexistent variable in
TestB to TestA. Thanks.