lib/HTML/FormFu/Element.pm

filter: Statementstmt 93.2% 125 / 134 Branchbran 91.1% 31 / 34 Conditioncond 94.4% 17 / 18 MC/DCmcdc 91.6% 11 / 12 Subroutinesub 83.3% 35 / 42 Podpod 15.3% 4 / 26 totaltotal 83.8% 223 / 266 CC 27 SCAR 15.8
CC
27
Cov
93%
_match_default_args_type
12.0
_match_default_args
11.0
name
4.0
CRAP 4.9
« lib/HTML/FormFu/Attribute.pm ↑ Summary lib/HTML/FormFu/Role/Element/Coercible.pm »
1 426 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Element;
4 426 $HTML::FormFu::Element::VERSION = '2.09';
5 # ABSTRACT: Element Base Class
6  
7 426 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 426 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 426 with 'HTML::FormFu::Role::Render',
11 'HTML::FormFu::Role::FormAndElementMethods',
12 'HTML::FormFu::Role::HasParent',
13 'HTML::FormFu::Role::CustomRoles',
14 'HTML::FormFu::Role::Populate';
15  
16 426 ▶use HTML::FormFu::Attribute qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
17 mk_attrs
18 mk_attr_accessors
19 mk_output_accessors
20 mk_inherited_accessors
21 mk_inherited_merging_accessors
22 426 );
23 426 ▶use HTML::FormFu::ObjectUtil qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
24 load_config_file
25 load_config_filestem
26 form
27 stash
28 parent
29 get_parent
30 426 );
31 use HTML::FormFu::Util
32 426 ▶ qw( require_class xml_escape process_attrs _merge_hashes );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 426 ▶use Clone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34 426 ▶use Scalar::Util qw( weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
35 426 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 426 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
38 'eq' => '_string_equals',
39 '==' => '_object_equals',
40 378 ▶ '""' => sub { return shift->render },
Subroutine __ANON__: called CC=1 SCAR=0.0
41 151 ▶ bool => sub {1},
Subroutine __ANON__: called CC=1 SCAR=0.0
42 426 fallback => 1
43 426 );
44  
45 426 __PACKAGE__->mk_attr_accessors(qw( id ));
46  
47 426 has type => ( is => 'rw', traits => ['Chained'] );
48 426 has filename => ( is => 'rw', traits => ['Chained'] );
49 426 has is_field => ( is => 'rw', traits => ['Chained'] );
50 426 has is_block => ( is => 'rw', traits => ['Chained'] );
51 426 has is_repeatable => ( is => 'rw', traits => ['Chained'] );
52  
53 4140 ▶after BUILD => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
54 4140 my ( $self, $args ) = @_;
55  
56 # TODO move to attribute 'default'
57 4140 $self->attributes( {} );
58 4140 $self->stash( {} );
59  
60 4140 return;
61 426 };
62  
63 68104 ▶sub name {
Subroutine name: called CC=4 SCAR=13.9
Pod documented
64 68104 my ( $self, $name ) = @_;
65  
66 68104 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1287 66817 68104
67  
68 1287 ▶ if ( defined $name && $name =~ /[\.\[\]]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and $name =~ /[\.\[\]]/) 1 1286 1287
Condition100%3/3
defined $name and $name =~ /[\.\[\]]/
!ll&&!rl&&r
712791
MC/DC100%2/2
defined $name and $name =~ /[\.\[\]]/
defined $name $name =~ /[\.\[\]]/
Truth table100%3/3
A and B
A= defined $nameB= $name =~ /[\.\[\]]/
ABresult
0X0
100
111
69 1 croak <<'ERROR_MESSAGE';
70 element names may not contain periods or square brackets
71 see documentation on nested_names() for details
72 ERROR_MESSAGE
73 }
74  
75 1286 $self->{name} = $name;
76  
77 1286 return $self;
78 }
79  
80 66817 return $self->{name};
81 }
82  
83 1877 ▶sub setup { }
Subroutine setup: called CC=1 SCAR=0.0
Pod undocumented
84  
85 0 ▶sub get_elements { [] }
Subroutine get_elements: not called CC=1 SCAR=6.9
Pod undocumented
86  
87 1 ▶sub get_element { }
Subroutine get_element: called CC=1 SCAR=0.0
Pod undocumented
88  
89 811 ▶sub get_all_elements { [] }
Subroutine get_all_elements: called CC=1 SCAR=0.0
Pod undocumented
90  
91 0 ▶sub get_all_element { }
Subroutine get_all_element: not called CC=1 SCAR=0.0
Pod undocumented
92  
93 11 ▶sub get_fields { [] }
Subroutine get_fields: called CC=1 SCAR=0.0
Pod undocumented
94  
95 0 ▶sub get_field { }
Subroutine get_field: not called CC=1 SCAR=0.0
Pod undocumented
96  
97 0 ▶sub get_deflators { [] }
Subroutine get_deflators: not called CC=1 SCAR=6.9
Pod undocumented
98  
99 1 ▶sub get_filters { [] }
Subroutine get_filters: called CC=1 SCAR=0.0
Pod undocumented
100  
101 1 ▶sub get_constraints { [] }
Subroutine get_constraints: called CC=1 SCAR=0.0
Pod undocumented
102  
103 1 ▶sub get_inflators { [] }
Subroutine get_inflators: called CC=1 SCAR=0.0
Pod undocumented
104  
105 1 ▶sub get_validators { [] }
Subroutine get_validators: called CC=1 SCAR=0.0
Pod undocumented
106  
107 1 ▶sub get_transformers { [] }
Subroutine get_transformers: called CC=1 SCAR=0.0
Pod undocumented
108  
109 3 ▶sub get_errors { [] }
Subroutine get_errors: called CC=1 SCAR=0.0
Pod undocumented
110  
111 1 ▶sub clear_errors { }
Subroutine clear_errors: called CC=1 SCAR=0.0
Pod undocumented
112  
113 1408 ▶sub pre_process { }
Subroutine pre_process: called CC=1 SCAR=0.0
Pod undocumented
114  
115 1722 ▶sub process { }
Subroutine process: called CC=1 SCAR=0.0
Pod undocumented
116  
117 1722 ▶sub post_process { }
Subroutine post_process: called CC=1 SCAR=0.0
Pod undocumented
118  
119 3 ▶sub prepare_id { }
Subroutine prepare_id: called CC=1 SCAR=0.0
Pod documented
120  
121 1642 ▶sub prepare_attrs { }
Subroutine prepare_attrs: called CC=1 SCAR=0.0
Pod documented
122  
123 0 ▶sub get_output_processors {
Subroutine get_output_processors: not called CC=1 SCAR=6.9
Pod undocumented
124 0 my $self = shift;
125  
126 0 return $self->form->get_output_processors(@_);
127 }
128  
129 0 ▶sub get_output_processor {
Subroutine get_output_processor: not called CC=1 SCAR=6.9
Pod undocumented
130 0 my $self = shift;
131  
132 0 return $self->form->get_output_processor(@_);
133 }
134  
135 277 ▶sub _match_default_args {
Subroutine _match_default_args: called CC=11 SCAR=24.0
136 277 my ( $self, $defaults ) = @_;
137  
138 277 ▶ return {} if !$defaults || !%$defaults;
Branch: 1 branch
BranchTrueFalseTotal
unless $defaults and %$defaults 251 26 277
Condition66%2/3
$defaults and %$defaults
!ll&&!rl&&r
251026
MC/DC50%1/2
$defaults and %$defaults
$defaults %$defaults
Truth table66%2/3
A and B
A= $defaultsB= %$defaults
ABresult
0X0
100
111
139  
140 # apply any starting with 'Block', 'Field', 'Input' first, each longest first
141 0 my @block = sort { length $a <=> length $b }
142 26 grep { $_ =~ /^Block/ } keys %$defaults;
143 0 my @field = sort { length $a <=> length $b }
144 26 grep { $_ =~ /^Field/ } keys %$defaults;
145 3 my @input = sort { length $a <=> length $b }
146 26 grep { $_ =~ /^Input/ } keys %$defaults;
147  
148 26 my %others = map { $_ => 1 } keys %$defaults;
149 26 map { delete $others{$_} } @block, @field, @input;
150  
151 # apply remaining keys, longest first
152 26 my $arg = {};
153  
154 KEY:
155 26 for my $key ( @block, @field, @input,
156 5 sort { length $a <=> length $b } keys %others )
157 {
158 49 my @type = split qr{\|}, $key;
159 49 my $match;
160  
161 TYPE:
162 49 for my $type (@type) {
163 52 my $not_in;
164 my $is_in;
165 52 ▶ if ( $type =~ s/^-// ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ s/^-//) { } 3 49 52
elsif ($type =~ s/^\+//) { } 1 48 49
166 3 $not_in = 1;
167 }
168 elsif ( $type =~ s/^\+// ) {
169 1 $is_in = 1;
170 }
171  
172 52 ▶ my $check_parents = $not_in || $is_in;
Condition100%3/3
$not_in || $is_in
l!l&&r!l&&!r
3148
MC/DC100%2/2
$not_in || $is_in
$not_in $is_in
Truth table100%3/3
A || B
A= $not_inB= $is_in
ABresult
1X1
011
000
173  
174 52 ▶ if ( $self->_match_default_args_type( $type, $check_parents ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_match_default_args_type($type, $check_parents)) 26 26 52
175 26 ▶ if ($not_in) {
Branch: 1 branch
BranchTrueFalseTotal
if ($not_in) { } 1 25 26
176 1 next KEY;
177 }
178 else {
179 25 $match = 1;
180 25 next TYPE;
181 }
182 }
183 }
184  
185 48 ▶ if ($match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match) 24 24 48
186 24 $arg = _merge_hashes( $arg, $defaults->{$key} );
187 }
188 }
189  
190 26 return $arg;
191 }
192  
193 52 ▶sub _match_default_args_type {
Subroutine _match_default_args_type: called CC=12 SCAR=24.9
194 52 my ( $self, $type, $check_parents ) = @_;
195  
196 52 my @target;
197 52 ▶ if ($check_parents) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check_parents) { } 4 48 52
198 4 my $self = $self;
199 4 ▶ while ( defined( my $parent = $self->parent ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $parent = $self->parent)) 5 0 5
200 5 ▶ last if !$parent->isa('HTML::FormFu::Element');
Branch: 1 branch
BranchTrueFalseTotal
unless $parent->isa("HTML::FormFu::Element") 4 1 5
201 1 push @target, $parent;
202 1 $self = $parent;
203 }
204 }
205 else {
206 48 @target = ($self);
207 }
208  
209 52 for my $target (@target) {
210  
211 # handle Block default_args
212 49 ▶ if ( 'Block' eq $type
Branch: 1 branch
BranchTrueFalseTotal
if ("Block" eq $type and $target->isa("HTML::FormFu::Element::Block")) 3 46 49
Condition100%3/3
"Block" eq $type and $target->isa("HTML::FormFu::Element::Block")
!ll&&!rl&&r
4243
MC/DC100%2/2
"Block" eq $type and $target->isa("HTML::FormFu::Element::Block")
"Block" eq $type $target->isa("HTML::FormFu::Element::Block")
Truth table100%3/3
A and B
A= "Block" eq $typeB= $target->isa("HTML::FormFu::Element::Block")
ABresult
0X0
100
111
213 && $target->isa('HTML::FormFu::Element::Block') )
214 {
215 3 return 1;
216 }
217  
218 # handle Field default_args
219 46 ▶ if ( 'Field' eq $type
Branch: 1 branch
BranchTrueFalseTotal
if ("Field" eq $type and $target->does("HTML::FormFu::Role::Element::Field")) 11 35 46
Condition100%3/3
"Field" eq $type and $target->does("HTML::FormFu::Role::Element::Field")
!ll&&!rl&&r
30511
MC/DC100%2/2
"Field" eq $type and $target->does("HTML::FormFu::Role::Element::Field")
"Field" eq $type $target->does("HTML::FormFu::Role::Element::Field")
Truth table100%3/3
A and B
A= "Field" eq $typeB= $target->does("HTML::FormFu::Role::Element::Field")
ABresult
0X0
100
111
220 && $target->does('HTML::FormFu::Role::Element::Field') )
221 {
222 11 return 1;
223 }
224  
225 # handle Input default_args
226 35 ▶ if ( 'Input' eq $type
Branch: 1 branch
BranchTrueFalseTotal
if ("Input" eq $type and $target->does("HTML::FormFu::Role::Element::Input")) 5 30 35
Condition100%3/3
"Input" eq $type and $target->does("HTML::FormFu::Role::Element::Input")
!ll&&!rl&&r
2645
MC/DC100%2/2
"Input" eq $type and $target->does("HTML::FormFu::Role::Element::Input")
"Input" eq $type $target->does("HTML::FormFu::Role::Element::Input")
Truth table100%3/3
A and B
A= "Input" eq $typeB= $target->does("HTML::FormFu::Role::Element::Input")
ABresult
0X0
100
111
227 && $target->does('HTML::FormFu::Role::Element::Input') )
228 {
229 5 return 1;
230 }
231  
232 # handle explicit default_args
233 30 ▶ if ( $type eq $target->type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $target->type) 7 23 30
234 7 return 1;
235 }
236 }
237 }
238  
239 558 ▶sub clone {
Subroutine clone: called CC=2 SCAR=7.0
Pod documented
240 558 my ($self) = @_;
241  
242 558 my %new = %$self;
243  
244 $new{tt_args} = Clone::clone( $self->{tt_args} )
245 558 ▶ if $self->{tt_args};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tt_args"} 0 558 558
246  
247 558 $new{attributes} = Clone::clone( $self->attributes );
248 558 $new{model_config} = Clone::clone( $self->model_config );
249  
250 558 return bless \%new, ref $self;
251 }
252  
253 1270 ▶sub render_data {
Subroutine render_data: called CC=1 SCAR=0.0
Pod undocumented
254 1270 return shift->render_data_non_recursive(@_);
255 }
256  
257 1642 ▶sub render_data_non_recursive {
Subroutine render_data_non_recursive: called CC=2 SCAR=7.1
Pod undocumented
258 1642 my ( $self, $args ) = @_;
259  
260 my %render = (
261 name => xml_escape( $self->name ),
262 attributes => xml_escape( $self->attributes ),
263 type => $self->type,
264 filename => $self->filename,
265 is_field => $self->is_field,
266 stash => $self->stash,
267 parent => $self->parent,
268 0 ▶ form => sub { return shift->{parent}->form },
Subroutine __ANON__: not called CC=1 SCAR=6.9
269 1642 ▶ object => $self,
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 1642 0 1642
270 $args ? %$args : (),
271 );
272  
273 1642 weaken( $render{parent} );
274  
275 1642 $self->prepare_id( \%render );
276  
277 1642 $self->prepare_attrs( \%render );
278  
279 1642 return \%render;
280 }
281  
282 426 __PACKAGE__->meta->make_immutable;
283  
284 426 1;
285  
286 __END__
« lib/HTML/FormFu/Attribute.pm ↑ Summary lib/HTML/FormFu/Role/Element/Coercible.pm »