Greetings, Monks

I have a single module file (say, Foo.pm) that defines subroutines for several packages, for example like this:

# Foo.pm package Foo::Bar; sub foo_bar_one{ ... } sub foo_bar_two{ ... } package Foo:Transforms; sub transform_one{ ... } sub transform_two{ ... } package Foo::Baz; # ... and more

What I'd like to do is to be able to use Foo and import some subroutines from a specific package in the module file into the caller's namespace (in this case, the "transform" subs). I figured I'd be able to set it up like this:

# Foo.pm package Foo; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( &Foo::transform_one &Foo::transform_two); our %EXPORT_TAGS = ( transforms => [qw( &Foo::transform_one &Foo::transform_two]); # ... rest of Foo.pm # Then in script.pl: use Foo qw(:transforms); say transform_one("xyzabc");

This doesn't seem to work - I get an undefined subroutine error; it appears none of the transform methods were exported.

I suppose I could break out the "transforms" into their own separate module and use it separately. But I was wondering if any wise Monks have advice for me on this. Is it possible to export symbols from another package (without too many gyrations?) Am I trying to do something unnatural or unadvised?

Thanks in advance for your input.


In reply to Exporting symbols from another package by crashtest

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.