|
Posted by Ben Morrow on May 13, 2008, 10:26 am
Please log in for more thread options
Quoth bernie@fantasyfarm.com:
> On May 13, 9:50 am, ber...@fantasyfarm.com wrote:
>
> > > I think you'd rather just export the constants to any package that
> > > needs them, instead of making them truly global (which would be more
> > > or less equivalent to exporting them to *all* packages)
>
> >... I guess I could do
> > something along the lines of putting require Exporter in my main
> > program, setting up @EXPORT_OK in the main program the "constants" I
> > want the interior packages to be able to import, and then do
> > a ::import(stuff I need) after the 'package' for the interior object-
> > section?
It's probably a bad idea to export from main::. I'd define a separate
package for your constants, and 'use' it from everywhere else.
> I'm running down this path to see how it looks and feels to properly
> export and import my "global" constants. And I've run into a
> problem. The man page for Exporter says:
>
> package YourModule;
> use Exporter 'import'; # gives you Exporter's import() method
> directly
> @EXPORT_OK = qw(munge frobnicate); # symbols to export on request
>
> But in my code I have:
> --------------------------
> #!/usr/bin/perl
>
> use strict ;
> use warnings ;
>
> use Exporter 'import' ;
> our @ISA = qw(Exporter);
> use constant AAA => 4 ;
> our @EXPORT_OK = ('AAA') ;
> ----------------------------
>
> "import" is not exported by the Exporter module at test.pl line 6
Does the manpage you're using match your version of Exporter? The
ability to import (rather than inherit) Exporter::import was not present
in older versions of Exporter.
Ben
--
Although few may originate a policy, we are all able to judge it.
Pericles of Athens, c.430 B.C.
ben@morrow.me.uk
|