Module loading order

Module loading order

am 13.02.2006 05:42:20 von newtan

Hello,

Description:

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

am 17.02.2006 16:29:51 von Stephan Titard

newtan@gmail.com escribió:
> Hello,
>
> Description:
>
> 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;
careful with this it is a *core* package (compiler suite)
better to use A1 A2 and test again

HTH stephan

> 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.
>