in reply to Defining a function in the caller's package

Hi, maybe chromatic's response in the thread How to fool caller() / use NEXT within a dynamic sub might help you. (Update: Hmm, I'm not sure if this works here, because the problem in that thread was the name of the sub, not the package.)

caller always returns the package where the code was, regardless of which name in which package you used to call the code.

By the way, what you are trying to do (creating a sub in the importing package) is basically what Exporter does, however it aliases it to a sub in the imported package.

  • Comment on Re: Defining a function in the caller's package

Replies are listed 'Best First'.
Re^2: Defining a function in the caller's package
by rovf (Priest) on Aug 08, 2008 at 11:44 UTC
    caller always returns the package where the code was, regardless of which name in which package you used to call the code.

    I see, this explains why my first attempt had to fail.

    Actually, the reference you gave was very helpful, because what my do_something *really* does, is to call NEXT(). I just left out this detail because I thought it would not be relevant to the problem.

    I just wonder whether fiddling around with __ANON__, as shown in the example you refered to, is considered portable Perl style (I couldn't find any "official" Perl documentation about __ANON__), or whether the eval solution I used would be better. Both seem to be a hack, but which one is the kinder hack ?-)

    -- 
    Ronald Fischer <ynnor@mm.st>

      t/op/caller.t and t/comp/package.t in the core test suite both test aspects of __ANON__'s behavior. I consider that official enough to believe that it won't go away.