lib/HTML/FormFu/Role/Render.pm

filter: Statementstmt 85.9% 61 / 71 Branchbran 57.1% 16 / 28 Conditioncond 36.3% 4 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 70.8% 90 / 127 SCAR 33.1
CC
20
Cov
74%
tt
25.1
_share_dir
4.3
render
3.1
CRAP 27.3
« lib/HTML/FormFu/Constraint/Equal.pm ↑ Summary lib/HTML/FormFu/Element.pm »
1 403 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::Render;
4 403 $HTML::FormFu::Role::Render::VERSION = '2.06';
5 403 ▶use HTML::FormFu::Util qw( process_attrs );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 403 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 403 ▶use Scalar::Util qw( reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 403 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 403 our $SHARE_DIR;
12 403 our $SHARE_ERROR;
13  
14 sub render {
15 1119 ▶ my $self = shift;
Subroutine render: called CC=3 SCAR=11.2
Pod undocumented
16  
17 1119 ▶ my $render_method = $ENV{HTML_FORMFU_RENDER_METHOD} || $self->render_method;
Condition33%1/3
$ENV{'HTML_FORMFU_RENDER_METHOD'} || $self->render_method
l!l&&r!l&&!r
011190
MC/DC0%0/2
$ENV{'HTML_FORMFU_RENDER_METHOD'} || $self->render_method
$ENV{'HTML_FORMFU_RENDER_METHOD'} $self->render_method
Truth table33%1/3
A || B
A= $ENV{'HTML_FORMFU_RENDER_METHOD'}B= $self->render_method
ABresult
1X1
011
000
18 1119 my $output = $self->$render_method(@_);
19  
20 1119 for my $proc ( @{ $self->form->get_output_processors } ) {
21 31 $output = $proc->process($output);
22 }
23  
24 1119 return $output;
25 }
26  
27 sub tt {
28 7 ▶ my ( $self, $args ) = @_;
Subroutine tt: called CC=15 SCAR=32.2
Pod undocumented
29  
30 7 ▶ $args ||= {};
Condition100%2/2
$args ||= {}
l!l
43
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
31  
32 7 ▶ $args->{filename} = $self->filename if !exists $args->{filename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"filename"} 3 4 7
33 7 ▶ $args->{render_data} = $self->render_data if !exists $args->{render_data};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"render_data"} 3 4 7
34  
35 7 my $form = $self->form;
36 7 my $share_dir = _share_dir();
37  
38 7 my %args = %{ $self->tt_args };
39  
40 7 ▶ if ( defined $share_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $share_dir) 7 0 7
41  
42 # add $share_dir to the end of INCLUDE_PATH
43  
44 $args{INCLUDE_PATH}
45 = exists $args{INCLUDE_PATH}
46 ? ref $args{INCLUDE_PATH} eq 'ARRAY'
47 2 ? [ @{ $args{INCLUDE_PATH} }, $share_dir ]
48 7 ▶ : [ $args{INCLUDE_PATH}, $share_dir ]
Branch: 2 branches
BranchTrueFalseTotal
exists $args{'INCLUDE_PATH'} ? : 7 0 7
ref $args{'INCLUDE_PATH'} eq 'ARRAY' ? : 2 5 7
49 : [$share_dir];
50 }
51  
52 7 ▶ $args{ENCODING} = 'UTF-8' if !exists $args{ENCODING};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"ENCODING"} 7 0 7
53 7 $args{RELATIVE} = 1;
54 7 $args{RECURSION} = 1;
55  
56 7 my $tt_module = $form->tt_module;
57  
58 $tt_module = $ENV{HTML_FORMFU_TT_MODULE}
59 if defined $ENV{HTML_FORMFU_TT_MODULE}
60 7 ▶ && length $ENV{HTML_FORMFU_TT_MODULE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"HTML_FORMFU_TT_MODULE"} and length $ENV{"HTML_FORMFU_TT_MODULE"} 0 7 7
Condition33%1/3
defined $ENV{"HTML_FORMFU_TT_MODULE"} and length $ENV{"HTML_FORMFU_TT_MODULE"}
!ll&&!rl&&r
700
MC/DC0%0/2
defined $ENV{"HTML_FORMFU_TT_MODULE"} and length $ENV{"HTML_FORMFU_TT_MODULE"}
defined $ENV{"HTML_FORMFU_TT_MODULE"} length $ENV{"HTML_FORMFU_TT_MODULE"}
Truth table33%1/3
A and B
A= defined $ENV{"HTML_FORMFU_TT_MODULE"}B= length $ENV{"HTML_FORMFU_TT_MODULE"}
ABresult
0X0
100
111
61  
62 7 my $class = $tt_module;
63 7 $class =~ s|::|/|g;
64 7 $class .= ".pm";
65  
66 7 ▶ if ( !exists $::INC{$class} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $INC{$class}) 0 7 7
67 0 eval { require $class };
68 0 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
69 }
70  
71 7 my $template = $tt_module->new( \%args );
72  
73 7 my $output;
74 my %vars = (
75 self => $args->{render_data},
76 7 process_attrs => \&process_attrs,
77 reftype => \&reftype,
78 );
79  
80 7 ▶ if ( !$template->process( $args->{filename}, \%vars, \$output ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($template->process($args->{"filename"}, \%vars, \$output)) 0 7 7
81  
82 0 my $error = $template->error;
83  
84 0 ▶ if ( $error->type() eq 'file' && $error =~ /not found/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error->type eq 'file' and $error =~ /not found/i) { } 0 0 0
Condition0%0/3
$error->type eq "file" and $error =~ /not found/i
!ll&&!rl&&r
000
MC/DC0%0/2
$error->type eq "file" and $error =~ /not found/i
$error->type eq "file" $error =~ /not found/i
Truth table0%0/3
A and B
A= $error->type eq "file"B= $error =~ /not found/i
ABresult
0X0
100
111
85 0 croak <<ERROR_MESSAGE;
86 $error
87 The template files should have been installed somewhere in \@INC as part of
88 the installation process.
89 If you're using Catalyst, see Catalyst::Helper::HTML::FormFu.
90 Alternatively, you can create a local copy of the files by running
91 `html_formfu_deploy.pl`.
92 Then set \$form->tt_args->{INCLUDE_PATH} to point to the template directory.
93 ERROR_MESSAGE
94  
95 }
96 else {
97 0 croak $error;
98 }
99 }
100  
101 7 return $output;
102 }
103  
104 sub _share_dir {
105  
106 7 ▶ return $SHARE_DIR if defined $SHARE_DIR;
Subroutine _share_dir: called CC=4 SCAR=14.6
Branch: 1 branch
BranchTrueFalseTotal
if defined $HTML::FormFu::Role::Render::SHARE_DIR 2 5 7
107  
108 5 ▶ return if $SHARE_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::FormFu::Role::Render::SHARE_ERROR 0 5 5
109  
110 5 eval {
111 5 require File::ShareDir;
112 5 require File::Spec;
113  
114 # dist_dir() doesn't reliably return the directory our files are in.
115 # find the path of one of our files, then get the directory from that
116  
117 5 my $path = File::ShareDir::dist_file( 'HTML-FormFu',
118 'templates/tt/xhtml/form' );
119  
120 5 my ( $volume, $dirs, $file ) = File::Spec->splitpath($path);
121  
122 5 $SHARE_DIR = File::Spec->catpath( $volume, $dirs, '' );
123 };
124  
125 5 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 5 5
126 0 $SHARE_DIR = undef;
127 0 $SHARE_ERROR = 1;
128 0 return;
129 }
130  
131 5 return $SHARE_DIR;
132 }
133  
134 403 1;
135  
136 __END__
137  
138 =pod
139  
140 =encoding UTF-8
141  
142 =head1 NAME
143  
144 HTML::FormFu::Role::Render
145  
146 =head1 VERSION
147  
148 version 2.06
149  
150 =head1 AUTHOR
151  
152 Carl Franks <cpan@fireartist.com>
153  
154 =head1 COPYRIGHT AND LICENSE
155  
156 This software is copyright (c) 2018 by Carl Franks.
157  
158 This is free software; you can redistribute it and/or modify it under
159 the same terms as the Perl 5 programming language system itself.
160  
161 =cut
« lib/HTML/FormFu/Constraint/Equal.pm ↑ Summary lib/HTML/FormFu/Element.pm »