On Monday, August 26, 2002, at 03:40 , Connie Chan wrote:
> package A;
> use strict;
> require Exporter;
> our @ISA = qw (Exporter); # What this actually for ?!
One way to think of this as a way of stopping the questions
about 'isa' - cf
perldoc UNIVERSAL
In this case it is an Exporter . but if you
play with say:
require HTML::HeadParser;
print "is a: $_ \n" for @HTML::HeadParser::ISA;
you will note that it return
is a: HTML::Parser
because just as in your package you said you
were a 'sub_class' of Exporter, in their package
they said that they were a sub_class of HTML::Parser.
you might try say:
use HTML::HeadParser;
my $p = new HTML::HeadParser;
#my $upper = ref($p->SUPER::new());
do_the_chain($p);
#------------------------
#
sub do_the_chain {
my ($ref) = @_;
my $p_is = ref($ref);
no strict "refs";
my @upper = @{"${p_is}::ISA"};
print "\$ref is a <$p_is> \n " ;
for my $parent (@upper) {
print "\tis a child of class $parent \n";
if ( UNIVERSAL::can($parent, 'new' )) {
my $p_type = new $parent;
do_the_chain($p_type);
}
}
} # end of do_the_chain
and you will get output like:
$ref is a <HTML::HeadParser>
is a child of class HTML::Parser
$ref is a <HTML::Parser>
is a child of class DynaLoader
[..]
>
> My question is, will perl re- assign the hash whenever
> a 'use package A' declared ? or when Perl found the package
> had loaded once, it won't load again ?
remember that 'use' goes through and does two things
a) require the package
b) import the package
in the first phase, as you will noted in the explaination
in perldoc -f require - it will return 1, IF it has already
been through the process of 'doing' the package....
the import phase sorts out the 'name space issues. So it
really is not a good idea of export the same variable
name from
package A
package B
since you are trying to stuff them into the same space:
%main::hash;
[..]
> 2. using sub to assign value (ie. .... our %hash ; sub GenHash { ..... }
> GenHash; 1; )
This sounds more promising as an idea - especially if you return
a reference to the hash and do not export the same function name
from each package -
hence you might have
use pack_a;
use pack_b;
my $a_hash_ref = pack_a::generate_hash();
my $b_hash_ref = pack_b::generate_hash();
or if you go REALLY freaky you could look at the sub_class
approach where in package A
package A
our @ISA = qw(Exporter);
.....
sub generate_hash {
}
next file
package B
@ISA = qw(A);
sub generate_hash {
# foist we get our parents hash
my $upper = $self->SUPER::generate_hash();
#
# now we add our stuff here
#
$upper->{b1} = "this block one";
$upper->{b2} = "this block two";
.....
return($upper);
}
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]