From 1c9aacf69e71f3db4843bdad100caa8e0286d068 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 1 Jul 2009 10:46:19 +0200 Subject: [PATCH] =?utf8?q?Einf=C3=BChrung=20RegEx=20f=C3=BCr=20Vergleichso?= =?utf8?q?perationen=20in=20<%if=20...%>-Statements.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Template.pm | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/SL/Template.pm b/SL/Template.pm index 4a59273a0..4a26b7b4c 100644 --- a/SL/Template.pm +++ b/SL/Template.pm @@ -336,13 +336,37 @@ sub parse_block { $new_contents .= $self->substitute_vars(substr($contents, 0, $pos_if), @indices); substr($contents, 0, $pos_if) = ""; - if ($contents !~ m|^$self->{tag_start_qm}if\s*(not)?\s+(.*?)$self->{tag_end_qm}|) { + # if ($contents !~ m|^$self->{tag_start_qm}if\s*(not)?\s+(.*?)$self->{tag_end_qm}|) { + if ($contents !~ m/^$self->{tag_start_qm} + \s* + (not|\!)? # $1 -- Eventuelle Negierung + \s* + ([^\s]+) # $2 -- Name der zu überprüfenden Variablen + ( # $3 -- Beginn des optionalen Vergleiches + \s* + ([!=])= # $4 -- Art des Vergleiches speichern + \s* + ( # $5 -- Gequoteter String oder Bareword + "(.*)(?{tag_end_qm} + /x) { $self->{"error"} = "Malformed $self->{tag_start}if$self->{tag_end}."; $main::lxdebug->leave_sub(); return undef; } - my ($not, $var) = ($1, $2); + my $not = $1; + my $var = $2; + my $operator = $4; # '=' oder '!' oder undef, wenn kein Vergleich erkannt + my $quoted = $5; # nur gültig, wenn quoted string angegeben (siehe unten); dann "value" aus <%if var == "value" %> + my $bareword = $7; # undef, falls quoted string angegeben wurde; andernfalls "othervar" aus <%if var == othervar %> + + $not = !$not if ($operator && $operator eq '!'); substr($contents, 0, length($&)) = ""; @@ -353,17 +377,18 @@ sub parse_block { return undef; } - my $form = $self->{form}; - $form = $form->{TEMPLATE_ARRAYS} if @indices - && ref $form->{TEMPLATE_ARRAYS} eq 'HASH' - && ref $form->{TEMPLATE_ARRAYS}->{$var} eq 'ARRAY'; - my $value = $form->{$var}; - for (my $i = 0; $i < scalar(@indices); $i++) { - last unless (ref($value) eq "ARRAY"); - $value = $value->[$indices[$i]]; + my $value = $self->_get_loop_variable($var, 0, @indices); + my $hit = 0; + + if ($operator) { + my $compare_to = $bareword ? $self->_get_loop_variable($bareword, 0, @indices) : $quoted; + $hit = ($not && !($value eq $compare_to)) || (!$not && ($value eq $compare_to)); + + } else { + $hit = ($not && ! $value) || (!$not && $value); } - if (($not && !$value) || (!$not && $value)) { + if ($hit) { my $new_text = $self->parse_block($block, @indices); if (!defined($new_text)) { $main::lxdebug->leave_sub(); -- 2.20.1