in reply to Getting module to call importer's function

How about:

use strict; package M; sub x { my $caller_package = shift; print "Caller: $caller_package\n"; $caller_package->_x(); } package main; sub _x { my $class = shift; print "$class _x\n"; } main->M::x();

output:

Caller: main main _x

update: added "shift" in _x - thanks ikegami.

Replies are listed 'Best First'.
Re^2: Getting module to call importer's function
by ikegami (Patriarch) on Sep 22, 2004 at 21:33 UTC
    Note: The above has the side effect of passing an extra argument to _x. Probably acceptable.
      Yep, got this working. Is there a way to call the function in a different context so as not to have to stick a dinky shift; at the start of _x? I'm trying some of the other discussed options, but can't get them working with passing parameters to _x.
        yes there is. See the first post in this thread. To pass params, do &$func($param1, $param2);

        Actually, the "class" parameter is important if you are thinking about using OO style - it makes it possible to subclass those methods properly. And it is easy to just shift it out while it is not needed.