summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2015-03-14 23:46:29 -0400
committerJesse Luehrs <doy@tozt.net>2015-03-14 23:46:29 -0400
commitec949d7fb6fd6c2de05a23f8691a03d589509741 (patch)
tree3ffbd17316f588e4c53d82ac752a09bc7cb6c62c
parentd2afd505de39854b4be13358cfb866f90ae5e14f (diff)
parentd461c4d4b34e9316ad9e9fa0320678d999b5868f (diff)
downloadspreadsheet-template-ec949d7fb6fd6c2de05a23f8691a03d589509741.tar.gz
spreadsheet-template-ec949d7fb6fd6c2de05a23f8691a03d589509741.zip
Merge pull request #7 from SocialFlowDev/skaufman.attr_json
make json an attr to allow dependency injection
-rw-r--r--Changes2
-rw-r--r--lib/Spreadsheet/Template.pm16
2 files changed, 17 insertions, 1 deletions
diff --git a/Changes b/Changes
index 06c2dfe..7ee1304 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,8 @@ Revision history for Spreadsheet-Template
{{$NEXT}}
+ - add json as a param instead of hardcoding from_json.
+
0.04 2014-09-10
- support more border types (merrilymeredith, #5)
diff --git a/lib/Spreadsheet/Template.pm b/lib/Spreadsheet/Template.pm
index 4b879c8..ebbf73b 100644
--- a/lib/Spreadsheet/Template.pm
+++ b/lib/Spreadsheet/Template.pm
@@ -404,6 +404,20 @@ has _processor => (
},
);
+=attr json
+
+Instance of a JSON class that will handle decoding. Defaults to an instance of L<JSON>.
+Passing in a JSON obj with ->relaxed(1) set will allow for trailing commas in your templates.
+
+=cut
+
+has json => (
+ is => 'ro',
+ default => sub {
+ return JSON->new;
+ }
+);
+
sub _writer {
my $self = shift;
my $class = $self->writer_class;
@@ -426,7 +440,7 @@ sub render {
my $contents = $self->_processor->process($template, $vars);
# not decode_json, since we expect that we are already being handed a
# character string (decode_json also decodes utf8)
- my $data = from_json($contents);
+ my $data = $self->json->decode($contents);
return $self->_writer->write($data);
}