*** /home/dj/tmp/lib/TWiki/Plugins/TopicVarsPlugin.pm Thu Nov 15 22:23:09 2001 --- lib/TWiki/Plugins/TopicVarsPlugin.pm Fri Jun 28 11:26:51 2002 *************** *** 66,81 **** ## with the symbol table, but I'm not up to that right now. sub getVarsFromTopic { ! my ( $theWeb, $theTopic ) = @_; my $theKeyPrefix = ""; &TWiki::Func::writeDebug( "- TWiki::Plugins::TopicVarsPlugin::getVarsFromTopic( $theWeb.$theTopic )" ) if $debug; ! my( $meta, $text ) = &TWiki::Store::readTopic( $theWeb, $theTopic ); $text =~ s/\r/\n/go; $text =~ s/\n+/\n/go; my $keyPrefix = $theKeyPrefix || ""; # prefix is for plugin prefs my $key = ""; my $value =""; --- 66,87 ---- ## with the symbol table, but I'm not up to that right now. sub getVarsFromTopic { ! my ( $theWeb, $theTopic, $text ) = @_; my $theKeyPrefix = ""; &TWiki::Func::writeDebug( "- TWiki::Plugins::TopicVarsPlugin::getVarsFromTopic( $theWeb.$theTopic )" ) if $debug; ! (my $meta, $text ) = &TWiki::Store::readTopic( $theWeb, $theTopic ) ! unless defined $text; $text =~ s/\r/\n/go; $text =~ s/\n+/\n/go; + # initialize the variable hash for this topic. if not + # done, running under mod_perl causes old variables to be cached + # and there's no way of expunging them. + $vars{$theWeb}{$theTopic} = {}; + my $keyPrefix = $theKeyPrefix || ""; # prefix is for plugin prefs my $key = ""; my $value =""; *************** *** 84,89 **** --- 90,96 ---- if( /^\t+\*\sSet\s([a-zA-Z0-9_]+)\s\=\s*(.*)/ ) { if( $isKey ) { $vars{$theWeb}{$theTopic}{$key} = $value; + &TWiki::Func::writeDebug( "- TopicVarsPlugin::getVarsFromTopic $theWeb.$theTopic.$key: [$value]" ) if $debug; } $key = "$keyPrefix$1"; $value = defined $2 ? $2 : ""; *************** *** 94,99 **** --- 101,107 ---- $value .= "\n$_"; } else { $vars{$theWeb}{$theTopic}{$key} = $value; + &TWiki::Func::writeDebug( "- TopicVarsPlugin::getVarsFromTopic $theWeb.$theTopic.$key: [$value]" ) if $debug; $isKey = 0; } } *************** *** 100,105 **** --- 108,114 ---- } if( $isKey ) { $vars{$theWeb}{$theTopic}{$key} = $value; + &TWiki::Func::writeDebug( "- TopicVarsPlugin::getVarsFromTopic $theWeb.$theTopic.$key: [$value]" ) if $debug; } } *************** *** 149,154 **** --- 158,172 ---- # $_[0] =~ s/%XYZ%/&handleXyz()/geo; # $_[0] =~ s/%XYZ{(.*?)}%/&handleXyz($1)/geo; + # must reparse the current topic in case we're about to render the topic + # after a Preview. If we don't, changes to the variables won't be noticed. + # It'd be nice to limit the reparsing to that stage. Note that the + # actual passed text is parsed (rather than the stored topic), + # so that we pick up any changes immediately. Unfortunately, this + # loads the variable hash with the preview values (which may not be the + # final runtime values) so we have to clean them out later! + getVarsFromTopic( $_[2], $_[1], $_[0] ); + ## Handle unqualified var references (will look on this page) $_[0] =~ s/%([a-zA-Z0-9_]+)%/&do_var_from_topic($1)/geo; *************** *** 157,162 **** --- 175,185 ---- ## Handle fully-qualified var references (will look at webs/topics on this wiki) $_[0] =~ s/%([A-Z][^%]*)\.([A-Z]+[a-z]+[A-Z]+[A-Za-z0-9_]*)\.([a-zA-Z0-9_]+)%/&do_var_from_wiki($1, $2, $3)/geo; + + # ok, now we *delete* any variables from the passed text, as mentioned + # above. this sucks. if only we knew when we were in preview mode! + $vars{$theWeb}{$theTopic} = {}; + } # =========================