You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Will Trillich <wi...@serensoft.com> on 2004/04/02 05:39:34 UTC

MP2: trouble in PerlSection: how to do multiple "PerlSetVar"?

/lurk :)

we're having trouble translating a standard httpd.conf setup into
a <Perl> section when there's a directive that can be legally
repeated multiple times, such as PerlSetVar --

objective: translate MULTIPLE "PerlSetVar" from straight
httpd.conf into <Perl>perl sections code</Perl>.

<VirtualHost *>
	...
	PerlSetVar MasonCompRoot        /var/www/mywebsite
	PerlSetVar MasonDataDir         /var/cache/mason/mywebsite
	PerlSetVar MasonAutoHandlerName my.autohandler.mason
	PerlSetVar MasonDHandlerName    my.dhandler.mason
	PerlSetVar MasonDeclineDirs     0
	...
</VirtualHost>

we figured we could translate that into <Perl> sections thus:

	push @{$VirtualHost{'*'}},{
		...
		PerlSetVar => [
			MasonCompRoot        => "/var/www/$site",
			MasonDataDir         => "/var/cache/mason/$site",
			MasonAutoHandlerName => "$autohandlername",
			MasonDHandlerName    => "$dhandlername",
			MasonDeclineDirs     => '0',
		],
		...
	};

but that gives the following error:

"Syntax error on line 3 of /etc/apache2/sites-enabled/perl:
PerlSetVar takes two arguments, PerlSetVar at
/usr/lib/perl5/Apache2/Apache/PerlSections.pm line 177."

we've also tried sub-arrays, thus:

		PerlSetVar => [
			[ MasonCompRoot        => "/var/www/$site", ],
			[ MasonDataDir         => "/var/cache/mason/$site", ],
			[ MasonAutoHandlerName => "$autohandlername", ],
			[ MasonDHandlerName    => "$dhandlername", ],
			[ MasonDeclineDirs     => '0', ],
		],

with identical (failed) results.

after revisiting the docs for the eleventh time, i see that they
(both for mp1 and mp2, at perl.apache.org) mention:

	<quote>
	If an Apache directive can take two or three arguments you may
	push strings (the lowest number of arguments will be shifted off
	the @list) or use an array reference to handle any number
	greater than the minimum for that directive:

		push @Redirect, "/foo", "http://www.foo.com/";
		push @Redirect, "/imdb", "http://www.imdb.com/";
		push @Redirect, [qw(temp "/here" "http://www.there.com")];
	</quote>

i presume these three lines of code are all intended to be taken
as one block from an example script; if so, the resulting
@Redirect will look like this:

	@Redirect = (
		'/foo',
		'http://www.foo.com/',
		'/imdb',
		'http://www.imdb.com/',
		[
			'temp',
			'/here',
			'http://www.there.com',
		],
	);

but perusing Apache2/Apache/PerlSections.pm it looks like sub
dump_entry should generate this (wrong config) instead of what's
expected:

	Redirect /foo
	Redirect http://www.foo.com/
	Redirect /imdb
	Redirect http://www.imdb.com/
	Redirect temp /here http://www.there.com

except (as the docs mention) there's probably some per-directive
facility to override the defaults, where it shifts the right number
of items off the list.

but i digress.

so as a workaround, in theory, we could do this:

		PerlSetVar => [
			["MasonCompRoot        /var/www/$site",],
			["MasonDataDir         /var/cache/mason/$site",],
			["MasonAutoHandlerName $autohandlername",],
			["MasonDHandlerName    $dhandlername",],
			["MasonDeclineDirs     0",],
		],

now this should get dumped into the config (via lines 153-5 of
Apache2/Apache/PerlSections, v0.01:

	elsif ($type eq 'ARRAY') {
		$self->add_config("$name @$entry\n");
	}

) to be exactly what we started with in the pre-perl config
above, right?

zut alors.

even with this approach, we STILL get the "PerlSetVar takes two
arguments"...  business.

what's the workaround? didn't see anything like this in our
searchings through the mod_perl list archives...

we also tried "grep -ri 'takes two arguments'
/usr/lib/perl5/Apache2" and turned up nothing. where's the error
message actually coming from?

any pointers greatefully welcomed!

===

# apache2 -v
Server version: Apache/2.0.48
Server built:   Jan 30 2004 20:35:32
# uname -a
Linux tigris 2.4.21-xfs #13 SMP Tue Aug 26 01:46:14 CEST 2003 i686 GNU/Linux

using debian sarge (still in state "testing" at the moment, but
closing in on "stable" real soon now)

-- 
will trillich
http://www.serensoft.com/
http://www.midwestRepo.com/
http://www.skylineAuto.net/


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: MP2: trouble in PerlSection: how to do multiple "PerlSetVar"?

