From b13b15133aeb4ac4a2db5f2fe48c5623d42950dc Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 19 Jul 2010 18:11:32 +0200 Subject: [PATCH] UCW::Temple: Support substitution of named arguments via @(name) --- UCW/Temple.pm | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/UCW/Temple.pm b/UCW/Temple.pm index a7591e5..6efa090 100644 --- a/UCW/Temple.pm +++ b/UCW/Temple.pm @@ -16,6 +16,7 @@ our @EXPORT_OK = qw(); use IO::File; +our $arguments; our @cond; sub out { @@ -108,6 +109,11 @@ sub parse_string($) { $x =~ s/^\[//; $x =~ s/\]$//; eval_if_ok($x); + } elsif ($t =~ /\G@\(/cgs) { + my $x = get_nested(\$t, '\(', '\)'); + $x =~ s/^\(//; + $x =~ s/\)$//; + out (defined($arguments->{$x}) ? $arguments->{$x} : ""); } elsif ($t =~ /\G\@(\w+)\(/cgs) { my $func = $1; my $args = get_nested(\$t, '(', ')'); @@ -136,8 +142,9 @@ sub parse_file($) { parse_string($text); } -sub start() +sub start($) { + $arguments = $_[0]; @cond = (1); } @@ -146,15 +153,17 @@ sub finish() $#cond and die "Unterminated \@if (depth $#cond)"; } -sub process_file($) { - start(); - parse_file($_[0]); +sub process_file($;$) { + my ($name, $args) = @_; + start($args); + parse_file($name); finish(); } -sub process_string($) { - start(); - parse_string($_[0]); +sub process_string($;$) { + my ($string, $args) = @_; + start($args); + parse_string($string); finish(); } -- 2.39.5