develooper Front page | perl.perl5.porters | Postings from November 2011

[perl #105024] UNIVERSAL::AUTOLOAD breaks named captures/%-/%+

Thread Next
From:
Father Chrysostomos via RT
Date:
November 30, 2011 17:49
Subject:
[perl #105024] UNIVERSAL::AUTOLOAD breaks named captures/%-/%+
Message ID:
rt-3.6.HEAD-5084-1322704188-1369.105024-15-0@perl.org
On Wed Nov 30 13:39:47 2011, l.mai@web.de wrote:
> % perl -wle '{ package UNIVERSAL; sub AUTOLOAD { warn "$AUTOLOAD(@_)"
>    } } "a" =~ /(?<X>.)/ or die; print "$+{X}"'
> IO::File::DESTROY(IO::File=IO(0x9447790)) at -e line 1.
> Use of uninitialized value $+{"X"} in string at -e line 1.
> 
> % perl -wle '%- if 0; { package UNIVERSAL; sub AUTOLOAD { warn
>    "$AUTOLOAD(@_)" } } "a" =~ /(?<X>.)/ or die; print "$+{X}"'
> IO::File::DESTROY(IO::File=IO(0x823f798)) at -e line 1.
> a
>
Tie::Hash::NamedCapture::DESTROY(Tie::Hash::NamedCapture=SCALAR(0x823fba8))
>    at -e line 1 during global destruction.
>
Tie::Hash::NamedCapture::DESTROY(Tie::Hash::NamedCapture=SCALAR(0x823fca8))
>    at -e line 1 during global destruction.
> IO::File::DESTROY(IO::File=IO(0x823f078)) at -e line 1 during global
>    destruction.
> IO::File::DESTROY(IO::File=IO(0x823f0f8)) at -e line 1 during global
>    destruction.
> IO::File::DESTROY(IO::File=IO(0x823f178)) at -e line 1 during global
>    destruction.
> 
> 
> So apparently just creating UNIVERSAL::AUTOLOAD is enough to break %+,
>    even if
> AUTOLOAD is never called. But (for some reason) letting the parser see
>    %+ early
> makes things work as expected.
> 
> As far as I can tell this is broken in 5.12 and 5.10 but works in
>    5.14,
> probably because Tie::Hash::NamedCapture is a real (XS) module there.
> 
> Any idea what's going on?

It was indeed this commit that made the difference, but I cannot
understand why:

commit 8dcfe2e99a72fe7951b4d15325e1541232823204
Author: Nicholas Clark <nick@ccl4.org>
Date:   Thu Oct 14 15:34:03 2010 +0100

    Move remaining Tie::Hash::NamedCapture XS code to NamedCapture.xs
    
    Now all the support code for %+ and %- is contained in the module in
ext/

-- 

Father Chrysostomos


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About