Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"require Exporter" question

Status
Not open for further replies.

DoraC

Programmer
May 7, 2002
98
US
Hi,

I was perusing the Panther book (advanced perl programming), and noticed that, in a particular example, the author does the following:
Code:
package Object Template;
require Exporter;
@ObjectTemplate::ISA = qw(Exporter);
@ObjectTemplate::EXPORT = qw(attributes);
My questions are:
1) package scope lasts until either the end of the inner-most block (if it's defined in a block) or until another package definition is encountered. Since we're pulling in package-code by requiring Exporter, what is the official end of its package scope? there are no package declarations after "require Exporter", nor are there any blocks containing the code "package Exporter" in Exporter.pm. It does have a terminating "1" - does that officially end its scope as a package in the enclosing code above? To me, that must be the case... it would seem preposterous that its package-scope would bleed into any modules that require it.
2) why are we fully-qualifying the @ISA and @EXPORT arrays here (e.g. "@ObjectTemplate::ISA" vs. "@ISA"). Is there
ambiguity as to which package they would belong to, otherwise? I've seen plenty of examples in which they are not fully qualified in this way.
3) would we have suffered by use-ing Exporter vs. Require-ing it, as above? Use is a compile-time thing, I know, and also makes the products of Exporter available to us. Even though we don't need to take explicit advantage of those in the example above, are there any other reasons for actively not using "use"?

Thank you,
dora c
 
1) Package scope ends at the last line of Exporter, since "require" acts like a block.

"require" takes the last statement in the module you are requiring, and treats it as a success/failure code. From the perlfunc man page:

"The file must return true as the last statement to indicate successful execution of any initialization code, so it's customary to end such a file with 1; unless you're sure it'll return true otherwise. But it's better just to put the 1;, in case you add more statements."

2) My guess is it needs to be fully qualified because otherwise it assumes old Perl symantics of the variables being truly global rather than package-specific. I might be wrong though...

3) I think you know more than I do about this part of your question... :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top