lib/HTML/FormFu/Attribute.pm

filter: Statementstmt 80.6% 192 / 238 Branchbran 58.6% 34 / 58 Conditioncond 42.4% 14 / 33 MC/DCmcdc 18.1% 4 / 22 Subroutinesub 72.2% 26 / 36 Podpod 0.0% 0 / 8 totaltotal 68.3% 270 / 395 SCAR 77.1
CC
311
Cov
73%
__ANON__
30.0
autofocus
30.0
multiple
30.0
CRAP 2225.7
↑ Summary lib/HTML/FormFu/Role/Element/Field.pm »
1 404 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Attribute;
4 404 $HTML::FormFu::Attribute::VERSION = '2.06';
5 # ABSTRACT: accessor class
6  
7 404 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 404 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 404 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 404 ▶use Class::MOP::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 404 use HTML::FormFu::Util qw(
13 append_xml_attribute remove_xml_attribute literal
14 404 ▶ _parse_args );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 404 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 sub mk_attrs {
24 1321 ▶ my ( $self, @names ) = @_;
Subroutine mk_attrs: called CC=4 SCAR=14.7
Pod undocumented
25  
26 1321 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
013210
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 1321 for my $name (@names) {
29 my $sub = sub {
30 1891 ▶ my ( $self, $attrs ) = @_;
Subroutine label_attributes: called CC=4 SCAR=13.9
Subroutine attributes: called CC=4 SCAR=13.9
31  
32 1891 ▶ if ( !exists $self->{$name} ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $self->{$name}) 712 1179 1891
unless (exists $self->{$name}) 8547 18874 27421
33 712 $self->{$name} = {};
34 }
35  
36 1891 ▶ return $self->{$name} if @_ == 1;
Branch: 2 branches
BranchTrueFalseTotal
if @_ == 1 843 1048 1891
if @_ == 1 19672 15865 35537
37  
38 1048 my $attr_slot = $self->{$name};
39  
40 1048 ▶ while ( my ( $key, $value ) = each %$attrs ) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = each %$attrs) 7 1048 1055
if (() = each %$attrs) 350 10712 11062
41 7 $attr_slot->{$key} = $value;
42 }
43  
44 1048 return $self;
45 2917 };
46  
47 2917 my $method = Class::MOP::Method->wrap(
48 body => $sub,
49 name => $name,
50 package_name => $class,
51 );
52  
53 my $xml_sub = sub {
54 0 ▶ my ( $self, $attrs ) = @_;
Subroutine second_xml: not called CC=1 SCAR=6.9
Subroutine error_attributes_xml: not called CC=1 SCAR=6.9
55  
56 return $self->$name(
57 0 { map { $_, literal( $attrs->{$_} ) }
58 keys %$attrs
59 } );
60 2917 };
61  
62 2917 my $xml_method = Class::MOP::Method->wrap(
63 body => $xml_sub,
64 name => "${name}_xml",
65 package_name => $class,
66 );
67  
68 2917 $class->meta->add_method( $name, $method );
69 2917 $class->meta->add_method( "${name}_xml", $xml_method );
70  
71 my $loc_sub = sub {
72 0 ▶ my ( $self, $mess, @args ) = @_;
Subroutine attrs_loc: not called CC=2 SCAR=17.9
Subroutine __ANON__: not called CC=2 SCAR=17.9
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 2917 };
81  
82 2917 my $loc_method = Class::MOP::Method->wrap(
83 body => $loc_sub,
84 name => "${name}_loc",
85 package_name => $class,
86 );
87  
88 # add shortcuts
89 2917 my $short = $name;
90 2917 ▶ if ( $short =~ s/attributes$/attrs/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($short =~ s/attributes$/attrs/) 2821 96 2917
91  
92 2821 my $method = Class::MOP::Method->wrap(
93 body => $sub,
94 name => $short,
95 package_name => $class,
96 );
97  
98 2821 my $xml_method = Class::MOP::Method->wrap(
99 body => $xml_sub,
100 name => "${short}_xml",
101 package_name => $class,
102 );
103  
104 2821 my $loc_method = Class::MOP::Method->wrap(
105 body => $loc_sub,
106 name => "${short}_loc",
107 package_name => $class,
108 );
109  
110 2821 $class->meta->add_method( $short, $method );
111 2821 $class->meta->add_method( "${short}_xml", $xml_method );
112 2821 $class->meta->add_method( "${short}_loc", $loc_method );
113 }
114 }
115  
116 1321 mk_add_attrs( $class, @names );
117 1321 mk_del_attrs( $class, @names );
118  
119 1321 return;
120 }
121  
122 sub mk_attr_accessors {
123 1579 ▶ my ( $self, @names ) = @_;
Subroutine mk_attr_accessors: called CC=3 SCAR=11.1
Pod undocumented
124  
125 1579 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
015790
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 1579 for my $name (@names) {
128 my $sub = sub {
129 1649 ▶ my ( $self, $attr ) = @_;
Subroutine pattern: called CC=2 SCAR=6.9
130  
131 1649 ▶ return $self->attributes->{$name} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 846 803 1649
132  
133 803 $self->attributes->{$name} = $attr;
134  
135 803 return $self;
136 4805 };
137  
138 4805 my $method = Class::MOP::Method->wrap(
139 body => $sub,
140 name => $name,
141 package_name => $class,
142 );
143  
144 my $xml_sub = sub {
145 1 ▶ my ( $self, $value ) = @_;
Subroutine id_xml: called CC=1 SCAR=0.0
146  
147 1 return $self->attributes->{$name} = literal $value;
148 4805 };
149  
150 4805 my $xml_method = Class::MOP::Method->wrap(
151 body => $xml_sub,
152 name => "${name}_xml",
153 package_name => $class,
154 );
155  
156 my $loc_sub = sub {
157 1 ▶ my ( $self, $mess, @args ) = @_;
Subroutine id_loc: called CC=2 SCAR=7.6
158  
159 1 ▶ if ( ref $mess eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mess eq "ARRAY") 0 1 1
160 0 ( $mess, @args ) = ( @$mess, @args );
161 }
162  
163 1 return $self->attributes->{$name}
164 = literal( $self->form->localize( $mess, @args ) );
165 4805 };
166  
167 4805 my $loc_method = Class::MOP::Method->wrap(
168 body => $loc_sub,
169 name => "${name}_loc",
170 package_name => $class,
171 );
172  
173 4805 $class->meta->add_method( $name, $method );
174 4805 $class->meta->add_method( "${name}_xml", $xml_method );
175 4805 $class->meta->add_method( "${name}_loc", $loc_method );
176 }
177  
178 1579 return;
179 }
180  
181 sub mk_add_attrs {
182 1321 ▶ my ( $self, @names ) = @_;
Subroutine mk_add_attrs: called CC=4 SCAR=14.1
Pod undocumented
183  
184 1321 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
013210
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 1321 for my $name (@names) {
187 my $sub = sub {
188 4 ▶ my ( $self, $attrs ) = @_;
Subroutine add_attributes: called CC=2 SCAR=6.9
189  
190 4 ▶ while ( my ( $key, $value ) = each %$attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attrs) 4 4 8
191 4 append_xml_attribute( $self->{$name}, $key, $value );
192 }
193 4 return $self;
194 2917 };
195  
196 2917 my $method = Class::MOP::Method->wrap(
197 body => $sub,
198 name => "add_$name",
199 package_name => $class,
200 );
201  
202 my $xml_sub = sub {
203 1 ▶ my ( $self, $attrs ) = @_;
Subroutine add_legend_attributes_xml: called CC=1 SCAR=0.0
204  
205 1 my $method = "add_$name";
206  
207 return $self->$method(
208 1 { map { $_, literal( $attrs->{$_} ) }
209 keys %$attrs
210 } );
211 2917 };
212  
213 2917 my $xml_method = Class::MOP::Method->wrap(
214 body => $xml_sub,
215 name => "add_${name}_xml",
216 package_name => $class,
217 );
218  
219 my $loc_sub = sub {
220 0 ▶ my ( $self, $mess, @args ) = @_;
Subroutine add_attributes_loc: not called CC=2 SCAR=17.9
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 2917 };
229  
230 2917 my $loc_method = Class::MOP::Method->wrap(
231 body => $loc_sub,
232 name => "add_${name}_loc",
233 package_name => $class,
234 );
235  
236 2917 $class->meta->add_method( "add_$name", $method );
237 2917 $class->meta->add_method( "add_${name}_xml", $xml_method );
238 2917 $class->meta->add_method( "add_${name}_loc", $loc_method );
239  
240 # add shortcuts
241 2917 my $short = $name;
242 2917 ▶ if ( $short =~ s/attributes$/attrs/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($short =~ s/attributes$/attrs/) 2821 96 2917
243  
244 2821 my $method = Class::MOP::Method->wrap(
245 body => $sub,
246 name => "add_$short",
247 package_name => $class,
248 );
249  
250 2821 my $xml_method = Class::MOP::Method->wrap(
251 body => $xml_sub,
252 name => "add_${short}_xml",
253 package_name => $class,
254 );
255  
256 2821 my $loc_method = Class::MOP::Method->wrap(
257 body => $loc_sub,
258 name => "add_${short}_loc",
259 package_name => $class,
260 );
261  
262 2821 $class->meta->add_method( "add_$short", $method );
263 2821 $class->meta->add_method( "add_${short}_xml", $xml_method );
264 2821 $class->meta->add_method( "add_${short}_loc", $loc_method );
265 }
266 }
267  
268 1321 return;
269 }
270  
271 sub mk_del_attrs {
272 1321 ▶ my ( $self, @names ) = @_;
Subroutine mk_del_attrs: called CC=4 SCAR=16.6
Pod undocumented
273  
274 1321 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
013210
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 1321 for my $name (@names) {
277 my $sub = sub {
278 0 ▶ my ( $self, $attrs ) = @_;
Subroutine del_legend_attributes: not called CC=2 SCAR=17.9
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 2917 };
285  
286 2917 my $method = Class::MOP::Method->wrap(
287 body => $sub,
288 name => "del_$name",
289 package_name => $class,
290 );
291  
292 my $xml_sub = sub {
293 0 ▶ my ( $self, $attrs ) = @_;
Subroutine del_second_xml: not called CC=1 SCAR=6.9
294  
295 0 my $method = "del_$name";
296  
297 return $self->$method(
298 0 { map { $_, literal( $attrs->{$_} ) }
299 keys %$attrs
300 } );
301 2917 };
302  
303 2917 my $xml_method = Class::MOP::Method->wrap(
304 body => $xml_sub,
305 name => "del_${name}_xml",
306 package_name => $class,
307 );
308  
309 my $loc_sub = sub {
310 0 ▶ my ( $self, $mess, @args ) = @_;
Subroutine del_legend_attributes_loc: not called CC=2 SCAR=17.9
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 2917 };
319  
320 2917 my $loc_method = Class::MOP::Method->wrap(
321 body => $loc_sub,
322 name => "del_${name}_loc",
323 package_name => $class,
324 );
325  
326 2917 $class->meta->add_method( "del_$name", $method );
327 2917 $class->meta->add_method( "del_${name}_xml", $xml_method );
328 2917 $class->meta->add_method( "del_${name}_loc", $loc_method );
329  
330 # add shortcuts
331 2917 my $short = $name;
332 2917 ▶ if ( $short =~ s/attributes$/attrs/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($short =~ s/attributes$/attrs/) 2821 96 2917
333  
334 2821 my $method = Class::MOP::Method->wrap(
335 body => $sub,
336 name => "del_$short",
337 package_name => $class,
338 );
339  
340 2821 my $xml_method = Class::MOP::Method->wrap(
341 body => $xml_sub,
342 name => "del_${short}_xml",
343 package_name => $class,
344 );
345  
346 2821 my $loc_method = Class::MOP::Method->wrap(
347 body => $loc_sub,
348 name => "del_${short}_loc",
349 package_name => $class,
350 );
351  
352 2821 $class->meta->add_method( "del_$short", $method );
353 2821 $class->meta->add_method( "del_${short}_xml", $xml_method );
354 2821 $class->meta->add_method( "del_${short}_loc", $loc_method );
355 }
356 }
357  
358 1321 return;
359 }
360  
361 sub mk_inherited_accessors {
362 1637 ▶ my ( $self, @names ) = @_;
Subroutine mk_inherited_accessors: called CC=3 SCAR=11.3
Pod undocumented
363  
364 1637 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
016370
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 1637 for my $name (@names) {
367 my $sub = sub {
368 11490 ▶ my ( $self, $value ) = @_;
Subroutine auto_container_per_error_class: called CC=4 SCAR=13.9
369  
370 11490 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 1122 10368 11490
371 1122 $self->{$name} = $value;
372 1122 return $self;
373 }
374  
375 # micro optimization! this method's called a lot, so access
376 # parent hashkey directly, instead of calling parent()
377 10368 ▶ while ( defined( my $parent = $self->{parent} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $parent = $self->{"parent"}) and not defined $self->{$name}) 19853 10368 30221
Condition100%6/6
defined(my $parent = $self->{"parent"}) and not defined $self->{$name}
!ll&&!rl&&r
103105819853
defined(my $parent = $self->{"parent"}) and not defined $self->{$name}
!ll&&!rl&&r
5081729776
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 19853 $self = $parent;
381 }
382 10368 return $self->{$name};
383 12115 };
384  
385 my $no_inherit_sub = sub {
386 0 ▶ my ( $self, $value ) = @_;
Subroutine config_callback_no_inherit: not called CC=2 SCAR=17.9
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 12115 };
394  
395 12115 my $method = Class::MOP::Method->wrap(
396 body => $sub,
397 name => $name,
398 package_name => $class,
399 );
400  
401 12115 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 12115 $class->meta->add_method( $name, $method );
408 12115 $class->meta->add_method( "${name}_no_inherit", $no_inherit_method );
409 }
410  
411 1637 return;
412 }
413  
414 sub mk_inherited_merging_accessors {
415 403 ▶ my ( $self, @names ) = @_;
Subroutine mk_inherited_merging_accessors: called CC=3 SCAR=12.7
Pod undocumented
416  
417 403 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
04030
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 403 $class->mk_inherited_accessors(@names);
420  
421 403 for my $name (@names) {
422 my $sub = sub {
423 1 ▶ my ( $self, $attrs ) = @_;
Subroutine add_tt_args: called CC=5 SCAR=21.6
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 806 };
441  
442 806 my $method = Class::MOP::Method->wrap(
443 body => $sub,
444 name => "add_$name",
445 package_name => $class,
446 );
447  
448 806 $class->meta->add_method( "add_$name", $method );
449 }
450  
451 403 return;
452 }
453  
454 sub mk_output_accessors {
455 1557 ▶ my ( $self, @names ) = @_;
Subroutine mk_output_accessors: called CC=3 SCAR=11.0
Pod undocumented
456  
457 1557 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
015570
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 1557 for my $name (@names) {
460 my $sub = sub {
461 7966 ▶ my ( $self, $value ) = @_;
Subroutine content: called CC=2 SCAR=6.9
462 7966 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 688 7278 7966
463 688 $self->{$name} = $value;
464 688 return $self;
465 }
466 7278 return $self->{$name};
467 2323 };
468  
469 2323 my $method = Class::MOP::Method->wrap(
470 body => $sub,
471 name => $name,
472 package_name => $class,
473 );
474  
475 my $xml_sub = sub {
476 6 ▶ my ( $self, $arg ) = @_;
Subroutine content_xml: called CC=1 SCAR=0.0
477  
478 6 return $self->$name( literal($arg) );
479 2323 };
480  
481 2323 my $xml_method = Class::MOP::Method->wrap(
482 body => $xml_sub,
483 name => "${name}_xml",
484 package_name => $class,
485 );
486  
487 my $loc_sub = sub {
488 13 ▶ my ( $self, $mess, @args ) = @_;
Subroutine default_loc: called CC=2 SCAR=6.9
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 2323 };
497  
498 2323 my $loc_method = Class::MOP::Method->wrap(
499 body => $loc_sub,
500 name => "${name}_loc",
501 package_name => $class,
502 );
503  
504 2323 $class->meta->add_method( $name, $method );
505 2323 $class->meta->add_method( "${name}_xml", $xml_method );
506 2323 $class->meta->add_method( "${name}_loc", $loc_method );
507 }
508  
509 1557 return;
510 }
511  
512 sub mk_attr_bool_accessors {
513 322 ▶ my ( $self, @names ) = @_;
Subroutine mk_attr_bool_accessors: called CC=3 SCAR=17.9
Pod undocumented
514  
515 322 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
03220
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 322 for my $name (@names) {
518 my $sub = sub {
519 0 ▶ my ( $self, $attr ) = @_;
Subroutine multiple: not called CC=5 SCAR=34.0
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 966 };
545  
546 966 my $method = Class::MOP::Method->wrap(
547 body => $sub,
548 name => $name,
549 package_name => $class,
550 );
551  
552 966 $class->meta->add_method( $name, $method );
553 }
554  
555 322 return;
556 }
557  
558 404 1;
559  
560 __END__
561  
562 =pod
563  
564 =encoding UTF-8
565  
566 =head1 NAME
567  
568 HTML::FormFu::Attribute - accessor class
569  
570 =head1 VERSION
571  
572 version 2.06
573  
574 =head1 SYNOPSIS
575  
576 =head1 DESCRIPTION
577  
578 =head1 METHODS
579  
580 =head1 AUTHOR
581  
582 Carl Franks, C<cfranks@cpan.org>
583  
584 Based on the original source code of L<HTML::Widget::Accessor>, by
585 Sebastian Riedel, C<sri@oook.de>.
586  
587 =head1 LICENSE
588  
589 This library is free software, you can redistribute it and/or modify it under
590 the same terms as Perl itself.
591  
592 =head1 AUTHOR
593  
594 Carl Franks <cpan@fireartist.com>
595  
596 =head1 COPYRIGHT AND LICENSE
597  
598 This software is copyright (c) 2018 by Carl Franks.
599  
600 This is free software; you can redistribute it and/or modify it under
601 the same terms as the Perl 5 programming language system itself.
602  
603 =cut
↑ Summary lib/HTML/FormFu/Role/Element/Field.pm »