in reply to Redefined import method and EXPORT not working

@EXPORT is not magical. It's just a variable. All the magic must happen in import.

The easiest approach would be to use Exporter::import, and stash that away and at the end, pass control to it:

use vars qw(@EXPORT $orig_import); use Exporter 'import'; sub my_import { print "Imported\n"; goto &$orig_import; }; BEGIN { # Install our own import routine over import: $orig_import= \&import; *import= \&my_import; };

Replies are listed 'Best First'.
Re^2: Redefined import method and EXPORT not working
by tobyink (Canon) on Dec 22, 2014 at 11:03 UTC

    That seems like an over-complicated way of doing:

    use Exporter (); sub import { print "Imported\n"; goto \&Exporter::import; }
      Great!
Re^2: Redefined import method and EXPORT not working
by Anonymous Monk on Dec 22, 2014 at 09:44 UTC

    That worked

    package M1; use parent qw(Exporter); @EXPORT=qw(func); sub func{print "Hello"} sub import{ print "Imported"; print @_; M1->export_to_level(1,@_)} 1;
    perl -I. -we 'use M1 qw(func);func()'

      Please, don't inherit from Exporter. Just use use Exporter 'import';. Inheritance as a way of getting access to methods of a module is not what I consider a clean approach.