*** ConditionalPlugin.pm.old 2002-08-11 09:24:03.000000000 -0700 --- ConditionalPlugin.pm 2003-05-13 17:30:32.000000000 -0700 *************** *** 39,58 **** package TWiki::Plugins::ConditionalPlugin; # ========================= use vars qw( ! $VERSION $debug $sandbox $pluginInitialized ); #use Safe; $VERSION = '1.000'; - $prefixPattern = '(^|[\s\-\*\(])'; $ops = '(<|>|<=|>=|lt|gt|le|ge|==|\!=|<=>|eq|ne|cmp|=~|\!~)'; ! $condPattern_ifonly = '(%IF{(\s*\w+\s*'.$ops.'\s*\w+\s*)}%(.*?)%ENDIF%)'; ! $condPattern_ifelse = '(%IF{(\s*\w+\s*'.$ops.'\s*\w+\s*)}%(.*?)%ELSE%(.*?)%ENDIF%)'; ! $postfixPattern = '(?=[\s\.\,\;\:\!\?\)]*(\s|$))'; ! # ========================= sub initPlugin --- 39,58 ---- package TWiki::Plugins::ConditionalPlugin; # ========================= + use strict; use vars qw( ! $VERSION $debug $sandbox $pluginInitialized $ops $word ! $condPattern_ifonly $condPattern_ifelse $topic $web $user $installWeb ); #use Safe; $VERSION = '1.000'; $ops = '(<|>|<=|>=|lt|gt|le|ge|==|\!=|<=>|eq|ne|cmp|=~|\!~)'; ! $word = '\s*(?:\w+|".*?")\s*'; ! $condPattern_ifonly = '(%IF{('.$word.$ops.$word.')}%(.*?)%ENDIF%)'; ! $condPattern_ifelse = '(%IF{('.$word.$ops.$word.')}%(.*?)%ELSE%(.*?)%ENDIF%)'; # ========================= sub initPlugin *************** *** 112,125 **** } _initDefaults() if( ! $pluginInitialized ); ! ! # try to match if/else first (otherwise it gets masked by the if-only ! # variant ! $_[0] =~ s/$prefixPattern$condPattern_ifelse$postfixPattern/&handleConditional($3, $5, $6)/geo; ! ! # try to match the if-only variant ! $_[0] =~ s/$prefixPattern$condPattern_ifonly$postfixPattern/&handleConditional($3, $5, '')/geos; ! } # ========================= --- 112,141 ---- } _initDefaults() if( ! $pluginInitialized ); ! ! # Nested if support - find the last occurence of %IF each time through and ! # process it first. Thus, the deepest nesting in each set of ifs is ! # processed first and parsed correctly. -- Walter Mundt ! ! my $text = \$_[0]; ! my $ifIndex = rindex($$text, "%IF"); ! while ($ifIndex != -1) { ! my $startText = substr($$text, 0, $ifIndex); ! my $endText = substr($$text, $ifIndex); ! ! # try to match if/else first (otherwise it gets masked by the if-only ! # variant ! $endText =~ s/^$condPattern_ifelse/&handleConditional($2, $4, $5)/geos; ! ! # then try to match the if-only variant ! $endText =~ s/^$condPattern_ifonly/&handleConditional($2, $4, '')/geos; ! ! # mark any remaining %IFs as invalid syntax ! $endText =~ s/^%IF/!!IF/s; ! ! $$text = $startText . $endText; ! $ifIndex = rindex($$text, "%IF"); ! } } # =========================