line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Terse::View::TT; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
55822
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.02; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use base qw/Terse::View/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
457
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
85954
|
use Template; |
|
1
|
|
|
|
|
15437
|
|
|
1
|
|
|
|
|
286
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub build_view { |
13
|
0
|
|
|
0
|
0
|
|
my ($self, $config) = @_; |
14
|
|
|
|
|
|
|
$config = $self->app_config = { |
15
|
|
|
|
|
|
|
EVAL_PERL => 0, |
16
|
|
|
|
|
|
|
INCLUDE_PATH => 'root/src', |
17
|
|
|
|
|
|
|
TEMPLATE_EXTENSION => 'tt', |
18
|
|
|
|
|
|
|
CLASS => 'Template', |
19
|
0
|
|
|
|
|
|
%{ $config } |
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
}; |
21
|
0
|
|
|
|
|
|
$self->{template} = $config->{CLASS}->new($config); |
22
|
0
|
|
|
|
|
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub render { |
26
|
0
|
|
|
0
|
0
|
|
my ($self, $t, $data) = @_; |
27
|
0
|
|
|
|
|
|
my $template = $data->{template}; |
28
|
0
|
0
|
|
|
|
|
if (!$template) { |
29
|
0
|
|
|
|
|
|
$template = $t->response_namespace; |
30
|
0
|
|
|
|
|
|
my $handler = $t->response_handler; |
31
|
0
|
0
|
|
|
|
|
if ($template !~ m/$handler$/) { |
32
|
0
|
|
|
|
|
|
$template .= '/' . $handler; |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
|
$template .= '.' . $self->app_config->TEMPLATE_EXTENSION; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
0
|
|
|
|
|
unless ($template) { |
37
|
0
|
0
|
|
|
|
|
return $self->can('handle_error') ? $self->handle_error('Error - Cannot find template') : ('text/html', ' Error - Cannot find template '); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
0
|
0
|
|
|
|
$self->template->{SERVICE}->{WRAPPER} = ($data->{NO_WRAPPER} || (!$data->WRAPPER && ! $self->app_config->WRAPPER)) |
|
|
|
0
|
|
|
|
|
40
|
|
|
|
|
|
|
? [] |
41
|
|
|
|
|
|
|
: [($data->WRAPPER || $self->app_config->WRAPPER) . '.' . $self->app_config->TEMPLATE_EXTENSION]; |
42
|
0
|
|
|
|
|
|
my $output = eval { $self->render_template($template, $data) }; |
|
0
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ($@) { |
44
|
0
|
0
|
|
|
|
|
return $self->can('handle_error') ? $self->handle_error($@) : ('text/html', $@); |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
return ('text/html', $output); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub render_template { |
50
|
0
|
|
|
0
|
0
|
|
my ($self, $template, $data) = @_; |
51
|
0
|
|
|
|
|
|
my $output; |
52
|
0
|
0
|
|
|
|
|
unless ($self->template->process( $template, {%{$data}}, \$output )) { |
|
0
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
die $self->template->error; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
return $output; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |