- my $object = shift;
- my $vars = shift;
- my $sub = shift;
- my $str = $object->$sub;
-
- my ($key, $value);
- $str =~ s|<\%${key}\%>|$value|g while ($key, $value) = each %{ $vars };
- $object->$sub($str);
+ my (%params) = @_;
+ my $sub = $params{attribute};
+ my $str = $params{object}->$sub;
+ my $sub_fmt = lc($params{attribute_format} // 'text');
+
+ my ($start_tag, $end_tag) = $sub_fmt eq 'html' ? ('<%', '%>') : ('<%', '%>');
+
+ $str =~ s{ ${start_tag} ([a-z0-9_]+) ( \s+ format \s*=\s* (.*?) \s* )? ${end_tag} }{
+ my ($key, $format) = ($1, $3);
+ $key = $::locale->unquote_special_chars('html', $key) if $sub_fmt eq 'html';
+ my $new_value;
+
+ if (!$params{vars}->{$key}) {
+ $new_value = '';
+
+ } elsif ($format) {
+ $format = $::locale->unquote_special_chars('html', $format) if $sub_fmt eq 'html';
+
+ $new_value = DateTime::Format::Strptime->new(
+ pattern => $format,
+ locale => 'de_DE',
+ time_zone => 'local',
+ )->format_datetime($params{vars}->{$key}->[0]);
+
+ } else {
+ $new_value = $params{vars}->{$1}->[1]->($params{vars}->{$1}->[0]);
+ }
+
+ $new_value = $::locale->quote_special_chars('html', $new_value) if $sub_fmt eq 'html';
+
+ $new_value;
+
+ }eigx;
+
+ $params{object}->$sub($str);