Author: torsten Date: Sun May 2 18:32:14 2010 New Revision: 940293 URL: http://svn.apache.org/viewvc?rev=940293&view=rev Log: Merged revisions 940287 via svnmerge from https://svn.eu.apache.org/repos/asf/perl/modperl/trunk
........ r940287 | torsten | 2010-05-02 20:25:41 +0200 (Sun, 02 May 2010) | 23 lines Implement a mini-preprocess language for map-files in xs/maps. Syntax is #_if_ perl-code #_elsif perl-code #_else_ #_end_ and #_eval_ perl-code The main reason for this change is to make structures and functions available if a certain condition is met only. For example: #_if_ do {use Apache2::Build; Apache2::Build::PERL_HAS_ITHREADS} ... #_end_ The _eval_ variant is thought mainly as a debugging tool: #_eval_ warn "here I am" ........ Modified: perl/modperl/branches/threading/ (props changed) perl/modperl/branches/threading/Changes perl/modperl/branches/threading/lib/ModPerl/MapUtil.pm Propchange: perl/modperl/branches/threading/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Sun May 2 18:32:14 2010 @@ -1 +1 @@ -/perl/modperl/trunk:594682-672484,672819-681118,693357,700369,732889-736218,751909-752425,757553-774171,807116,807332-807649,907778-932879,933373-933563,935519,936643 +/perl/modperl/trunk:594682-672484,672819-681118,693357,700369,732889-736218,751909-752425,757553-774171,807116,807332-807649,907778-932879,933373-933563,935519,936643,940287 Propchange: perl/modperl/branches/threading/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Sun May 2 18:32:14 2010 @@ -1 +1 @@ -/perl/modperl/trunk:1-712967,712969-936647 +/perl/modperl/trunk:1-712967,712969-940291 Modified: perl/modperl/branches/threading/Changes URL: http://svn.apache.org/viewvc/perl/modperl/branches/threading/Changes?rev=940293&r1=940292&r2=940293&view=diff ============================================================================== --- perl/modperl/branches/threading/Changes (original) +++ perl/modperl/branches/threading/Changes Sun May 2 18:32:14 2010 @@ -31,6 +31,9 @@ Expose modperl_interp_t via ModPerl::Int =item 2.0.5-dev +Implement a mini-preprocess language for map-files in xs/maps. +[Torsten Foertsch] + Implement APR::Socket::fileno [Torsten Foertsch] Export PROXYREQ_RESPONSE, a missing PROXYREQ_* constant [Gozer] Modified: perl/modperl/branches/threading/lib/ModPerl/MapUtil.pm URL: http://svn.apache.org/viewvc/perl/modperl/branches/threading/lib/ModPerl/MapUtil.pm?rev=940293&r1=940292&r2=940293&view=diff ============================================================================== --- perl/modperl/branches/threading/lib/ModPerl/MapUtil.pm (original) +++ perl/modperl/branches/threading/lib/ModPerl/MapUtil.pm Sun May 2 18:32:14 2010 @@ -87,13 +87,59 @@ package ModPerl::MapBase; *function_table = \&ModPerl::MapUtil::function_table; *structure_table = \&ModPerl::MapUtil::structure_table; +my @condition; + sub readline { my $fh = shift; while (<$fh>) { chomp; s/^\s+//; s/\s+$//; - s/^\#.*//; + + # this implements + # #_if_ cmd + # ... + # #_else_ + # #_end_ + if (/^\s*#\s*_(if|unless|els(?:e|if)|end)_(?:\s(.+))?/) { + my ($cmd, $param) = ($1, $2); + if ($cmd eq 'if') { + unshift @condition, 0+!!eval $param; + } + elsif ($cmd eq 'elsif') { + die "parse error ($ModPerl::MapUtil::MapFile line $.)". + " #_elsif_ without #_if_" + unless @condition; + if ($condition[0] == 0) { + $condition[0]+=!!eval $param; + } else { + $condition[0]++; + } + } + elsif ($cmd eq 'else') { + die "parse error ($ModPerl::MapUtil::MapFile line $.)". + " #_elsif_ without #_if_" + unless @condition; + $condition[0]+=1; + } + elsif ($cmd eq 'unless') { + unshift @condition, 0+!eval $param; + } + elsif ($cmd eq 'end') { + shift @condition; + } + } + next if @condition and $condition[0] != 1; + + if (/^\s*#\s*_(eval)_(?:\s(.+))?/) { + my ($cmd, $param) = ($1, $2); + if ($cmd eq 'eval') { + eval "#line $. $ModPerl::MapUtil::MapFile\n".$param; + die $@ if $@; + } + next; + } + s/\s*\#.*//; next unless $_; @@ -170,6 +216,7 @@ sub parse_map_files { open my $fh, $file or die "open $file: $!"; local $ModPerl::MapUtil::MapFile = $file; bless $fh, __PACKAGE__; + @condition=(); # see readline() above $self->parse($fh, $map); close $fh; }