[baltimorepm] Closures and Late-Binding Subroutine Calls

Brad Lhotsky brad.lhotsky at gmail.com
Thu Apr 26 08:28:50 PDT 2012


As per our IM conversation, look at using Sub::Exporter in PackageA so
you can pull that into PackageB however you'd like.

2012/4/26 Alan Grover <awgrover at gmail.com>:
> This sounds like "dynamic" context from before the days of "lexical"
> context (see early lisp).
>
> And I haven't tried that sort of Evil in perl yet. It's not a concept
> that is in favor, though it has some applications. Cf. "goto".
>
> Putting the closure in a special package (e.g. "MyDynamicPackage"), and
> autoload, plus hunting up the stack ("caller()") for the package/context
> where you want to resolve it, might do it.
>
> Also, this is how "hygenic" macros  work (again, in scheme/lisp):
> variables bind to the lexical context of the macro, but "free" variables
> bind to the execution context. Maybe look for various "macro" mechanisms
> in cpan?
>
> On 04/26/2012 10:24 AM, Stephen Belcher wrote:
>> Hi all,
>>
>> I'm wondering if anyone has an answer to
>> this? https://gist.github.com/2499830
>>
>> 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.
>>
>> I can think of a few ways around the problem I'm trying to solve which
>> aren't pretty, but I really like this one, cause I'm going for pretty,
>> and I hope the answer's not just "you can't do that in Perl without XS
>> Dark Magicks and/or a source filter".
>>
>> --Stephen
>>
>>
>> _______________________________________________
>> Baltimore-pm mailing list
>> Baltimore-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/baltimore-pm
>
> --
> Alan Grover
> awgrover at mail.msen.com
> +1.734.476.0969
>
> (The "email signature" and/or digital-signature
> are only for informational and integrity purposes
> and does not constitute a legal signature)
>
>
> _______________________________________________
> Baltimore-pm mailing list
> Baltimore-pm at pm.org
> http://mail.pm.org/mailman/listinfo/baltimore-pm



-- 
Brad Lhotsky


More information about the Baltimore-pm mailing list