From ea6c0c8b7a09c2ffb0fb863d90f26d472e67f2a4 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 20 Oct 2017 17:46:28 +0100 Subject: include patched Template::Plugin::DateTime::Format --- lib/Template/Plugin/DateTimeFormat.pm | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/Template/Plugin/DateTimeFormat.pm (limited to 'lib') diff --git a/lib/Template/Plugin/DateTimeFormat.pm b/lib/Template/Plugin/DateTimeFormat.pm new file mode 100644 index 0000000..8c6d592 --- /dev/null +++ b/lib/Template/Plugin/DateTimeFormat.pm @@ -0,0 +1,38 @@ +package Template::Plugin::DateTimeFormat; +$Template::Plugin::DateTimeFormat::VERSION = '0.04'; +use 5.006; +use strict; +use warnings; +use DateTime; +use Class::Load; + +# hacked Template::Plugin::DateTime::Format with patch from +# https://rt.cpan.org/Public/Bug/Display.html?id=120391 + +use base 'Template::Plugin'; + +sub new { + my ($class, $context, $formatter_class, $new_args, $format_args) = @_; + Class::Load::load_class($formatter_class || die 'need class name'); + + my @new_args = ref $new_args eq 'ARRAY' ? @$new_args : $new_args; + if ($format_args) { + $format_args = [ $format_args ] unless ref $format_args eq 'ARRAY'; + } + + bless { + _CONTEXT => $context, + formatter => $formatter_class->new(@new_args), + format_args => $format_args || [], + }, $class; +} + +sub format { + my ($self, $date) = @_; + + my $fmt = $self->{formatter}; + my @args = @{$self->{format_args}}; + return $fmt->format_datetime($date, @args); +} + +1; -- cgit v1.2.3