[sf-perl] exporting tags

David Alban extasia at extasia.org
Mon Aug 6 12:26:32 PDT 2007


Greeings,

I have:
  package My::Module;

  ...

  BEGIN {
     ...
     @EXPORT = qw(
              &sub_1
              &sub_2
              &sub_3
            );

     @EXPORT_OK = qw(
                      $scalar_1
                      $scalar_2
                    );

     %EXPORT_TAGS = ( foo => [ qw( $scalar_1 $scalar_2 ) ] );

  }

When the module is used as:

  use My::Module qw( :foo );

I see the scalars, but not the exported subroutines.  I can do:

  use My::Module qw( :DEFAULT :foo );

which works, but what I'd really like is to be able to do:

  use My::Module qw( :foo );

and get the subs in @EXPORT along with the subs in the :foo tag.

I think I'm missing something.  Is this impossible?

If I just did 'use My::Module;' I'd get everything in @EXPORT.  Why does
that stop if I supply a tag.

What I'm trying to do is define a set of Readonly.pm constants in the
module and let the user decide whether to import them so they don't have
to use the package prefix, or not to import them and have to use the
package prefix.  (Which is why I don't want to export them by default.)

Thanks.
David
-- 
Live in a world of your own, but always welcome visitors.


More information about the SanFrancisco-pm mailing list