aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2017-10-20 17:46:28 +0100
committerdakkar <dakkar@thenautilus.net>2017-10-20 17:46:28 +0100
commitea6c0c8b7a09c2ffb0fb863d90f26d472e67f2a4 (patch)
treef79ae74e8c816b5a662d9644e21ec9a3dbcae75a
parentexpose dates to TT (diff)
downloadWebCoso-ea6c0c8b7a09c2ffb0fb863d90f26d472e67f2a4.tar.gz
WebCoso-ea6c0c8b7a09c2ffb0fb863d90f26d472e67f2a4.tar.bz2
WebCoso-ea6c0c8b7a09c2ffb0fb863d90f26d472e67f2a4.zip
include patched Template::Plugin::DateTime::Format
-rw-r--r--Makefile.PL2
-rw-r--r--lib/Template/Plugin/DateTimeFormat.pm38
-rw-r--r--t/test-site/src/common/base-feed.tt2
3 files changed, 40 insertions, 2 deletions
diff --git a/Makefile.PL b/Makefile.PL
index 6734da3..8ca8458 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -20,7 +20,7 @@ WriteMakefile(
'Path::Class' => '0',
'Slay::Maker' => '0',
'Template' => '0',
- 'Template::Plugin::DateTime::Format' => '0',
+ #'Template::Plugin::DateTime::Format' => '0',
'Test::Exception' => '0',
'Test::More' => '0',
'Text::Restructured' => '0',
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;
diff --git a/t/test-site/src/common/base-feed.tt b/t/test-site/src/common/base-feed.tt
index d91ec0e..9bc4ff7 100644
--- a/t/test-site/src/common/base-feed.tt
+++ b/t/test-site/src/common/base-feed.tt
@@ -1,4 +1,4 @@
-[% USE df = DateTime::Format('DateTime::Format::Strptime',
+[% USE df = DateTimeFormat('DateTime::Format::Strptime',
{ pattern => '%FT%T%z',
locale => 'en_US',
time_zone => 'GMT' }) -%]