From e99fa320ad6c3d3aa8b3a816a1ab4034a7f37247 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 2 Jul 2013 11:19:36 -0400 Subject: allow passing options to the backends --- lib/Spreadsheet/Template.pm | 16 ++++++++++++++-- lib/Spreadsheet/Template/Generator.pm | 11 ++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/Spreadsheet/Template.pm b/lib/Spreadsheet/Template.pm index 1000393..21e432c 100644 --- a/lib/Spreadsheet/Template.pm +++ b/lib/Spreadsheet/Template.pm @@ -11,12 +11,24 @@ has processor_class => ( default => 'Spreadsheet::Template::Processor::Xslate', ); +has processor_options => ( + is => 'ro', + isa => 'HashRef', + default => sub { {} }, +); + has writer_class => ( is => 'ro', isa => 'Str', default => 'Spreadsheet::Template::Writer::XLSX', ); +has writer_options => ( + is => 'ro', + isa => 'HashRef', + default => sub { {} }, +); + has processor => ( is => 'ro', does => 'Spreadsheet::Template::Processor', @@ -26,7 +38,7 @@ has processor => ( my $self = shift; my $class = $self->processor_class; load_class($class); - return $class->new; + return $class->new($self->processor_options); }, ); @@ -39,7 +51,7 @@ has writer => ( my $self = shift; my $class = $self->writer_class; load_class($class); - return $class->new; + return $class->new($self->writer_options); }, ); diff --git a/lib/Spreadsheet/Template/Generator.pm b/lib/Spreadsheet/Template/Generator.pm index 655f1b0..0590eb6 100644 --- a/lib/Spreadsheet/Template/Generator.pm +++ b/lib/Spreadsheet/Template/Generator.pm @@ -4,13 +4,22 @@ use Moose; use Class::Load 'load_class'; use JSON; +has parser_options => ( + is => 'ro', + isa => 'HashRef', + default => sub { {} }, +); + sub generate { my $self = shift; my ($filename) = @_; (my $ext = $filename) =~ s/.*\.//; my $class = $self->parser_classes->{$ext}; load_class($class); - my $parser = $class->new(filename => $filename); + my $parser = $class->new( + filename => $filename, + %{ $self->parser_options } + ); my $data = $parser->parse; return JSON->new->pretty->canonical->encode($data); } -- cgit v1.2.3-54-g00ecf