develooper Front page | perl.perl5.porters | Postings from April 2007

Re: Proposed changes and to regular expression interfaces in core

Thread Previous | Thread Next
Ævar Arnfjörð Bjarmason
April 2, 2007 10:07
Re: Proposed changes and to regular expression interfaces in core
Message ID:
With regards to modifying the default Tie::Hash::NamedCapture
semantics which mirror how named captures work in the perl5 engine
I've come up with an implementation plan that's not as insane as it
could be.

In the case of qr// the package that the regex is being blessed into
is part of the regex structure via engine callbacks, but since %+ and
%- are globals you can't bind these lexically to a regex or have some
comfortable way to associate them with a single regex.

The workaround for this is to continue to bless %+ and %- into
Tie::Hash::NamedCapture but alter the routines so that
they use the p5 semantics in the default case as they do now OR if a
custom engine has been defined call engine->tie_pkg (or somesuch)
which is the real Tied package to use, so for instance FETCH migh
become something like:

# pseudocode
sub FETCH {
    if (my $pkg = re::tie_pkg($_[0]->{all})) {
        goto &{"$pkg\::FETCH"};
    return re::regname( ... );

This solution seems pretty clean to me and wouldn't impose any penalty
on $+{foo}  lookups using a custom engine other than seeing if they
need to be dispatching to a user-defined Tie::Hash package.

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