Home > Archive > PERL Modules > February 2006 > Module loading order
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Module loading order
|
|
| newtan@gmail.com 2006-02-13, 3:56 am |
| 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.
| |
| Stephan Titard 2006-02-17, 6:56 pm |
| 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.
>
|
|
|
|
|