line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::View::Excel::Template::Plus; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24739
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
710
|
use MRO::Compat; |
|
1
|
|
|
|
|
3542
|
|
|
1
|
|
|
|
|
38
|
|
7
|
1
|
|
|
1
|
|
323
|
use Excel::Template::Plus; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Scalar::Util 'blessed'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Catalyst::Exception; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
13
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use base 'Catalyst::View'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw[ |
18
|
|
|
|
|
|
|
etp_engine |
19
|
|
|
|
|
|
|
etp_config |
20
|
|
|
|
|
|
|
etp_params |
21
|
|
|
|
|
|
|
]); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
|
|
|
|
|
|
my($class, $c, $args) = @_; |
25
|
|
|
|
|
|
|
my $self = $class->next::method($c, $args); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $config = $c->config->{'View::Excel::Template::Plus'}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$args->{etp_engine} ||= $config->{etp_engine} || 'TT'; |
30
|
|
|
|
|
|
|
$args->{etp_config} ||= $config->{etp_config} || {}; |
31
|
|
|
|
|
|
|
$args->{etp_params} ||= $config->{etp_params} || {}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self->etp_engine($args->{etp_engine}); |
34
|
|
|
|
|
|
|
$self->etp_config($args->{etp_config}); |
35
|
|
|
|
|
|
|
$self->etp_params($args->{etp_params}); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
if ( defined $self->config->{TEMPLATE_EXTENSION} && $self->config->{TEMPLATE_EXTENSION} !~ /\./ ){ |
38
|
|
|
|
|
|
|
$c->log->warn(qq/Missing . (dot) in TEMPLATE_EXTENSION ( $class ), the attitude has changed with version 0.02./); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub process { |
45
|
|
|
|
|
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
my $c = shift; |
47
|
|
|
|
|
|
|
my @args = @_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $template = $self->get_template_filename($c); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
(defined $template) |
52
|
|
|
|
|
|
|
|| die 'No template specified for rendering'; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $etp_engine = $c->stash->{etp_engine} || $self->etp_engine; |
55
|
|
|
|
|
|
|
my $etp_config = $c->stash->{etp_config} || $self->etp_config; |
56
|
|
|
|
|
|
|
my $etp_params = $c->stash->{etp_params} || $self->etp_params; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $excel = $self->create_template_object($c => ( |
59
|
|
|
|
|
|
|
engine => $etp_engine, |
60
|
|
|
|
|
|
|
template => $template, |
61
|
|
|
|
|
|
|
config => $etp_config, |
62
|
|
|
|
|
|
|
params => $etp_params, |
63
|
|
|
|
|
|
|
)); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$excel->param( $self->get_template_params($c) ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# handle Content-Type |
68
|
|
|
|
|
|
|
$c->response->content_type('application/x-msexcel'); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# handle Content-Disposition |
71
|
|
|
|
|
|
|
my $excel_filename = $c->stash->{excel_filename} || 'excel.xls'; |
72
|
|
|
|
|
|
|
$excel_filename .= '.xls' unless ($excel_filename =~ /\.xls$/i); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $excel_disposition = $c->stash->{excel_disposition} || 'inline'; |
75
|
|
|
|
|
|
|
$c->response->headers->header("Content-Disposition" |
76
|
|
|
|
|
|
|
=> qq{$excel_disposition; filename="$excel_filename"}); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$c->response->body($excel->output); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub create_template_object { |
82
|
|
|
|
|
|
|
my ($self, $c, %options) = @_; |
83
|
|
|
|
|
|
|
Excel::Template::Plus->new( %options ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_template_filename { |
87
|
|
|
|
|
|
|
my ($self, $c) = @_; |
88
|
|
|
|
|
|
|
$c->stash->{template} |
89
|
|
|
|
|
|
|
|| |
90
|
|
|
|
|
|
|
($c->action . '.xml' . $self->config->{TEMPLATE_EXTENSION}); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub get_template_params { |
94
|
|
|
|
|
|
|
my ($self, $c) = @_; |
95
|
|
|
|
|
|
|
my $cvar = $self->config->{CATALYST_VAR} || 'c'; |
96
|
|
|
|
|
|
|
return ( $cvar => $c, %{ $c->stash } ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=pod |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Catalyst::View::Excel::Template::Plus - A Catalyst View for Excel::Template::Plus |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SYNOPSIS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# use the helper to create your View |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
MyApp_create.pl view Excel Excel::Template::Plus |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 DESCRIPTION |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This is a Catalyst View subclass which can handle rendering excel content |
118
|
|
|
|
|
|
|
through Excel::Template::Plus. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 CONFIG OPTIONS |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=over 4 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item I<etp_engine> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item I<etp_config> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item I<etp_params> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=back |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 STASH OPTIONS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=over 4 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item I<excel_disposition> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item I<excel_filename> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 METHODS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over 4 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item B<new> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This really just handles consuming the configuration parameters. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item B<process> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item B<get_template_filename> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item B<get_template_params> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item B<create_template_object> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 BUGS |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
All complex software has bugs lurking in it, and this module is no |
163
|
|
|
|
|
|
|
exception. If you find a bug please either email me, or add the bug |
164
|
|
|
|
|
|
|
to cpan-RT. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AUTHOR |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Stevan Little E<lt>stevan@cpan.orgE<gt> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Robert Bohne E<lt>rbo@cpan.orgE<gt> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Copyright 2007-2015 by Infinity Interactive, Inc. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L<http://www.iinteractive.com> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
181
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |