line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Excel::Template::Plus; |
3
|
2
|
|
|
2
|
|
44442
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Module::Runtime (); |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
|
|
|
|
|
|
shift; |
11
|
|
|
|
|
|
|
my %options = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $engine_class = 'Excel::Template::Plus::' . $options{engine}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
eval { Module::Runtime::use_module($engine_class) }; |
16
|
|
|
|
|
|
|
if ($@) { |
17
|
|
|
|
|
|
|
confess "Could not load engine class ($engine_class) because " . $@; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $template = eval { $engine_class->new(%options) }; |
21
|
|
|
|
|
|
|
if ($@) { |
22
|
|
|
|
|
|
|
confess "Could not create template from engine class ($engine_class) because " . $@; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return $template; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
no Moose; 1; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
__END__ |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=pod |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Excel::Template::Plus - An extension to the Excel::Template module |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SYNOPSIS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
use Excel::Template::Plus; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $template = Excel::Template::Plus->new( |
43
|
|
|
|
|
|
|
engine => 'TT', |
44
|
|
|
|
|
|
|
template => 'greeting.tmpl', |
45
|
|
|
|
|
|
|
config => { INCLUDE => [ '/templates' ] }, |
46
|
|
|
|
|
|
|
params => { greeting => 'Hello' } |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$template->param(location => 'World'); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$template->write_file('greeting.xls'); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DISCLAIMER |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This is the very first release of this module, it is an idea that I and |
56
|
|
|
|
|
|
|
Rob Kinyon (the author of Excel::Template) had discussed many times, but |
57
|
|
|
|
|
|
|
never got around to doing. This is the first attempt at bring this to |
58
|
|
|
|
|
|
|
reality, it may change B<radically> as it evolves, so be warned. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This module is an extension of the Excel::Template module, which allows |
63
|
|
|
|
|
|
|
the user to use various "engines" from which you can create Excel files |
64
|
|
|
|
|
|
|
through Excel::Template. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The idea is to use the existing (and very solid) excel file generation |
67
|
|
|
|
|
|
|
code in Excel::Template, but to extend its more templatey bits with more |
68
|
|
|
|
|
|
|
powerful options. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The only engine currently provided is the Template Toolkit engine, which |
71
|
|
|
|
|
|
|
replaces Excel::Template's built in template features (the LOOP, and IF |
72
|
|
|
|
|
|
|
constructs) with the full power of TT. This is similar to the module |
73
|
|
|
|
|
|
|
Excel::Template::TT, but expands on that even further to try and create |
74
|
|
|
|
|
|
|
a more extensive system. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
You can use this module to create Excel::Template-compatible XML files |
77
|
|
|
|
|
|
|
using one of the supported engines. For example, with the TT engine you |
78
|
|
|
|
|
|
|
could create a Excel::Template XML file like: |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
<workbook> |
81
|
|
|
|
|
|
|
<worksheet name="[% worksheet_name %]"> |
82
|
|
|
|
|
|
|
[% my_cols = get_list_of_columns %] |
83
|
|
|
|
|
|
|
<row> |
84
|
|
|
|
|
|
|
[% FOR col = my_cols %] |
85
|
|
|
|
|
|
|
<bold><cell>[% col %]</cell></bold> |
86
|
|
|
|
|
|
|
[% END %] |
87
|
|
|
|
|
|
|
</row> |
88
|
|
|
|
|
|
|
[% FOR my_row = get_list_of_objects %] |
89
|
|
|
|
|
|
|
<row> |
90
|
|
|
|
|
|
|
[% FOR col = my_cols %] |
91
|
|
|
|
|
|
|
<cell>[% my_row.$col %]</cell> |
92
|
|
|
|
|
|
|
[% END %] |
93
|
|
|
|
|
|
|
</row> |
94
|
|
|
|
|
|
|
[% END %] |
95
|
|
|
|
|
|
|
</worksheet> |
96
|
|
|
|
|
|
|
</workbook> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Your TT template thus creates a XML file suitable to handing over to |
99
|
|
|
|
|
|
|
Excel::Template for processing. Excel::Template::Plus simplifies |
100
|
|
|
|
|
|
|
the template-creation and handing-over process. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Future engine/plans include: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over 4 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item Pure Perl |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This would allow you to write you Excel::Template files using Perl itself |
109
|
|
|
|
|
|
|
which would then output the XML for Excel::Template to consume. This would |
110
|
|
|
|
|
|
|
be modeled after the recently released L<Template::Declare> module perhaps. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item TT Plugins/Macros/Wrappers |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This is basically anything which will make the TT engine easier to write |
115
|
|
|
|
|
|
|
templates for. I have experimented with some of these things, but I was not |
116
|
|
|
|
|
|
|
happy with any of them enough to release them yet. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item HTML::Template |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Excel::Template's templating features are based on HTML::Template, but the |
121
|
|
|
|
|
|
|
HTML::Template plugins and other goodies are not compatible. This engine |
122
|
|
|
|
|
|
|
would bring those things to Excel::Template. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=back |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 METHODS |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=over 4 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item B<new (%options)> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This method basically serves as a factory for creating new engine instances |
133
|
|
|
|
|
|
|
(for which L<Excel::Template::Plus::TT> is the only one currently). The only |
134
|
|
|
|
|
|
|
parameter that it requires is I<engine>, all other parameters are passed |
135
|
|
|
|
|
|
|
onto the engine's constructor (see the individual docs for more details on |
136
|
|
|
|
|
|
|
what is required). |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item B<meta> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Access to the metaclass. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=back |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 BUGS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
All complex software has bugs lurking in it, and this module is no |
147
|
|
|
|
|
|
|
exception. If you find a bug please either email me, or add the bug |
148
|
|
|
|
|
|
|
to cpan-RT. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=over 4 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item This module came out of several discussions I had with Rob Kinyon. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 AUTHOR |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Stevan Little E<lt>stevan@cpan.orgE<gt> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Copyright 2007-2014 by Infinity Interactive, Inc. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L<http://www.iinteractive.com> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
169
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |