in reply to Force caller to return - reflection

While I'm not exactly sure that what you want to do is sane, I think that Scope::Upper can help you, as it claims that you can unwind the stack frame and return arbitrary values there.

Replies are listed 'Best First'.
Re^2: Force caller to return - reflection
by Improv (Pilgrim) on Jan 20, 2009 at 14:21 UTC
    What I want to do isn't sane in the general case, but it is sane for the specific case of how the module works. :) Scope::Upper looks like it's designed to manipulate scoping rules - unwind() doesn't actually impact program flow. What I'm looking for is something a bit more like "pretend you're doing tail recursion and pop the call stack twice rather than once, returning this value". Thanks for the idea though.
        Interesting! I'll have to see if that can be nicely wrapped to do what I want. Thanks.
      unwind() doesn't actually impact program flow
      Oh yes it does. Just how do you think you can return values from an upper scope without restarting from there? Not mentioning that that would be of very limited use if it didn't!

      Continuation::Escape gives an alternate interface to it, which effectively relieves you from having to specify the target context yourself. But OTOH it requires you to be able to "mark" the context you want to return to. Reading its source code will surely teach you how it builds up on unwind.