Module loading order

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View



package A;
my $instance;
sub new {
     my $class = shift;
     my %args = @_;
     return $instance if $instance;
     . . . stuff appropriate args into $instance ...
     return bless $instance, $class;
. . .

package B;
use A;
our @ISA = qw(A);
__PACKAGE_->SUPER::new(some args);
. . .

package XYZ;
use A;
my $o = new A;
. . .

Now using them

1 - This will work
#!/usr/bin/perl -w
use strict;
use B;
use XYZ;

2 - This won't work
#!/usr/bin/perl -w
use strict;
use XYZ;
use B;                       <= this won't work

Since in XYZ the singleton $o is actually instantiated with appropriate
parameters by the line __PACKAGE__->SUPER::new in B, the order of
module loading in 1) will work while that in 2) won't  as 'use' implies
BEGIN blocks in FIFO.

Question: is there a way to ensure that a certain module is always
loaded before other modules no matter where it is with "use". In this
case, how can B be assured to be loaded before other aforementioned
modules? Thanks.

Re: Module loading order escribió:
Quoted text here. Click to load it
careful with this it is a *core* package (compiler suite)
better to use A1 A2 and test again

HTH stephan

Quoted text here. Click to load it

Site Timeline