Posted by Will Trillich <wi...@serensoft.com>.
On Mon, Apr 05, 2004 at 08:15:40AM -0400, Geoffrey Young wrote:
> >>did you try this:
> >>
> >>  push @PerlSetVar, "MasonCompRoot /var/www/$site";
> >>
> >>?
> 
> it was the full string that you ought to try:
> 
>  	push @{$VirtualHost{'*'}}, {
>  		PerlSetVar => "MasonCompRoot /var/www/$dir",

ah so. we hadn't tried that -- we had done the "string within
subarrays" like this

= so as a workaround, in theory, we could do this:
= 
=     PerlSetVar => [
=             ["MasonCompRoot        /var/www/$site",],
=             ["MasonDataDir         /var/cache/mason/$site",],
=             ["MasonAutoHandlerName $autohandlername",],
=             ["MasonDHandlerName    $dhandlername",],
=             ["MasonDeclineDirs     0",],
=     ],

but now, trying it without the subarrays,

     PerlSetVar => [
             "MasonCompRoot        /var/www/$site",
             "MasonDataDir         /var/cache/mason/$site",
             "MasonAutoHandlerName $autohandlername",
             "MasonDHandlerName    $dhandlername",
             "MasonDeclineDirs     0",
     ],

we STILL get "two args only, please, move along." pooh.
does it work for you?

-- 
will trillich
http://www.serensoft.com/
http://www.midwestRepo.com/
http://www.skylineAuto.net/


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: MP2: trouble in PerlSection: how to do multiple "PerlSetVar"?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>>did you try this:
>>
>>  push @PerlSetVar, "MasonCompRoot /var/www/$site";
>>
>>?
>>
>>IIRC most of the configurations could accept a simple string in
>>mp1, so I would expect things to be pretty much the same in
>>mp2.
> 
> 
> but this is for a virtualhost, so it hasta be a sub-item within
> a <virtualhost> hash, such as
> 
> 	...
> 	push @{$VirtualHost{'*'}}, {
> 		PerlSetVar => [
> 			MasonCompRoot => "/var/www/$dir",
> 			MasonDataDir  => "/var/cache/mason/$dir",
> 			...
> 		],
> 		ServerName => $dir,
> 		DocumentRoot => "$main/$dir",
> 		...
> 	};
> 	...

it was the full string that you ought to try:

 	push @{$VirtualHost{'*'}}, {
 		PerlSetVar => "MasonCompRoot /var/www/$dir",


> ah. so this looks like a "no can do" type of thing (despite the
> docs which say it just shifts off the minimum number of args).
> looks like i'll have to 
> 
> 	Apache->server->add_config()

if all else fails that's always available, yes.

--Geoff

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: MP2: trouble in PerlSection: how to do multiple "PerlSetVar"?

Posted by Will Trillich <wi...@serensoft.com>.
[recap: trying to simulate repeatable directives like this conf
snippet, in perl--

	<VirtualHost *>
		...
		PerlSetVar MasonCompRoot /var/www/xyz.pdq
		PerlSetVar MasonDataDir  /var/cache/mason/xyz.pdq
		...
	</VirtualHost>

and running into "PerlSetVar takes two arguments" error...]

On Thu, Apr 01, 2004 at 11:39:59PM -0500, Geoffrey Young wrote:
> > what's the workaround? didn't see anything like this in our
> > searchings through the mod_perl list archives...
> 
> did you try this:
> 
>   push @PerlSetVar, "MasonCompRoot /var/www/$site";
> 
> ?
> 
> IIRC most of the configurations could accept a simple string in
> mp1, so I would expect things to be pretty much the same in
> mp2.

but this is for a virtualhost, so it hasta be a sub-item within
a <virtualhost> hash, such as

	...
	push @{$VirtualHost{'*'}}, {
		PerlSetVar => [
			MasonCompRoot => "/var/www/$dir",
			MasonDataDir  => "/var/cache/mason/$dir",
			...
		],
		ServerName => $dir,
		DocumentRoot => "$main/$dir",
		...
	};
	...

the trouble is, as previously mentioned, that PerlSetVar pukes
when it gets more than two items (yes, even when pushing
arrayrefs instead of individual values); instead of generating
multiple "perlsetvar" statements as we'd hoped, it wants to do
just one such statement with all the args at once,

	PerlSetVar MasonCompRoot /var/www/site MasonDataDir /var/cache/mason/site

which is of course illegal. surely this can be done using
<perl> sections?

> > we also tried "grep -ri 'takes two arguments'
> > /usr/lib/perl5/Apache2" and turned up nothing. where's the
> > error message actually coming from?
> 
> that comes directly from Apache when it reinforces the TAKE2
> prototype

ah. so this looks like a "no can do" type of thing (despite the
docs which say it just shifts off the minimum number of args).
looks like i'll have to 

	Apache->server->add_config()

instead. unless i'm missing something?

===

hmm. just had a thought -- in this case maybe we could conjure
up some perl code to eval, that would contain the whole handler
code that creates the mason object with all the necessary
parameters. hmm!

that could work... but it's a special-case solution to this
situation. is there no <perl> section interface for this type of
thing?

-- 
will trillich
http://www.serensoft.com/
http://www.midwestRepo.com/
http://www.skylineAuto.net/


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: MP2: trouble in PerlSection: how to do multiple "PerlSetVar"?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> what's the workaround? didn't see anything like this in our
> searchings through the mod_perl list archives...

did you try this:

  push @PerlSetVar, "MasonCompRoot /var/www/$site";

?

IIRC most of the configurations could accept a simple string in mp1, so I
would expect things to be pretty much the same in mp2.

> 
> we also tried "grep -ri 'takes two arguments'
> /usr/lib/perl5/Apache2" and turned up nothing. where's the error
> message actually coming from?

that comes directly from Apache when it reinforces the TAKE2 prototype

HTH

--Geof

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html