line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::View::MicroTemplate::DataSection; |
2
|
2
|
|
|
2
|
|
2268554
|
use Moose; |
|
2
|
|
|
|
|
493533
|
|
|
2
|
|
|
|
|
21
|
|
3
|
2
|
|
|
2
|
|
19670
|
use Encode; |
|
2
|
|
|
|
|
9185
|
|
|
2
|
|
|
|
|
219
|
|
4
|
2
|
|
|
2
|
|
803
|
use Text::MicroTemplate::DataSection; |
|
2
|
|
|
|
|
12263
|
|
|
2
|
|
|
|
|
123
|
|
5
|
2
|
|
|
2
|
|
281
|
use namespace::autoclean; |
|
2
|
|
|
|
|
7282
|
|
|
2
|
|
|
|
|
23
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Catalyst::View'; |
10
|
|
|
|
|
|
|
with 'Catalyst::Component::ApplicationAttribute'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has section => ( |
13
|
|
|
|
|
|
|
is => 'rw', |
14
|
|
|
|
|
|
|
isa => 'Str', |
15
|
|
|
|
|
|
|
lazy_build => 1, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has context => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
isa => 'Catalyst', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has content_type => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => 'Str', |
26
|
|
|
|
|
|
|
lazy_build => 1, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has charset => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
isa => 'Str', |
32
|
|
|
|
|
|
|
default => 'UTF-8', |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has template_extension => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
isa => 'Str', |
38
|
|
|
|
|
|
|
default => '.mt', |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has engine => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => 'Text::MicroTemplate::DataSection', |
44
|
|
|
|
|
|
|
lazy_build => 1, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub ACCEPT_CONTEXT { |
49
|
2
|
|
|
2
|
1
|
274874
|
my ($self, $c) = @_; |
50
|
2
|
|
|
|
|
131
|
$self->context($c); |
51
|
2
|
|
|
|
|
14
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _build_section { |
55
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
56
|
0
|
|
|
|
|
0
|
return $self->context->action->class; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _build_content_type { |
60
|
1
|
|
|
1
|
|
4
|
my ($self) = @_; |
61
|
1
|
|
|
|
|
58
|
return $self->context->res->content_type; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _build_engine { |
65
|
1
|
|
|
1
|
|
5
|
my ($self) = @_; |
66
|
1
|
|
|
|
|
64
|
return Text::MicroTemplate::DataSection->new(package => $self->section); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub render { |
70
|
1
|
|
|
1
|
0
|
6
|
my ($self, $c, $template) = @_; |
71
|
1
|
|
|
|
|
61
|
return $self->engine->render($template.$self->template_extension, $c->stash); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub process { |
75
|
1
|
|
|
1
|
1
|
1597
|
my ($self, $c) = @_; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
33
|
|
|
11
|
my $template = $c->stash->{template} || $c->action->name; |
78
|
1
|
|
|
|
|
229
|
my $body = $self->render($c, $template); |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
1477
|
$c->res->content_type($self->content_type.'; charset=' . $self->charset); |
81
|
|
|
|
|
|
|
|
82
|
1
|
50
|
33
|
|
|
336
|
if (blessed $body && $body->can('as_string')) { |
83
|
1
|
|
|
|
|
10
|
$body = $body->as_string; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
53
|
$c->res->body( $body ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Catalyst::View::MicroTemplate::DataSection - Text::MicroTemplate::DataSection View For Catalyst |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# subclassing to making your view class |
102
|
|
|
|
|
|
|
package MyApp::View::DataSection; |
103
|
|
|
|
|
|
|
use Moose; |
104
|
|
|
|
|
|
|
extends 'Catalyst::View::MicroTemplate::DataSection'; |
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# using in a controller |
108
|
|
|
|
|
|
|
sub index :Path :Args(0) { |
109
|
|
|
|
|
|
|
my ( $self, $c ) = @_; |
110
|
|
|
|
|
|
|
$c->stash->{username} = 'masakyst'; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
... |
113
|
|
|
|
|
|
|
.. |
114
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
__DATA__ |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
@@ index.mt |
120
|
|
|
|
|
|
|
? my $stash = shift; |
121
|
|
|
|
|
|
|
hello <?= $stash->{username} ?> !! |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 DESCRIPTION |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Catalyst::View::MicroTemplate::DataSection is simple wrapper module allows you to render MicroTemplate template from __DATA__ section in Catalyst controller. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 One file .psgi example |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
plackup -a hello.psgi |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
package Hello::View::MicroTemplate::DataSection { |
133
|
|
|
|
|
|
|
use Moose; extends 'Catalyst::View::MicroTemplate::DataSection'; |
134
|
|
|
|
|
|
|
sub _build_section { 'main' } |
135
|
|
|
|
|
|
|
}; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
package Hello::Controller::Root { |
138
|
|
|
|
|
|
|
use Moose; BEGIN { extends 'Catalyst::Controller' } |
139
|
|
|
|
|
|
|
__PACKAGE__->config(namespace => ''); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub index :Path :Args(0) { |
142
|
|
|
|
|
|
|
my ($self, $c) = @_; |
143
|
|
|
|
|
|
|
$c->stash->{okinawa} = "Yomitan perl mongers"; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub end : ActionClass('RenderView') {} |
147
|
|
|
|
|
|
|
}; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
package Hello 0.01 { |
150
|
|
|
|
|
|
|
use Moose; |
151
|
|
|
|
|
|
|
use Catalyst::Runtime 5.80; |
152
|
|
|
|
|
|
|
extends 'Catalyst'; |
153
|
|
|
|
|
|
|
__PACKAGE__->setup(); |
154
|
|
|
|
|
|
|
}; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
package main; |
157
|
|
|
|
|
|
|
Hello->psgi_app; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__DATA__ |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
@@ index.mt |
162
|
|
|
|
|
|
|
? my $stash = shift; |
163
|
|
|
|
|
|
|
<?= $stash->{okinawa} ?> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 SEE ALSO |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=over 1 |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item L<Text::MicroTemplate::DataSection> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item L<Data::Section::Simple> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=back |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 LICENSE |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Copyright (C) Masaaki Saito. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
182
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 AUTHOR |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Masaaki Saito E<lt>masakyst.public@gmail.comE<gt> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|