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.