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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |