- If by "available" you just mean "callable", you can simply use the function's fully-qualified name:
package SomePM;
use OtherPackage;
OtherPackege::some_func(); # works
I sometimes do this in my projects for debugging:
sub ::D { require Data::Dumper; return Data::Dumper::Dumper(@_) }
sub ::DD { require Carp; Carp::confess(::D(@_)) }
# later, call it like this:
print ::D({ current_state => $state }); # debug print
::DD($state); # dump, stack trace, die.
- If you want some_func to be callable without qualification from any package... you can't do this generally and unevilly. :)
If you have the cooperation of the other modules, have them use your module, and write an import routine to export your functions to the calling namespaces.
- If you don't have that cooperation, you might hook %INC (see require) to do this
exploiting exporting for you. Note that unless you hook %INC early in the initialization of your program, you will probably have untreated modules already loaded in memory, and you will have to find out who they are and treat them post-fact. This of course will miss out on their BEGIN blocks.
| [reply] [Watch: Dir/Any] [d/l] [select] |
You can use the standard Exporter module for this. | [reply] [Watch: Dir/Any] |
| [reply] [Watch: Dir/Any] |