perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject Re: [Patch mp2] PerlSections namespace
Date Wed, 10 Dec 2003 01:44:08 GMT
Philippe M. Chiasson wrote:
> It's been a long time that perl sections have been having trouble with
> recursive inclusion. This has been discussed before and has to do with
> the fact that all PerlSections are evaluated in the same namespace
> Apache::ReadSections.
> The following patch follows a similar design than ModPerl::Registry,
> putting each <Perl> block in it's own namespace, based on filename &
> lineno.

Coolio ;)

> This now prevents infinite-recursion problems and makes $Includes from
> within <Perl> sections work fine.
> There is still one little problem left with this, people will not be
> able to put stuff directly in the Apache::ReadSections namespace
> themselves. I do have a plan for fixing that as well in a subsequent
> patch.

You mean it will break their code. In which case I'd suggest not to commit 
this patch till you get it all ready.

> As usual, look at it and tell me if it breaks more stuff than it fixes
> ;-)

I suppose it was a proof of concept, since you need to fix quite a few style 
things (long lines, some missing indent, missing spaces around ops).

> I had to introduce a function in mod_perl_util.c, modperl_file2package,
> that makes a package-safe name from a filepath, so maybe it could be
> exposed and used by ModPerl::Registry as well?

Good idea. I've just introduced the opposite function package2filename (to fix 
the problems in modperl_mgv). I'm not sure it fits registrycooker, since it 
doesn't drop /, whereas your function does, collapsing everything into a 
single word. It may have problems, since these two distinct names will map 
into the same namespace:


so the concept of dropping / is wrong. You need to replace each '/' with '::'.

modperl_file2package has its own problems ;) a stash name can't start with 
numerical and ':'. See below:

> +#define MP_VALID_PKG_CHAR(c) (isalnum(c)||c==':'||c=='_')
> +static const char *modperl_file2package(apr_pool_t *p, const char *file)
> +{
> +    char *package;
> +    char *c;
> +
> +    c = package = apr_pcalloc(p, strlen(file));
> +
> +    /* First, skip invalid prefix characters */
> +    while (!MP_VALID_PKG_CHAR(*file)) {
> +        file++;
> +    }

You need here:

#define MP_VALID_PKG_FIRST_CHAR(c) (isalpha(c) || c == '_')

/* First, skip invalid prefix characters */
while (!MP_VALID_PKG_FIRST_CHAR(*file)) {

Neither you can have a single ':' in the package name (or triple, etc), so you 
should check that they come in doubles...

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message