Don't make a closure. Just assign the typeglob.
This would not solve my problem (sorry if I was not precise enough about this). If I would adapt your example for my application, it would look more like:
This would print 'Foo', but I would like to have it printed 'main'. This can be accomplished using, for instance, the eval "package ...." mechanism.package ForeignModule; sub NEXT { print scalar caller } ================================= package Foo; use ForeignModule qw(NEXT); sub do_something { NEXT(); } sub import { my $target = caller; no strict 'refs'; *{"$target:\:do_something"} = \&do_something; } ================================= package main; use Foo; do_something();
In reply to Re^2: Defining a function in the caller's package
by rovf
in thread Defining a function in the caller's package
by rovf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |