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

Documenting coderef @INC (Re: CPAN "make this script work" feature)

Thread Previous | Thread Next
Nicholas Clark
February 25, 2001 16:42
Documenting coderef @INC (Re: CPAN "make this script work" feature)
Message ID:
On Fri, Dec 08, 2000 at 07:59:35PM +0000, Nicholas Clark wrote:
> On Fri, Dec 08, 2000 at 02:37:00PM -0500, Jeff Pinyan wrote:
> > On Dec 8, Simon Cozens said:
> > 
> > >use CPAN (); push @INC, sub { CPAN::install($_[0]) && eval "use $_[0]" }
> > 
> > WHOA.  That is not in perlvar.pod as far as I can tell, and it appears
> > $_[0] is the code reference itself -- you mean $_[1] here.
> > 
> > I do not see any documentation on the code-ref behavior of @INC.  I can
> > write a patch.
> Beat me to saying that it's not documented.
> If you make it install a filter it's also broken w.r.t. the filter spec
> (your filter sub gets called with data from the previous call left by
> the downstream filter) and w.r.t. stealing temporaries (I think)(IIRC
> copying from $_ in a filter sub breaks it)
> I can send demos for both (will take some effort to dig them up and make them
> presentably terse) For the latter I can't send a patch.

Forgot to say that the actual standard coderef bit works just fine.
It's the icing-on-the-cake filter bit that's not perfect.

> It would appear easier not to fix the filter aspect of it until perlio is
> stable enough for source filters to be built atop perlio.
> OTOH now that the Filter modules are in the core bundle, it might be possible
> to change it to use Filter::Simple.

Would this be a good idea? I'm not sure if it would subtly change the
(undocumented except for somewhere on the p5p archive) semantics of the
filters it installs (just the filters. and possibly not even the filters)

However, as it's both experimental and undocumented, how many people are
using it?

Anyway, this gets dragged up again because I'd really quite like a 3 line
change to @INC-a-coderef:

--- pp_ctl.c.orig	Sat Feb 17 16:42:21 2001
+++ pp_ctl.c	Sun Feb 25 20:41:30 2001
@@ -3166,7 +3166,10 @@
-		    count = call_sv(loader, G_ARRAY);
+		    if (sv_isobject(loader))
+			count = call_method("INC", G_ARRAY);
+		    else
+			count = call_sv(loader, G_ARRAY);
 		    if (count > 0) {

as this then gives you INC-an-object

[object's method INC gets called, as $obj->INC($file)
where $file is the file require or use is wanting]

It makes it much easier to do @INC-a-zipfile all in XS, without having
to worry about making closures or other complicated thing.

[read "much easier" as "I've got it working, works fine with SelfLoader,
just need to make some serious regression tests, find a name (currently
'ex::lib::zib' as CPAN says experimental pragmas live in 'ex::') and upload

So, which POD should code-ref @INC be documented in?

Nicholas Clark

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