line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::View::PSP; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
868
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
5
|
use base 'Catalyst::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
840
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use File::Spec; |
7
|
|
|
|
|
|
|
use Text::PSP; |
8
|
|
|
|
|
|
|
use Text::PSP::Parser; |
9
|
|
|
|
|
|
|
use Text::PSP::Template; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors('psp'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Catalyst::View::PSP - PSP View Class |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# use the helper |
22
|
|
|
|
|
|
|
create.pl view PSP PSP |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# lib/MyApp/View/PSP.pm |
25
|
|
|
|
|
|
|
package MyApp::View::PSP; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use base 'Catalyst::View::PSP'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
__PACKAGE__->config( |
30
|
|
|
|
|
|
|
workdir => '/tmp/psp' |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Meanwhile, maybe in an 'end' action |
36
|
|
|
|
|
|
|
$c->forward('MyApp::View::PSP'); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 DESCRIPTION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This is the C<PSP> view class. Your subclass should inherit from this |
42
|
|
|
|
|
|
|
class. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 METHODS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over 4 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item new |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
The constructor for the PSP view. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub new { |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
my $c = shift; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$self = $self->NEXT::new(@_); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my %config = ( |
61
|
|
|
|
|
|
|
create_workdir => 1, |
62
|
|
|
|
|
|
|
template_root => $c->config->{root}, |
63
|
|
|
|
|
|
|
workdir => File::Spec->catdir( File::Spec->tmpdir, 'psp' ), |
64
|
|
|
|
|
|
|
%{ $self->config } |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$self->psp( Text::PSP->new(%config) ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item process |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Renders the template specified in C<< $c->stash->{template} >> or |
75
|
|
|
|
|
|
|
C<< $c->request->match >>. Template arguments are C<$c>. Output is stored |
76
|
|
|
|
|
|
|
in C<< $c->response->body >>. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub process { |
81
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $template = $c->stash->{template} || $c->req->match; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
unless ($template) { |
86
|
|
|
|
|
|
|
$c->log->debug('No template specified for rendering') if $c->debug; |
87
|
|
|
|
|
|
|
return 0; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $psp; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
eval { $psp = $self->psp->find_template( 'base/' . $template ) }; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
if ( my $error = $@ ) { |
95
|
|
|
|
|
|
|
chomp $error; |
96
|
|
|
|
|
|
|
$error = qq/Couldn't parse template "$template". Error: "$error"/; |
97
|
|
|
|
|
|
|
$c->log->error($error); |
98
|
|
|
|
|
|
|
$c->error($error); |
99
|
|
|
|
|
|
|
return 0; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$c->log->debug(qq/Rendering template "$template"/) if $c->debug; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $body; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
eval { $body = $psp->run($c) }; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
if ( my $error = $@ ) { |
109
|
|
|
|
|
|
|
chomp $error; |
110
|
|
|
|
|
|
|
$error = qq/Couldn't render template "$template". Error: "$error"/; |
111
|
|
|
|
|
|
|
$c->log->error($error); |
112
|
|
|
|
|
|
|
$c->error($error); |
113
|
|
|
|
|
|
|
return 0; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
unless ( $c->response->headers->content_type ) { |
117
|
|
|
|
|
|
|
$c->res->headers->content_type('text/html; charset=utf-8'); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$c->response->body( join( "\n", @{ $body } ) ); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
return 1; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item config |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This allows your view subclass to pass additional settings to the |
128
|
|
|
|
|
|
|
Petal config hash. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=back |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SEE ALSO |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L<Text::PSP>, L<Catalyst>, L<Catalyst::Base>. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Christian Hansen, C<ch@ngmedia.com> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 COPYRIGHT |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it |
143
|
|
|
|
|
|
|
under the same terms as Perl itself. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |