Re: [patch] better failure diagnostics for config token substitution

2001-12-29 Thread Doug MacEachern
On Mon, 24 Dec 2001, Stas Bekman wrote:

> if the config token get mistyped, e.g. @servrename@ the current replace()
> sub will simply die without helping to locate which token is unknown to
> Apache-Test. This patch reports the offensive token (of course it'd be
> nice to tell which file it comes from but the current implementation
> doesn't allow that)

+1

filename would be nice.  local $Apache::TestConfig::File or similar in
generate_extra_conf would get most of them.



[patch] better failure diagnostics for config token substitution

2001-12-23 Thread Stas Bekman
if the config token get mistyped, e.g. @servrename@ the current replace()
sub will simply die without helping to locate which token is unknown to
Apache-Test. This patch reports the offensive token (of course it'd be
nice to tell which file it comes from but the current implementation
doesn't allow that)

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.117
diff -u -r1.117 TestConfig.pm
--- Apache-Test/lib/Apache/TestConfig.pm2001/12/21 12:44:16 1.117
+++ Apache-Test/lib/Apache/TestConfig.pm2001/12/23 16:36:50
@@ -755,7 +755,12 @@

 sub replace {
 my $self = shift;
-s/@(\w+)@/$self->{vars}->{lc $1}/g;
+s[@(\w+)@]
+ [ my $key = lc $1;
+  exists $self->{vars}->{$key}
+  ? $self->{vars}->{$key}
+  : die qq{cannot substitute "[EMAIL PROTECTED]@" token}
+ ]ge;
 }

 #need to configure the vhost port for redirects and $ENV{SERVER_PORT}

we could do simpler:

+s[@(\w+)@]
+ [ $self->{vars}->{lc $1}
+   || die qq{cannot substitute "[EMAIL PROTECTED]@" token}
+ ]ge;

But the value can be false (while valid), so it won't work for all cases.

_
Stas Bekman JAm_pH  --   Just Another mod_perl Hacker
http://stason.org/  mod_perl Guide   http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/