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

RFC: Overridable keywords ([perl #96116] File::Glob ':glob' causes infinite loop)

Thread Previous | Thread Next
Father Chrysostomos via RT
October 27, 2011 12:58
RFC: Overridable keywords ([perl #96116] File::Glob ':glob' causes infinite loop)
Message ID:
Although this is a discussion about glob in particular, I’d like to make
all keywords overridable under ‘use v5.16’.  See the last paragraph below.

On Wed Oct 26 09:40:56 2011, wrote:
> On 10/26/11 11:46, Father Chrysostomos via RT wrote:
> > Since people already know that bsd_glob() does not split on spaces,
> we
> > could have ‘use File::Glob ':bsd_glob'’ export a special glob()
> function
> > that maintains state but calls bsd_glob underneath.
> >
> This sounds great!  My primary concern has been that the synopsis for
> File::Glob encourages something that can all-too-easily lead to
> infinite
> looping (and there's not even a warning in the documentation).  If
> ':bsd_glob' handles both "while magic" and multiple, unsplit,
> patterns,
> then putting it in the synopsis addresses all my concerns (and gets me
> out of the loop, which is also useful).

This is complicated, not in terms of actually writing the code, but in
thinking about the edge cases and deciding how they should work.

If we make glob truly overridable under ‘use v5.16’, then we have the
problem of modules like List::Gen exporting a glob() function that
expects to get the magic second argument to indicate the call site.

We could continue to have that work for <...>, but then how does
List::Gen::glob tell the difference between <*> and glob('*',42)?  One
solution to that is to continue to treat glob overrides specially under
‘use v5.16’ as long as the subroutine itself was *not* declared under
‘use v5.16’.

Also, the while(glob...) magic (implicit defined()) disappears if all we
have is a subroutine call (the way most overrides work).  But that I
consider a reasonable trade-off, as it’s possible to implement the same
thing in XS.  In fact, it’s possible to write an XS module to apply that
while-defined magic to *any* subroutine, not just those named ‘glob’.

If we make all keywords overridable, then we also have the problem of
‘require bareword’ magic disappearing.  But that I also consider a
reasonable trade-off.  We need to get away from special-casing
particular keywords.  It’s possible to write XS modules to apply these
special cases more generally (special-case the subroutines themselves,
not their names).

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