Any of the following three lines of code would create a sub named new_sub in the package Test, no matter which file contained the code.
Ah, but only the one with a package statement will necessarily use Test as the package for finding unqualified global variables. One-arg bless, caller() in called routines, and SUPER:: also will be affected, as well as probably other things that I'm unable to think of ATM. For all but trivial routines, using a proper package statement is best.
The following demonstrates how Nopkg::Super is connected to it's containing package "Pkg", not to "Nopkg":
$ cat pkg.pl
use strict;
use warnings;
sub main::Duper {
print "in main::Duper, called from pkg", scalar caller, "\n";
}
@Pkg::ISA = "Super";
@Nopkg::ISA = "main";
sub Super::Duper {
print "in Super::Duper, called from pkg ", scalar caller, "\n";
}
{
package Pkg;
sub Nopkg::Duper {
our @ISA; print "isa: @ISA\n";
my $obj = bless {}; print "blessed a ", ref($obj), "\n";
$obj->SUPER::Duper;
}
}
Nopkg::Duper();
sthoenna@DHX98431 ~/pbed
$ perl pkg.pl
isa: Super
blessed a Pkg
in Super::Duper, called from pkg Pkg
| [reply] [d/l] |
True. Thanks for eloborating.
| [reply] |