develooper Front page | perl.perl5.porters | Postings from August 2001

Re: The coderef in @INC strikes back

Thread Previous | Thread Next
Nicholas Clark
August 22, 2001 02:46
Re: The coderef in @INC strikes back
Message ID:
On Tue, Aug 21, 2001 at 09:54:00PM +0200, Rafael Garcia-Suarez wrote:
> Do you remember this little odd feature that allows to add
> a coderef in @INC? See the digest for info :
> AFAIK, this feature has been left unfinished in the core :
> there are no docs and no tests for it.
> I've looked back into the p5p archives. You can add a coderef in @INC;

Sort of here ish:

> it should return a filehandle from which the Perl source to use/require
> will be read. An arrayref in which the 1st element is a coderef will
> also work.

Around Feb this year (I think) a patch from me was added so that if the
"coderef" is actually a blessed reference then its INC method is called.
I believe that in doing this I've actually bust a specific corner case of
a blessed array reference (code in pp_ctl.c currently seems to dereference it
to get 1st element and then do the "is it coderef or blessed?" check - this
means that you can't use the INC method on an object that is a blessed
hashref. This is probably wrong)

> The thing becomes more complicated when you learn that this coderef is
> also allowed to return _another_ coderef (in addition to the filehandle)
> that will act as a source filter. (I'm summarizing the API here, but
> that's the big picture). Doesn't this duplicate the functionality
> provided by the Filter::* modules? (TIMTOWTDI, but that's not a reason
> to include in the core something that is also provided by separate
> modules).

The core filter is subtly broken in its implementation - see the message I
reference for 1 case. At the time that Ken Fox provided the original patch
Filter::* had not been assimilated. My opinion is that the core filter should
be removed, and the pp_ctl.c code be rewritten to use Filter::Simple.
However, I don't know (yet) how to implement the necessary perl opcodes
to do this.

> Anyway, documentation and tests are needed here. Also, I think that
> the core modules that iterate over @INC, assuming that it contains
> strings, should be reviewed.

A reasonable idea. Who gets to do this? :-)

Gisle Aas already supplied a patch to stop chomp stringifying everything
willy nilly, which was related to coderef INC:

Nicholas Clark

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