On Thu, 20 Sep 2001, Doug MacEachern wrote:
> On Fri, 21 Sep 2001, Stas Bekman wrote:
>
> > But then for me to craft the right patch, which way should I go? Always
> > have a hash of lists or should I optimize it at the expense of more if's
> > to turn the value into a list ref only if there is more than one value
> > to store? I guess it doesn't matter for the build, but we could reuse
> > the concept in other places as well.
>
> the size of config in test .pm's should always be fairly small, so
> speed/size is not much of a concern. whichever solution requires least
> coding effort would be best in this case.
patch:
- allows to have more than one identical directive in the __DATA__
section of the response handlers in tests, but turning a list into HoL
- adds chomp, so extra new lines won't be added in config
- allows a new virtual block <Base></Base> if the test wants to plant
something into the base level configuration
Now I can do this:
TestAPI/request_rec.pm:
-----------------------
__END__
<Base>
PerlSetVar FooMain Bar
PerlSetVar FooMain2 Bar2
</Base>
PerlOptions +GlobalRequest
PerlSetVar InDir Cool
PerlSetVar InDir2 Cool2
and it will auto-generate:
PerlSetVar FooMain Bar
PerlSetVar FooMain2 Bar2
<Location /TestAPI::request_rec>
PerlSetVar InDir Cool
PerlSetVar InDir2 Cool2
PerlOptions +GlobalRequest
SetHandler modperl
PerlResponseHandler TestAPI::request_rec
</Location>
Notice that adding PerlSetVar into external container is not very good, as
it duplicates the <Location> container for this response handler. But
rather than trying to fix that, I prefer an explicit block, which removes
a need for %outside_container alltogether, makes it easy for test writers
add new directives to the base, without asking to adjust the Apache-Test
code.
Index: Apache-Test/lib/Apache/TestConfig.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfig.pm,v
retrieving revision 1.64
diff -u -r1.64 TestConfig.pm
--- Apache-Test/lib/Apache/TestConfig.pm 2001/09/19 11:12:06 1.64
+++ Apache-Test/lib/Apache/TestConfig.pm 2001/09/21 06:19:25
@@ -321,7 +321,14 @@
$args = "<$directive $arg>\n";
if (ref($hash)) {
while (my($k,$v) = each %$hash) {
- $args .= " $k $v\n";
+ if (ref($v) eq 'ARRAY') {
+ for (@$v) {
+ $args .= " $k $_\n";
+ }
+ }
+ else {
+ $args .= " $k $v\n";
+ }
}
}
else {
Index: Apache-Test/lib/Apache/TestConfigPerl.pm
===================================================================
RCS file:
/home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfigPerl.pm,v
retrieving revision 1.26
diff -u -r1.26 TestConfigPerl.pm
--- Apache-Test/lib/Apache/TestConfigPerl.pm 2001/09/19 11:12:06 1.26
+++ Apache-Test/lib/Apache/TestConfigPerl.pm 2001/09/21 06:19:25
@@ -192,6 +192,17 @@
if ($outside_container{$directive}) {
$self->postamble($directive => $rest);
}
+ elsif ($directive eq '<Base>') {
+ # <Base> and </Base> are removed
+ my $end = "</Base>";
+ while (<$fh>) {
+ chomp;
+ last if m:^\Q$end:;
+ $self->replace;
+ s/^\s*//; # align for base
+ $self->postamble($_);
+ }
+ }
elsif ($directive =~ m/^<(\w+)/) {
if ($directive eq '<VirtualHost') {
$rest =~ s/>$//;
@@ -202,6 +213,7 @@
$self->postamble($directive => $rest);
my $end = "</$1>";
while (<$fh>) {
+ chomp;
$self->replace;
$self->postamble($_);
last if m:^\Q$end:;
@@ -286,12 +298,28 @@
push @args, @handler_cfg;
}
+ my $args_hash = L2HoL(\@args);
$self->postamble($self->$container($module),
- { @args }) if @args;
+ $args_hash) if @args;
$self->write_pm_test($module, lc $base, lc $sub);
}, $dir);
}
+}
+
+
+# turn a balanced (key=>val) list with potentially multiple indentical
+# keys into a hash of lists.
+#############
+sub L2HoL {
+ my $arr = shift;
+ my %hash = ();
+ my $pairs = @$arr / 2;
+ for my $i (0..($pairs-1)) {
+ my ($key, $val) = ($arr->[$i*2], $arr->[$i*2+1]);
+ push @{ $hash{$key} }, $val;
+ }
+ return \%hash;
}
# We have to test whether tests have APACHE_TEST_CONFIGURE() in them
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]