develooper Front page | perl.perl5.porters | Postings from July 2009

Re: Hooks at the end of a scope during compile time

Thread Previous | Thread Next
Florian Ragwitz
July 16, 2009 01:15
Re: Hooks at the end of a scope during compile time
Message ID:
On Wed, Jul 15, 2009 at 10:37:50PM +0100, Ben Morrow wrote:
> Quoth (Florian Ragwitz):
> >
> > The following patch implements a new special variable,
> > @{^COMPILE_SCOPE_CONTAINER}, which allows implementing the behaviour required
> > by the current users of the %^H + Scope::Guard and B::Hooks::EndOfScope users.
> Oh, snap! I'm just in the middle of writing a more general solution to
> the same problem, which I've currently got at
> . My idea was not to use a
> special variable, but rather a new special block, SCOPECHECK, which gets
> called at the end of compiling the current scope. My intention was to
> implement ENTER/LEAVE/&c. from Perl 6 at the same time.

I'm glad to see I'm not the only one fighting against this problem.

I don't know which approach would be better. However, I must note that a
variable offers some kind of introspection for data attached to a scope
during its compile time. How that is useful is also demonstrated by the
test, which is part of my patch.

> My proposal was going to be that this be dual-life, and hold the
> best-effort hacks (like the %^H hack) for implementing these semantics
> on older perls. That way they're under the pumpking's eye, and if
> something in maint breaks them we get notice and can fix it.

I'm not sure how viable this solution would be. For the %^H hack to work
correctly, we need to use free magic on it. Currently this is done using
Variable::Magic, which is likely not going to be put in the core, as
discussed earlier this month on this list. Of course, this could also be
achieved by using plain XS, to avoid the dependency.

My initial plan was to make B::Hooks::EndOfScope, which every module
in need of end-of-scope hooks on cpan, except for autodie, already uses,
the compatibility-module, which simply does what it currently does on
older perls, or uses the new feature on perls that have it. Similar to
what MRO::Compat does for the mro pragma and Class::C3.

BOFH excuse #344:
Network failure -  call NBC

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About