line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Role::Render; |
2
|
|
|
|
|
|
|
|
3
|
400
|
|
|
400
|
|
230512
|
use HTML::FormFu::Util qw( process_attrs ); |
|
400
|
|
|
|
|
593
|
|
|
400
|
|
|
|
|
18632
|
|
4
|
400
|
|
|
400
|
|
1586
|
use Carp qw( croak ); |
|
400
|
|
|
|
|
494
|
|
|
400
|
|
|
|
|
13988
|
|
5
|
400
|
|
|
400
|
|
1459
|
use Scalar::Util qw( reftype ); |
|
400
|
|
|
|
|
497
|
|
|
400
|
|
|
|
|
13615
|
|
6
|
|
|
|
|
|
|
|
7
|
400
|
|
|
400
|
|
1586
|
use strict; |
|
400
|
|
|
|
|
550
|
|
|
400
|
|
|
|
|
12966
|
|
8
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
400
|
|
|
400
|
|
1530
|
use Moose::Role; |
|
400
|
|
|
|
|
518
|
|
|
400
|
|
|
|
|
3335
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $SHARE_DIR; |
13
|
|
|
|
|
|
|
our $SHARE_ERROR; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub render { |
16
|
1116
|
|
|
1116
|
0
|
1341
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
1116
|
|
33
|
|
|
6200
|
my $render_method = $ENV{HTML_FORMFU_RENDER_METHOD} || $self->render_method; |
19
|
1116
|
|
|
|
|
4919
|
my $output = $self->$render_method(@_); |
20
|
|
|
|
|
|
|
|
21
|
1116
|
|
|
|
|
2175
|
for my $proc ( @{ $self->form->get_output_processors } ) { |
|
1116
|
|
|
|
|
3117
|
|
22
|
31
|
|
|
|
|
91
|
$output = $proc->process($output); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
1116
|
|
|
|
|
5565
|
return $output; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub tt { |
29
|
7
|
|
|
7
|
0
|
13
|
my ( $self, $args ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
7
|
|
100
|
|
|
23
|
$args ||= {}; |
32
|
|
|
|
|
|
|
|
33
|
7
|
100
|
|
|
|
94
|
$args->{filename} = $self->filename if !exists $args->{filename}; |
34
|
7
|
100
|
|
|
|
37
|
$args->{render_data} = $self->render_data if !exists $args->{render_data}; |
35
|
|
|
|
|
|
|
|
36
|
7
|
|
|
|
|
34
|
my $form = $self->form; |
37
|
7
|
|
|
|
|
23
|
my $share_dir = _share_dir(); |
38
|
|
|
|
|
|
|
|
39
|
7
|
|
|
|
|
9
|
my %args = %{ $self->tt_args }; |
|
7
|
|
|
|
|
46
|
|
40
|
|
|
|
|
|
|
|
41
|
7
|
50
|
|
|
|
23
|
if ( defined $share_dir ) { |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# add $share_dir to the end of INCLUDE_PATH |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$args{INCLUDE_PATH} |
46
|
|
|
|
|
|
|
= exists $args{INCLUDE_PATH} |
47
|
|
|
|
|
|
|
? ref $args{INCLUDE_PATH} eq 'ARRAY' |
48
|
2
|
|
|
|
|
9
|
? [ @{ $args{INCLUDE_PATH} }, $share_dir ] |
49
|
7
|
100
|
|
|
|
51
|
: [ $args{INCLUDE_PATH}, $share_dir ] |
|
|
50
|
|
|
|
|
|
50
|
|
|
|
|
|
|
: [$share_dir]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
7
|
50
|
|
|
|
26
|
$args{ENCODING} = 'UTF-8' if !exists $args{ENCODING}; |
54
|
7
|
|
|
|
|
13
|
$args{RELATIVE} = 1; |
55
|
7
|
|
|
|
|
12
|
$args{RECURSION} = 1; |
56
|
|
|
|
|
|
|
|
57
|
7
|
|
|
|
|
212
|
my $tt_module = $form->tt_module; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$tt_module = $ENV{HTML_FORMFU_TT_MODULE} |
60
|
|
|
|
|
|
|
if defined $ENV{HTML_FORMFU_TT_MODULE} |
61
|
7
|
50
|
33
|
|
|
31
|
&& length $ENV{HTML_FORMFU_TT_MODULE}; |
62
|
|
|
|
|
|
|
|
63
|
7
|
|
|
|
|
11
|
my $class = $tt_module; |
64
|
7
|
|
|
|
|
14
|
$class =~ s|::|/|g; |
65
|
7
|
|
|
|
|
11
|
$class .= ".pm"; |
66
|
|
|
|
|
|
|
|
67
|
7
|
50
|
|
|
|
21
|
if ( !exists $::INC{$class} ) { |
68
|
0
|
|
|
|
|
0
|
eval { require $class }; |
|
0
|
|
|
|
|
0
|
|
69
|
0
|
0
|
|
|
|
0
|
croak $@ if $@; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
7
|
|
|
|
|
61
|
my $template = $tt_module->new( \%args ); |
73
|
|
|
|
|
|
|
|
74
|
7
|
|
|
|
|
50462
|
my $output; |
75
|
|
|
|
|
|
|
my %vars = ( |
76
|
|
|
|
|
|
|
self => $args->{render_data}, |
77
|
7
|
|
|
|
|
42
|
process_attrs => \&process_attrs, |
78
|
|
|
|
|
|
|
reftype => \&reftype, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
7
|
50
|
|
|
|
39
|
if ( !$template->process( $args->{filename}, \%vars, \$output ) ) { |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
my $error = $template->error; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
0
|
|
|
0
|
if ( $error->type() eq 'file' && $error =~ /not found/i ) { |
86
|
0
|
|
|
|
|
0
|
croak <<ERROR_MESSAGE; |
87
|
|
|
|
|
|
|
$error |
88
|
|
|
|
|
|
|
The template files should have been installed somewhere in \@INC as part of |
89
|
|
|
|
|
|
|
the installation process. |
90
|
|
|
|
|
|
|
If you're using Catalyst, see Catalyst::Helper::HTML::FormFu. |
91
|
|
|
|
|
|
|
Alternatively, you can create a local copy of the files by running |
92
|
|
|
|
|
|
|
`html_formfu_deploy.pl`. |
93
|
|
|
|
|
|
|
Then set \$form->tt_args->{INCLUDE_PATH} to point to the template directory. |
94
|
|
|
|
|
|
|
ERROR_MESSAGE |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
0
|
|
|
|
|
0
|
croak $error; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
7
|
|
|
|
|
28487
|
return $output; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _share_dir { |
106
|
|
|
|
|
|
|
|
107
|
7
|
100
|
|
7
|
|
19
|
return $SHARE_DIR if defined $SHARE_DIR; |
108
|
|
|
|
|
|
|
|
109
|
5
|
50
|
|
|
|
13
|
return if $SHARE_ERROR; |
110
|
|
|
|
|
|
|
|
111
|
5
|
|
|
|
|
11
|
eval { |
112
|
5
|
|
|
|
|
2699
|
require File::ShareDir; |
113
|
5
|
|
|
|
|
23532
|
require File::Spec; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# dist_dir() doesn't reliably return the directory our files are in. |
116
|
|
|
|
|
|
|
# find the path of one of our files, then get the directory from that |
117
|
|
|
|
|
|
|
|
118
|
5
|
|
|
|
|
19
|
my $path = File::ShareDir::dist_file( 'HTML-FormFu', |
119
|
|
|
|
|
|
|
'templates/tt/xhtml/form' ); |
120
|
|
|
|
|
|
|
|
121
|
5
|
|
|
|
|
781
|
my ( $volume, $dirs, $file ) = File::Spec->splitpath($path); |
122
|
|
|
|
|
|
|
|
123
|
5
|
|
|
|
|
46
|
$SHARE_DIR = File::Spec->catpath( $volume, $dirs, '' ); |
124
|
|
|
|
|
|
|
}; |
125
|
|
|
|
|
|
|
|
126
|
5
|
50
|
|
|
|
21
|
if ($@) { |
127
|
0
|
|
|
|
|
0
|
$SHARE_DIR = undef; |
128
|
0
|
|
|
|
|
0
|
$SHARE_ERROR = 1; |
129
|
0
|
|
|
|
|
0
|
return; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
5
|
|
|
|
|
12
|
return $SHARE_DIR; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |