| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MojoX::Renderer::HTP; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21758
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
40
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
100
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use base 'Mojo::Base'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
746
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use HTML::Template::Pro (); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
MojoX::Renderer::HTP - HTML::Tempate::Pro renderer for Mojo |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.032 |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.032'; |
|
22
|
|
|
|
|
|
|
__PACKAGE__->attr('pro' => 1); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Add the handler: |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use MojoX::Renderer::HTP; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub startup { |
|
31
|
|
|
|
|
|
|
... |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $pro = MojoX::Renderer::HTP->build( |
|
34
|
|
|
|
|
|
|
mojo => $self, |
|
35
|
|
|
|
|
|
|
template_options => { |
|
36
|
|
|
|
|
|
|
path => [ $self->home->rel_dir('templates') ], |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->renderer->add_handler( pro => $pro ); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->renderer->default_handler('pro'); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Then in controller: |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->render( |
|
49
|
|
|
|
|
|
|
message => 'test', |
|
50
|
|
|
|
|
|
|
list => [{id => 1}, { id=>2 }] |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 build |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
create handler for renderer |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub build { |
|
62
|
|
|
|
|
|
|
my $self = shift->SUPER::new(@_); |
|
63
|
|
|
|
|
|
|
$self->_init(@_); |
|
64
|
|
|
|
|
|
|
return sub { $self->_render(@_) } |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _init { |
|
68
|
|
|
|
|
|
|
my $self = shift; |
|
69
|
|
|
|
|
|
|
my %args = @_; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $mojo = delete $args{mojo}; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# now we only remember options |
|
74
|
|
|
|
|
|
|
$self->pro($args{template_options}); |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return $self; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _render { |
|
80
|
|
|
|
|
|
|
my ($self, $renderer, $c, $output, $options) = @_; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# get template name from controller |
|
83
|
|
|
|
|
|
|
my $template = $c->stash->{template}; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# if not set get it from options |
|
86
|
|
|
|
|
|
|
$template = $renderer->template_path($options) |
|
87
|
|
|
|
|
|
|
unless $template; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# try to get content |
|
90
|
|
|
|
|
|
|
my $content = eval { |
|
91
|
|
|
|
|
|
|
my $t = HTML::Template::Pro->new( |
|
92
|
|
|
|
|
|
|
filename => $template, |
|
93
|
|
|
|
|
|
|
die_on_bad_params => 1, |
|
94
|
|
|
|
|
|
|
%{$self->pro} |
|
95
|
|
|
|
|
|
|
); |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$t->param({%{$c->stash}, c => $c}); |
|
98
|
|
|
|
|
|
|
$t->output(); |
|
99
|
|
|
|
|
|
|
}; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# write error message to log if eval fails |
|
102
|
|
|
|
|
|
|
# and return with false |
|
103
|
|
|
|
|
|
|
if($@) { |
|
104
|
|
|
|
|
|
|
warn "MojoX::Renderer::HTP ERROR: $@"; |
|
105
|
|
|
|
|
|
|
return 0; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# return false if content empty |
|
109
|
|
|
|
|
|
|
return 0 |
|
110
|
|
|
|
|
|
|
unless $content; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# assign content to $output ref |
|
113
|
|
|
|
|
|
|
$$output = $content; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# and return with true (success) |
|
116
|
|
|
|
|
|
|
return 1; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Sergey Lobin, C<< >> |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 BUGS |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
126
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
127
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SUPPORT |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
perldoc MojoX::Renderer::HTP |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
You can also look for information at: |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over 4 |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * Search CPAN |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Copyright 2009 Sergey Lobin, all rights reserved. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
167
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; # End of MojoX::Renderer::HTP |