line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::View::MicroTemplate::DataSection; |
2
|
1
|
|
|
1
|
|
1352
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use Encode; |
4
|
|
|
|
|
|
|
use Text::MicroTemplate::DataSection; |
5
|
|
|
|
|
|
|
use namespace::autoclean; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
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
|
|
|
|
|
|
|
my ($self, $c) = @_; |
50
|
|
|
|
|
|
|
$self->context($c); |
51
|
|
|
|
|
|
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _build_section { |
55
|
|
|
|
|
|
|
my ($self) = @_; |
56
|
|
|
|
|
|
|
return $self->context->action->class; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _build_content_type { |
60
|
|
|
|
|
|
|
my ($self) = @_; |
61
|
|
|
|
|
|
|
return $self->context->res->content_type; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _build_engine { |
65
|
|
|
|
|
|
|
my ($self) = @_; |
66
|
|
|
|
|
|
|
return Text::MicroTemplate::DataSection->new(package => $self->section); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub render { |
70
|
|
|
|
|
|
|
my ($self, $c, $template) = @_; |
71
|
|
|
|
|
|
|
return $self->engine->render($template.$self->template_extension, $c->stash); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub process { |
75
|
|
|
|
|
|
|
my ($self, $c) = @_; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $template = $c->stash->{template} || $c->action->name; |
78
|
|
|
|
|
|
|
my $body = $self->render($c, $template); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$c->res->content_type($self->content_type.'; charset=' . $self->charset); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
if (blessed $body && $body->can('as_string')) { |
83
|
|
|
|
|
|
|
$body = $body->as_string; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$c->res->body( $body ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |