in reply to Re: Defining a function in the caller's package
in thread Defining a function in the caller's package
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();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Defining a function in the caller's package
by mr_mischief (Monsignor) on Aug 11, 2008 at 16:10 UTC | |
by rovf (Priest) on Aug 12, 2008 at 08:19 UTC |