in reply to Re: using strict from another module
in thread using strict from another module

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?

Replies are listed 'Best First'.
Re^3: using strict from another module
by xdg (Monsignor) on Mar 31, 2006 at 15:08 UTC

    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.

      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
Re^3: using strict from another module
by salva (Canon) on Mar 31, 2006 at 14:41 UTC
    The problem is that now, Exporter->import is not being called, because mod::personal->import is hidding it.

    Calling Exporter->import from mod::personal->import would not work either because it expects to be called directly from the package where the subs have to be imported. Fortunately Exporter has another method just for those cases: export_to_level:

    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, @_); }