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