lib/HTML/FormFu/Attribute.pm

filter: Statementstmt 78.1% 186 / 238 Branchbran 56.9% 33 / 58 Conditioncond 42.4% 14 / 33 MC/DCmcdc 18.1% 4 / 22 Subroutinesub 66.6% 24 / 36 Podpod 0.0% 0 / 8 totaltotal 66.0% 261 / 395 CC 310 SCAR 16.0
CC
310
Cov
71%
__ANON__
30.0
autofocus
30.0
multiple
30.0
CRAP 5.0
« lib/HTML/FormFu/Role/Element/Input.pm ↑ Summary lib/HTML/FormFu/Element.pm »
1 518 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Attribute;
4 518 $HTML::FormFu::Attribute::VERSION = '2.09';
5 # ABSTRACT: accessor class
6  
7 518 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 518 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 518 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 518 ▶use Class::MOP::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 518 ▶use HTML::FormFu::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 append_xml_attribute remove_xml_attribute literal
14 518 _parse_args );
15  
16 518 our @EXPORT_OK = qw(
17 mk_attrs mk_attr_accessors
18 mk_attr_modifiers mk_inherited_accessors
19 mk_output_accessors mk_inherited_merging_accessors
20 mk_attr_bool_accessors
21 );
22  
23 1451 ▶sub mk_attrs {
Subroutine mk_attrs: called CC=4 SCAR=14.2
Pod undocumented
24 1451 my ( $self, @names ) = @_;
25  
26 1451 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
014510
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
27  
28 1451 for my $name (@names) {
29 12282 ▶ my $sub = sub {
Subroutine attributes: called CC=4 SCAR=13.9
Subroutine __ANON__: called CC=4 SCAR=13.9
30 12282 my ( $self, $attrs ) = @_;
31  
32 12282 ▶ if ( !exists $self->{$name} ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{$name}) 3470 8812 12282
unless (exists $self->{$name}) 6933 15834 22767
33 3470 $self->{$name} = {};
34 }
35  
36 12282 ▶ return $self->{$name} if @_ == 1;
Branch: 2 branches
BranchTrueFalseTotal
if @_ == 1 5698 6584 12282
if @_ == 1 18307 13804 32111
37  
38 6584 my $attr_slot = $self->{$name};
39  
40 6584 ▶ while ( my ( $key, $value ) = each %$attrs ) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = each %$attrs) 86 6584 6670
if (() = each %$attrs) 283 7769 8052
41 86 $attr_slot->{$key} = $value;
42 }
43  
44 6584 return $self;
45 3187 };
46  
47 3187 my $method = Class::MOP::Method->wrap(
48 body => $sub,
49 name => $name,
50 package_name => $class,
51 );
52  
53 0 ▶ my $xml_sub = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 0 my ( $self, $attrs ) = @_;
55  
56 return $self->$name(
57 0 { map { $_, literal( $attrs->{$_} ) }
58 keys %$attrs
59 } );
60 3187 };
61  
62 3187 my $xml_method = Class::MOP::Method->wrap(
63 body => $xml_sub,
64 name => "${name}_xml",
65 package_name => $class,
66 );
67  
68 3187 $class->meta->add_method( $name, $method );
69 3187 $class->meta->add_method( "${name}_xml", $xml_method );
70  
71 0 ▶ my $loc_sub = sub {
Subroutine attrs_loc: not called CC=2 SCAR=13.0
Subroutine __ANON__: called CC=2 SCAR=13.0
72 0 my ( $self, $mess, @args ) = @_;
73  
74 0 ▶ if ( ref $mess eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $mess eq "ARRAY") 0 0 0
if (ref $mess eq "ARRAY") 0 0 0
75 0 ( $mess, @args ) = ( @$mess, @args );
76 }
77  
78 0 return $self->$name(
79 literal( $self->form->localize( $mess, @args ) ) );
80 3187 };
81  
82 3187 Class::MOP::Method->wrap(
83 body => $loc_sub,
84 name => "${name}_loc",
85 package_name => $class,
86 );
87  
88 # add shortcuts
89 3187 my $short = $name;
90 3187 ▶ if ( $short =~ s/attributes$/attrs/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($short =~ s/attributes$/attrs/) 3073 114 3187
91  
92 3073 my $method = Class::MOP::Method->wrap(
93 body => $sub,
94 name => $short,
95 package_name => $class,
96 );
97  
98 3073 my $xml_method = Class::MOP::Method->wrap(
99 body => $xml_sub,
100 name => "${short}_xml",
101 package_name => $class,
102 );
103  
104 3073 my $loc_method = Class::MOP::Method->wrap(
105 body => $loc_sub,
106 name => "${short}_loc",
107 package_name => $class,
108 );
109  
110 3073 $class->meta->add_method( $short, $method );
111 3073 $class->meta->add_method( "${short}_xml", $xml_method );
112 3073 $class->meta->add_method( "${short}_loc", $loc_method );
113 }
114 }
115  
116 1451 mk_add_attrs( $class, @names );
117 1451 mk_del_attrs( $class, @names );
118  
119 1451 return;
120 }
121  
122 1688 ▶sub mk_attr_accessors {
Subroutine mk_attr_accessors: called CC=3 SCAR=12.7
Pod undocumented
123 1688 my ( $self, @names ) = @_;
124  
125 1688 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
016880
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
126  
127 1688 for my $name (@names) {
128 1250 ▶ my $sub = sub {
Subroutine enctype: called CC=2 SCAR=7.6
Subroutine __ANON__: not called CC=2 SCAR=7.6
129 0 my ( $self, $attr ) = @_;
130  
131 0 ▶ return $self->attributes->{$name} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 665 585 1250
132  
133 0 $self->attributes->{$name} = $attr;
134  
135 585 return $self;
136 5072 };
137  
138 5072 my $method = Class::MOP::Method->wrap(
139 body => $sub,
140 name => $name,
141 package_name => $class,
142 );
143  
144 0 ▶ my $xml_sub = sub {
Subroutine id_xml: not called CC=1 SCAR=6.9
145 0 my ( $self, $value ) = @_;
146  
147 0 return $self->attributes->{$name} = literal $value;
148 5072 };
149  
150 5072 my $xml_method = Class::MOP::Method->wrap(
151 body => $xml_sub,
152 name => "${name}_xml",
153 package_name => $class,
154 );
155  
156 0 ▶ my $loc_sub = sub {
Subroutine method_loc: not called CC=2 SCAR=17.9
157 0 my ( $self, $mess, @args ) = @_;
158  
159 0 ▶ if ( ref $mess eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mess eq "ARRAY") 0 0 0
160 0 ( $mess, @args ) = ( @$mess, @args );
161 }
162  
163 0 return $self->attributes->{$name}
164 = literal( $self->form->localize( $mess, @args ) );
165 5072 };
166  
167 5072 my $loc_method = Class::MOP::Method->wrap(
168 body => $loc_sub,
169 name => "${name}_loc",
170 package_name => $class,
171 );
172  
173 5072 $class->meta->add_method( $name, $method );
174 5072 $class->meta->add_method( "${name}_xml", $xml_method );
175 5072 $class->meta->add_method( "${name}_loc", $loc_method );
176 }
177  
178 1688 return;
179 }
180  
181 1451 ▶sub mk_add_attrs {
Subroutine mk_add_attrs: called CC=4 SCAR=14.8
Pod undocumented
182 1451 my ( $self, @names ) = @_;
183  
184 1451 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
014510
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
185  
186 1451 for my $name (@names) {
187 3 ▶ my $sub = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
188 3 my ( $self, $attrs ) = @_;
189  
190 3 ▶ while ( my ( $key, $value ) = each %$attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attrs) 3 3 6
191 3 append_xml_attribute( $self->{$name}, $key, $value );
192 }
193 3 return $self;
194 3187 };
195  
196 3187 my $method = Class::MOP::Method->wrap(
197 body => $sub,
198 name => "add_$name",
199 package_name => $class,
200 );
201  
202 0 ▶ my $xml_sub = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
203 0 my ( $self, $attrs ) = @_;
204  
205 0 my $method = "add_$name";
206  
207 return $self->$method(
208 0 { map { $_, literal( $attrs->{$_} ) }
209 keys %$attrs
210 } );
211 3187 };
212  
213 3187 my $xml_method = Class::MOP::Method->wrap(
214 body => $xml_sub,
215 name => "add_${name}_xml",
216 package_name => $class,
217 );
218  
219 0 ▶ my $loc_sub = sub {
Subroutine add_attributes_loc: not called CC=2 SCAR=17.9
220 0 my ( $self, $mess, @args ) = @_;
221  
222 0 ▶ if ( ref $mess eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mess eq "ARRAY") 0 0 0
223 0 ( $mess, @args ) = ( @$mess, @args );
224 }
225  
226 0 return $self->$method(
227 literal( $self->form->localize( $mess, @args ) ) );
228 3187 };
229  
230 3187 my $loc_method = Class::MOP::Method->wrap(
231 body => $loc_sub,
232 name => "add_${name}_loc",
233 package_name => $class,
234 );
235  
236 3187 $class->meta->add_method( "add_$name", $method );
237 3187 $class->meta->add_method( "add_${name}_xml", $xml_method );
238 3187 $class->meta->add_method( "add_${name}_loc", $loc_method );
239  
240 # add shortcuts
241 3187 my $short = $name;
242 3187 ▶ if ( $short =~ s/attributes$/attrs/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($short =~ s/attributes$/attrs/) 3073 114 3187
243  
244 3073 my $method = Class::MOP::Method->wrap(
245 body => $sub,
246 name => "add_$short",
247 package_name => $class,
248 );
249  
250 3073 my $xml_method = Class::MOP::Method->wrap(
251 body => $xml_sub,
252 name => "add_${short}_xml",
253 package_name => $class,
254 );
255  
256 3073 my $loc_method = Class::MOP::Method->wrap(
257 body => $loc_sub,
258 name => "add_${short}_loc",
259 package_name => $class,
260 );
261  
262 3073 $class->meta->add_method( "add_$short", $method );
263 3073 $class->meta->add_method( "add_${short}_xml", $xml_method );
264 3073 $class->meta->add_method( "add_${short}_loc", $loc_method );
265 }
266 }
267  
268 1451 return;
269 }
270  
271 1451 ▶sub mk_del_attrs {
Subroutine mk_del_attrs: called CC=4 SCAR=16.6
Pod undocumented
272 1451 my ( $self, @names ) = @_;
273  
274 1451 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
014510
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
275  
276 1451 for my $name (@names) {
277 0 ▶ my $sub = sub {
Subroutine del_attributes: not called CC=2 SCAR=17.9
278 0 my ( $self, $attrs ) = @_;
279  
280 0 ▶ while ( my ( $key, $value ) = each %$attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attrs) 0 0 0
281 0 remove_xml_attribute( $self->{$name}, $key, $value );
282 }
283 0 return $self;
284 3187 };
285  
286 3187 my $method = Class::MOP::Method->wrap(
287 body => $sub,
288 name => "del_$name",
289 package_name => $class,
290 );
291  
292 0 ▶ my $xml_sub = sub {
Subroutine del_attributes_xml: not called CC=1 SCAR=6.9
293 0 my ( $self, $attrs ) = @_;
294  
295 0 my $method = "del_$name";
296  
297 return $self->$method(
298 0 { map { $_, literal( $attrs->{$_} ) }
299 keys %$attrs
300 } );
301 3187 };
302  
303 3187 my $xml_method = Class::MOP::Method->wrap(
304 body => $xml_sub,
305 name => "del_${name}_xml",
306 package_name => $class,
307 );
308  
309 0 ▶ my $loc_sub = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
310 0 my ( $self, $mess, @args ) = @_;
311  
312 0 ▶ if ( ref $mess eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mess eq "ARRAY") 0 0 0
313 0 ( $mess, @args ) = ( @$mess, @args );
314 }
315  
316 0 return $self->$method(
317 literal( $self->form->localize( $mess, @args ) ) );
318 3187 };
319  
320 3187 my $loc_method = Class::MOP::Method->wrap(
321 body => $loc_sub,
322 name => "del_${name}_loc",
323 package_name => $class,
324 );
325  
326 3187 $class->meta->add_method( "del_$name", $method );
327 3187 $class->meta->add_method( "del_${name}_xml", $xml_method );
328 3187 $class->meta->add_method( "del_${name}_loc", $loc_method );
329  
330 # add shortcuts
331 3187 my $short = $name;
332 3187 ▶ if ( $short =~ s/attributes$/attrs/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($short =~ s/attributes$/attrs/) 3073 114 3187
333  
334 3073 my $method = Class::MOP::Method->wrap(
335 body => $sub,
336 name => "del_$short",
337 package_name => $class,
338 );
339  
340 3073 my $xml_method = Class::MOP::Method->wrap(
341 body => $xml_sub,
342 name => "del_${short}_xml",
343 package_name => $class,
344 );
345  
346 3073 my $loc_method = Class::MOP::Method->wrap(
347 body => $loc_sub,
348 name => "del_${short}_loc",
349 package_name => $class,
350 );
351  
352 3073 $class->meta->add_method( "del_$short", $method );
353 3073 $class->meta->add_method( "del_${short}_xml", $xml_method );
354 3073 $class->meta->add_method( "del_${short}_loc", $loc_method );
355 }
356 }
357  
358 1451 return;
359 }
360  
361 1810 ▶sub mk_inherited_accessors {
Subroutine mk_inherited_accessors: called CC=3 SCAR=11.3
Pod undocumented
362 1810 my ( $self, @names ) = @_;
363  
364 1810 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
018100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
365  
366 1810 for my $name (@names) {
367 11139 ▶ my $sub = sub {
Subroutine repeatable_count: called CC=4 SCAR=13.9
368 11139 my ( $self, $value ) = @_;
369  
370 11139 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1206 9933 11139
371 1206 $self->{$name} = $value;
372 1206 return $self;
373 }
374  
375 # micro optimization! this method's called a lot, so access
376 # parent hashkey directly, instead of calling parent()
377 9933 ▶ while ( defined( my $parent = $self->{parent} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $parent = $self->{"parent"}) and not defined $self->{$name}) 18789 9933 28722
Condition100%6/6
defined(my $parent = $self->{"parent"}) and not defined $self->{$name}
!ll&&!rl&&r
98478618789
defined(my $parent = $self->{"parent"}) and not defined $self->{$name}
!ll&&!rl&&r
59914411346
MC/DC100%2/2
defined(my $parent = $self->{"parent"}) and not defined $self->{$name}
defined(my $parent = $self->{"parent"}) not defined $self->{$name}
MC/DC100%2/2
defined(my $parent = $self->{"parent"}) and not defined $self->{$name}
defined(my $parent = $self->{"parent"}) not defined $self->{$name}
Truth table100%3/3
A and not(B)
A= defined(my $parent = $self->{"parent"})B= not defined $self->{$name}
ABresult
0X0
100
111
Truth table100%3/3
A and not(B)
A= defined(my $parent = $self->{"parent"})B= not defined $self->{$name}
ABresult
0X0
100
111
378 && !defined $self->{$name} )
379 {
380 18789 $self = $parent;
381 }
382 9933 return $self->{$name};
383 13300 };
384  
385 0 ▶ my $no_inherit_sub = sub {
Subroutine auto_container_error_class_no_inherit: not called CC=2 SCAR=17.9
386 0 my ( $self ) = @_;
387  
388 0 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
389 0 croak "Cannot call ${name}_no_inherit as a setter";
390 }
391  
392 0 return $self->{$name};
393 13300 };
394  
395 13300 my $method = Class::MOP::Method->wrap(
396 body => $sub,
397 name => $name,
398 package_name => $class,
399 );
400  
401 13300 my $no_inherit_method = Class::MOP::Method->wrap(
402 body => $no_inherit_sub,
403 name => "${name}_no_inherit",
404 package_name => $class,
405 );
406  
407 13300 $class->meta->add_method( $name, $method );
408 13300 $class->meta->add_method( "${name}_no_inherit", $no_inherit_method );
409 }
410  
411 1810 return;
412 }
413  
414 441 ▶sub mk_inherited_merging_accessors {
Subroutine mk_inherited_merging_accessors: called CC=3 SCAR=12.7
Pod undocumented
415 441 my ( $self, @names ) = @_;
416  
417 441 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
04410
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
418  
419 441 $class->mk_inherited_accessors(@names);
420  
421 441 for my $name (@names) {
422 1 ▶ my $sub = sub {
Subroutine add_tt_args: called CC=5 SCAR=21.6
423 1 my ( $self, $attrs ) = @_;
424  
425 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
426 1 ▶ while ( my ( $key, $value ) = each %$attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attrs) 1 1 2
427 1 append_xml_attribute( $self->{$name}, $key, $value );
428 }
429 1 return $self;
430 }
431  
432 # micro optimization! this method's called a lot, so access
433 # parent hashkey directly, instead of calling parent()
434 0 ▶ while ( defined( my $parent = $self->{parent} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $parent = $self->{"parent"}) and not defined $self->{$name}) 0 0 0
Condition0%0/3
defined(my $parent = $self->{"parent"}) and not defined $self->{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined(my $parent = $self->{"parent"}) and not defined $self->{$name}
defined(my $parent = $self->{"parent"}) not defined $self->{$name}
Truth table0%0/3
A and not(B)
A= defined(my $parent = $self->{"parent"})B= not defined $self->{$name}
ABresult
0X0
100
111
435 && !defined $self->{$name} )
436 {
437 0 $self = $parent;
438 }
439 0 return $self->{$name};
440 882 };
441  
442 882 my $method = Class::MOP::Method->wrap(
443 body => $sub,
444 name => "add_$name",
445 package_name => $class,
446 );
447  
448 882 $class->meta->add_method( "add_$name", $method );
449 }
450  
451 441 return;
452 }
453  
454 1675 ▶sub mk_output_accessors {
Subroutine mk_output_accessors: called CC=3 SCAR=11.0
Pod undocumented
455 1675 my ( $self, @names ) = @_;
456  
457 1675 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
016750
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
458  
459 1675 for my $name (@names) {
460 9234 ▶ my $sub = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
461 9234 my ( $self, $value ) = @_;
462 9234 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 797 8437 9234
463 797 $self->{$name} = $value;
464 797 return $self;
465 }
466 8437 return $self->{$name};
467 2505 };
468  
469 2505 my $method = Class::MOP::Method->wrap(
470 body => $sub,
471 name => $name,
472 package_name => $class,
473 );
474  
475 6 ▶ my $xml_sub = sub {
Subroutine form_error_message_xml: called CC=1 SCAR=0.0
476 6 my ( $self, $arg ) = @_;
477  
478 6 return $self->$name( literal($arg) );
479 2505 };
480  
481 2505 my $xml_method = Class::MOP::Method->wrap(
482 body => $xml_sub,
483 name => "${name}_xml",
484 package_name => $class,
485 );
486  
487 13 ▶ my $loc_sub = sub {
Subroutine form_error_message_loc: called CC=2 SCAR=6.9
488 13 my ( $self, $mess, @args ) = @_;
489  
490 13 ▶ if ( ref $mess eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mess eq "ARRAY") 1 12 13
491 1 ( $mess, @args ) = ( @$mess, @args );
492 }
493  
494 13 return $self->$name(
495 literal( $self->form->localize( $mess, @args ) ) );
496 2505 };
497  
498 2505 my $loc_method = Class::MOP::Method->wrap(
499 body => $loc_sub,
500 name => "${name}_loc",
501 package_name => $class,
502 );
503  
504 2505 $class->meta->add_method( $name, $method );
505 2505 $class->meta->add_method( "${name}_xml", $xml_method );
506 2505 $class->meta->add_method( "${name}_loc", $loc_method );
507 }
508  
509 1675 return;
510 }
511  
512 342 ▶sub mk_attr_bool_accessors {
Subroutine mk_attr_bool_accessors: called CC=3 SCAR=17.9
Pod undocumented
513 342 my ( $self, @names ) = @_;
514  
515 342 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
03420
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
516  
517 342 for my $name (@names) {
518 0 ▶ my $sub = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
519 0 my ( $self, $attr ) = @_;
520  
521 0 ▶ if ( @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
522  
523 # Getter
524 return undef ## no critic (ProhibitExplicitReturnUndef);
525 0 ▶ if !exists $self->attributes->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->attributes->{$name} 0 0 0
526  
527 return $self->attributes->{$name}
528 0 ▶ ? $self->attributes->{$name}
Branch: 1 branch
BranchTrueFalseTotal
$self->attributes->{$name} ? : 0 0 0
529 : undef;
530 }
531  
532 # Any true value sets a bool attribute, e.g.
533 # required="required"
534 # Any false value deletes the attribute
535  
536 0 ▶ if ($attr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr) { } 0 0 0
537 0 $self->attributes->{$name} = $name;
538 }
539 else {
540 0 delete $self->attributes->{$name};
541 }
542  
543 0 return $self;
544 1026 };
545  
546 1026 my $method = Class::MOP::Method->wrap(
547 body => $sub,
548 name => $name,
549 package_name => $class,
550 );
551  
552 1026 $class->meta->add_method( $name, $method );
553 }
554  
555 342 return;
556 }
557  
558 518 1;
559  
560 __END__
« lib/HTML/FormFu/Role/Element/Input.pm ↑ Summary lib/HTML/FormFu/Element.pm »