[baltimorepm] Closures and Late-Binding Subroutine Calls

John SJ Anderson genehack at genehack.org
Thu Apr 26 09:44:46 PDT 2012


On Thursday, April 26, 2012 at 10:24 AM, Stephen Belcher wrote:
> Hi all,
>  
> I'm wondering if anyone has an answer to this? https://gist.github.com/2499830
>  
Looking at the gist, and specifically at the last section of it, I'm wondering why you can't just use the fully specified method name. I.e., instead of

    sub configure {
        my ($coderef) = sub {
            hello;
        };

do
    sub configure {
        my ($coderef) = sub {
            PackageA::hello;
        };


  
>  
> Essentially, I want to create a coderef while in the scope of one package, and delay binding of the subroutine calls until the actual execution, which will happen in or relative to another package, meaning that the subroutines that eventually resolve will be the ones located in the second package, not the first. This is different from what normally happens in closures.
>  
>  

It sounds like you have some problem you're trying to decide, and you have gotten onto this particular path of solving it, and it's not really the right solution. Perhaps you could explain what you're trying to achieve with this code? (Not the "call a method in packageB but use packageA's context for method resolution", but the problem you were working on solving _before_ you started on this…)

 chrs,
john.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/baltimore-pm/attachments/20120426/af88428c/attachment-0001.html>


More information about the Baltimore-pm mailing list