From e5904772f64a1ccfe84f9e1012761fe4e0575287 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 28 Jan 2013 11:39:39 +0000 Subject: [PATCH] Fixup {V_[]} in language variables. --- Webperl/Template.pm | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Webperl/Template.pm b/Webperl/Template.pm index 7194031..b09e289 100644 --- a/Webperl/Template.pm +++ b/Webperl/Template.pm @@ -315,10 +315,7 @@ sub replace_langvar { } } - # Do any module marker replacements if we can - if($self -> {"modules"}) { - $txtstr =~ s/{B_\[(\w+?)\]}/$self->replace_blockname($1)/ge; - } + $self -> fix_variables(\$textstr); return $txtstr; } @@ -506,16 +503,7 @@ sub process_template { $count += $$textref =~ s/{L_(\w+?)}/$self->replace_langvar($1)/ge; } while($count); - # Fix 'standard' variables - $$textref =~ s/{V_\[scriptpath\]}/$self->{scriptpath}/g; - $$textref =~ s/{V_\[templatepath\]}/$self->{templatepath}/g; - $$textref =~ s/{V_\[commonpath\]}/$self->{commonpath}/g; - $$textref =~ s/{V_\[sitename\]}/$self->{settings}->{config}->{site_name}/g; - - # Do any module marker replacements if we can - if($self -> {"modules"}) { - $$textref =~ s/{B_\[(\w+?)\]}/$self->replace_blockname($1)/ge; - } + $self -> fix_variables($textref); unless($nocharfix) { # Convert some common utf-8 characters @@ -535,6 +523,28 @@ sub process_template { } +## @method $ fix_variables($textref) +# Fix up {V_[name]} and {B_[name]} markers in the specified text. This will replace +# the variable and block markers in the specified text with the expanded equivalents. +# +# @param textref A reference to a string to process. +sub fix_variables { + my $self = shift; + my $textref = shift; + + # Fix 'standard' variables + $$textref =~ s/{V_\[scriptpath\]}/$self->{scriptpath}/g; + $$textref =~ s/{V_\[templatepath\]}/$self->{templatepath}/g; + $$textref =~ s/{V_\[commonpath\]}/$self->{commonpath}/g; + $$textref =~ s/{V_\[sitename\]}/$self->{settings}->{config}->{site_name}/g; + + # Do any module marker replacements if we can + if($self -> {"modules"}) { + $$textref =~ s/{B_\[(\w+?)\]}/$self->replace_blockname($1)/ge; + } +} + + # ============================================================================ # Higher-level templating functions