in reply to Adding "sub import{}" to my module makes global symbols require an explicit package name

In addition to what Corion said: With recent perl/Exporter versions (perl >=5.8.3 / Exporter >=5.57), you no longer need to inherit from Exporter, it is sufficient to import Exporter's import routine (see Exporting without inheriting from Exporter). So you can drop the line ...

@ISA=qw(Exporter);
... and change ...
use Exporter;
... to ...
use Exporter qw( import );

Of course, if you have your own import method, that won't work. You can use export_to_level instead, see Exporting without using Exporter's import method. Inheriting is also not needed then, and you also don't have to (and should not) import Exporter's import.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
  • Comment on Re: Adding "sub import{}" to my module makes global symbols require an explicit package name
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Adding "sub import{}" to my module makes global symbols require an explicit package name
by BadHarry (Initiate) on Sep 29, 2010 at 09:22 UTC

    Thank you both for your replies. I now have it working with export_to_level, though not using it exactly as you described.

    While my use statement was:

    use OddEffectOfImportTest;

    the following worked fine.

    OddEffectOfImportTest->export_to_level(1, @_);

    ... but changing the use statement to:

    use OddEffectOfImportTest xxx => 6;

    ... makes it fail, albeit with a different error.

    All of the next three work

    OddEffectOfImportTest->export_to_level(1);

    OddEffectOfImportTest->export_to_level(1, $_[0]);

    OddEffectOfImportTest->export_to_level(1, $_[0], @EXPORT);

    I plan to use the second one.

    If you think I'm missing something fundamental, please do follow up. Otherwise thank you for your invaluable help.

    Barrie