crashtest has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Exporting symbols from another package
by BrowserUk (Patriarch) on Mar 29, 2010 at 19:39 UTC | |
Re: Exporting symbols from another package
by almut (Canon) on Mar 29, 2010 at 20:28 UTC | |
Re: Exporting symbols from another package
by Hue-Bond (Priest) on Mar 29, 2010 at 20:36 UTC | |
Re: Exporting symbols from another package
by zwon (Abbot) on Mar 29, 2010 at 19:26 UTC | |
by BrowserUk (Patriarch) on Mar 29, 2010 at 19:33 UTC |