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

Re: [PATCH] Allow an @INC hook to set %INC

Thread Previous
From:
Jarkko Hietaniemi
Date:
September 28, 2001 16:26
Subject:
Re: [PATCH] Allow an @INC hook to set %INC
Message ID:
20010929022654.U11113@alpha.hut.fi
On Fri, Sep 28, 2001 at 10:18:13PM +0200, Rafael Garcia-Suarez wrote:
> In the process of getting something useful from this coderef-in-@INC feature...
> here's a patch.
> 
> It allows an hook placed in @INC to set the entry in %INC for the files it has loaded.
> 
> For example, the hook may do something like this :
> 
> 	push @INC, sub {
> 	    my $file = $_[1];
> 	    # ...figure out some $path...
> 	    open my $fh, "$path/$file" or return undef;
> 	    $INC{$file} = "$path/$file";
>             return $fh;
> 	};
> 
> And, with such a clever hook, dynaloaded modules (and other modules that use %INC)
> will work seamlessly.

Seams reasonable, thanks, applied.  Documentation patch would be nice.

> Sidenote: I'm proposing this patch because I'm writing an experimental pragma,
> ex::newest. When 'use ex::newest;' in put in a program, this modifies the
> behavior of use and require so that newest versions of modules are loaded
> (for modules that are installed several times locally) : @INC is walked for
> multiple occurences of the module to find the newest $VERSION. If this patch
> is useful for my funny pragma, it may be useful for other programmers.
> 
> --- pp_ctl.c.orig	Wed Sep 26 15:59:55 2001
> +++ pp_ctl.c	Fri Sep 28 21:50:06 2001
> @@ -3323,10 +3323,14 @@
>  	SETERRNO(0, SS$_NORMAL);
>  
>      /* Assume success here to prevent recursive requirement. */
> -    (void)hv_store(GvHVn(PL_incgv), name, strlen(name),
> -		   (hook_sv ? SvREFCNT_inc(hook_sv)
> -			    : newSVpv(CopFILE(&PL_compiling), 0)),
> -		   0 );
> +    len = strlen(name);
> +    /* Check whether a hook in @INC has already filled %INC */
> +    if (!hook_sv || !(svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
> +	(void)hv_store(GvHVn(PL_incgv), name, len,
> +		       (hook_sv ? SvREFCNT_inc(hook_sv)
> +				: newSVpv(CopFILE(&PL_compiling), 0)),
> +		       0 );
> +    }
>  
>      ENTER;
>      SAVETMPS;

-- 
$jhi++; # http://www.iki.fi/jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen

Thread Previous


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