1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package Spreadsheet::Template;
use Moose;
use Class::Load 'load_class';
use JSON;
has processor_class => (
is => 'ro',
isa => 'Str',
default => 'Spreadsheet::Template::Processor::Xslate',
);
has writer_class => (
is => 'ro',
isa => 'Str',
default => 'Spreadsheet::Template::Writer::XLSX',
);
has processor => (
is => 'ro',
does => 'Spreadsheet::Template::Processor',
handles => 'Spreadsheet::Template::Processor',
lazy => 1,
default => sub {
my $self = shift;
my $class = $self->processor_class;
load_class($class);
return $class->new;
},
);
has writer => (
is => 'ro',
does => 'Spreadsheet::Template::Writer',
handles => 'Spreadsheet::Template::Writer',
lazy => 1,
default => sub {
my $self = shift;
my $class = $self->writer_class;
load_class($class);
return $class->new;
},
);
sub render {
my $self = shift;
my ($template, $vars) = @_;
my $contents = $self->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);
return $self->write($data);
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;
|