| [reply] |
Hi, That works as you explained. The thing I don't understand is now I have to fully name my exported methods by using the package name, IE instead of: phash(\%hash) I need to put: Mod::Personal::phash(\%hash)
Any ideas why that is?
| [reply] |
It's because you are no longer using Exporter's import. ToolSet takes care of this by doing the import for you, plus it will re-export functions from other modules -- which you'd also have to do in your custom import routine if you want to make, say, Carp functions available when Mod::Personal is used.
You're really just re-implementing ToolSet step-by-step. Here's how ToolSet would work:
package Mod::Personal;
use base 'ToolSet';
ToolSet->set_strict(1);
ToolSet->export(
'Carp' => undef, # get the defaults for Carp
'List::Util' => 'shuffle sum', # or specific functions
);
our @Export = qw( phash );
sub phash {
# your code here
}
1;
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
| [reply] [d/l] [select] |
Hi,
I will probably end up using toolset in the long run, I'm just trying to get a handle on packages and modules, importing/exporting etc. For me the best way to learn is try to do it and learn from a (very) long list of mistakes ;-). Once I know it (enough to satisfy myself anyway) I revert to using "magic" modules.
Many thanks for all the help. Displeaser
| [reply] |
package mod::personal;
require strict;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw (phash);
use Foo qw(phash);
sub import {
strict->import;
$_[0]->export_to_level(1, @_);
}
| [reply] [d/l] [select] |