Click here to get back home

Module loading order

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Module loading order newtan 02-12-2006
Posted by newtan on February 12, 2006, 11:42 pm
Please log in for more thread options


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.


Posted by Stephan Titard on February 17, 2006, 10:29 am
Please log in for more thread options


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

Similar ThreadsPosted
Which module should I use in order to load files over the internet? October 5, 2006, 3:38 pm
Apache::SSIChain Out of Order November 8, 2004, 8:40 pm
$db->DataHash does not return keys/fields in same order as they appear in database September 16, 2007, 11:59 am
Loading Perl Modules faster January 21, 2005, 3:26 am
LWP fail to catch loading balacing websites March 9, 2005, 6:10 am
Loading (from Internet), resizing and saving images March 22, 2005, 6:15 am
Loading Perl Modules from same directory as script February 13, 2006, 5:27 pm
Loading Perl Modules from same directory as script February 13, 2006, 5:35 pm
AppConfig loading undef values into ARGCOUNT_LIST March 22, 2007, 2:54 pm
Lower case module name for non-pragma module January 4, 2005, 10:19 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap