Revision 85629633
Von Sven Schöling vor etwa 13 Jahren hinzugefügt
SL/Template/Simple.pm | ||
---|---|---|
85 | 85 |
} |
86 | 86 |
|
87 | 87 |
sub _get_loop_variable { |
88 |
my $self = shift; |
|
89 |
my $var = shift; |
|
90 |
my $get_array = shift; |
|
91 |
my @indices = @_; |
|
92 |
|
|
88 |
my ($self, $var, $get_array, @indices) = @_; |
|
93 | 89 |
my $form = $self->{form}; |
94 |
my $value;
|
|
90 |
my ($value, @methods);
|
|
95 | 91 |
|
96 | 92 |
if ($var =~ m/\./) { |
97 |
$value = $form; |
|
98 |
for my $part (split(m/\./, $var)) { |
|
99 |
if (ref($value) =~ m/^(?:Form|HASH)$/) { |
|
100 |
$value = $value->{$part}; |
|
101 |
} elsif (blessed($value) && $value->can($part)) { |
|
102 |
$value = $value->$part; |
|
103 |
} else { |
|
104 |
$value = ''; |
|
105 |
last; |
|
106 |
} |
|
107 |
} |
|
108 |
} elsif (($get_array || @indices) && (ref $form->{TEMPLATE_ARRAYS} eq 'HASH') && (ref $form->{TEMPLATE_ARRAYS}->{$var} eq 'ARRAY')) { |
|
93 |
($var, @methods) = split m/\./, $var; |
|
94 |
} |
|
95 |
|
|
96 |
if (($get_array || @indices) && (ref $form->{TEMPLATE_ARRAYS} eq 'HASH') && (ref $form->{TEMPLATE_ARRAYS}->{$var} eq 'ARRAY')) { |
|
109 | 97 |
$value = $form->{TEMPLATE_ARRAYS}->{$var}; |
110 | 98 |
} else { |
111 | 99 |
$value = $form->{$var}; |
... | ... | |
116 | 104 |
$value = $value->[$indices[$i]]; |
117 | 105 |
} |
118 | 106 |
|
107 |
for my $part (@methods) { |
|
108 |
if (ref($value) =~ m/^(?:Form|HASH)$/) { |
|
109 |
$value = $value->{$part}; |
|
110 |
} elsif (blessed($value) && $value->can($part)) { |
|
111 |
$value = $value->$part; |
|
112 |
} else { |
|
113 |
$value = ''; |
|
114 |
last; |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
119 | 118 |
return $value; |
120 | 119 |
} |
121 | 120 |
|
Auch abrufbar als: Unified diff
dot notation in templates auch für TEMPLATE_ARRAY variablen