use strict;
+use Scalar::Util qw(blessed);
+
# Parameters:
# 1. The template's file name
# 2. A reference to the Form object
}
sub _get_loop_variable {
- my $self = shift;
- my $var = shift;
- my $get_array = shift;
- my @indices = @_;
-
+ my ($self, $var, $get_array, @indices) = @_;
my $form = $self->{form};
- my $value;
+ my ($value, @methods);
+
+ if ($var =~ m/\./) {
+ ($var, @methods) = split m/\./, $var;
+ }
if (($get_array || @indices) && (ref $form->{TEMPLATE_ARRAYS} eq 'HASH') && (ref $form->{TEMPLATE_ARRAYS}->{$var} eq 'ARRAY')) {
$value = $form->{TEMPLATE_ARRAYS}->{$var};
$value = $value->[$indices[$i]];
}
+ for my $part (@methods) {
+ if (ref($value) =~ m/^(?:Form|HASH)$/) {
+ $value = $value->{$part};
+ } elsif (blessed($value) && $value->can($part)) {
+ $value = $value->$part;
+ } else {
+ $value = '';
+ last;
+ }
+ }
+
return $value;
}
while ($text =~ /$self->{substitute_vars_re}/) {
my ($tag_pos, $tag_len) = ($-[0], $+[0] - $-[0]);
- my ($var, @options) = split(/\s+/, $1);
+ my ($var, @option_list) = split(/\s+/, $1);
+ my %options = map { ($_ => 1) } @option_list;
my $value = $self->_get_loop_variable($var, 0, @indices);
- $value = $self->format_string($value) unless (grep(/^NOESCAPE$/, @options));
+ $value = $form->parse_amount({ numberformat => $::myconfig{output_numberformat} || $::myconfig{numberformat} }, $value) if $options{NOFORMAT};
+ $value = $self->format_string($value) unless $options{NOESCAPE};
substr($text, $tag_pos, $tag_len, $value);
}
my $not = $1;
my $var = $2;
+ my $comparison = $3; # Optionaler Match um $4..$8
my $operator_neg = $4; # '=' oder '!' oder undef, wenn kein Vergleich erkannt
my $operator_type = $5; # '=' oder '~' für Stringvergleich oder Regex
my $quoted_word = $7; # nur gültig, wenn quoted string angegeben (siehe unten); dann "value" aus <%if var == "value" %>
substr($$contents, 0, length($&)) = "";
my $block;
- ($block, $$contents) = $self->find_end($$contents, 0, $var, $not);
+ ($block, $$contents) = $self->find_end($$contents, 0, "$var $comparison", $not);
if (!$block) {
$self->{"error"} = "Unclosed $self->{tag_start}if$self->{tag_end}." unless ($self->{"error"});
$main::lxdebug->leave_sub();