That's what
import is basically for... The idea is to make aliases to your selection of package variables and subs, into the package where the module is
used. That means that other variables (though, of the same name) come to life into the caller package, which reference the same values/subs as your original package variables/subs... Modify one, and the other follows, that's what aliasing means.
import is supposed to be a sub, called as a class method, whenever your module of the same name as the package, is used. As it's a class method, you'll see two difference with a normal sub:
- You'll see the name of the package which invokes the method, as an extra first parameter
- Inheritance works.
The latter is the basis of how
Exporter works. Your module package inherits from
Exporter, and as a result, the
import method from
Exporter is called. And that module's
import method can handle the importing of your subs and variables, in a standard and convenient way — with very little work required on your part. All you have to do is set up some package variables:
@EXPORT,
@EXPORT_OK, and possibly a few more. See the docs for
Exporter, if you're curious.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.