SyForm/Util/HTML.pm

filter: Statementstmt 100% 50 / 50 Branchbran 83.3% 10 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 4 totaltotal 92.2% 71 / 77 CC 11 SCAR 10.1
CC
11
Cov
97%
get_html_attr
4.1
_add_or_put_html_attr
4.0
set_html_attr
3.0
CRAP 2.7
« SyForm/ViewField.pm ↑ Summary SyForm/ViewRole/Bootstrap.pm »
1 package SyForm::Util::HTML;
2 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 $SyForm::Util::HTML::AUTHORITY = 'cpan:GETTY';
4 }
5 2 $SyForm::Util::HTML::VERSION = '0.103';
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Clone 'clone';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our @EXPORT = qw(
12  
13 add_html_attr
14 put_html_attr
15 set_html_attr
16 get_html_attr
17  
18 );
19  
20 1 ▶sub add_html_attr {
Subroutine add_html_attr: called CC=1 SCAR=0.0
Pod undocumented
21 1 my ( $html_declare, %attrs ) = @_;
22 1 return _add_or_put_html_attr($html_declare,0,%attrs);
23 }
24  
25 1 ▶sub put_html_attr {
Subroutine put_html_attr: called CC=1 SCAR=0.0
Pod undocumented
26 1 my ( $html_declare, %attrs ) = @_;
27 1 return _add_or_put_html_attr($html_declare,1,%attrs);
28 }
29  
30 2 ▶sub _add_or_put_html_attr {
Subroutine _add_or_put_html_attr: called CC=4 SCAR=13.9
31 2 my ( $html_declare, $add_put, %attrs ) = @_;
32 2 my $clone = clone($html_declare);
33 2 for my $key (keys %attrs) {
34 4 my $current = _get_html_attr($clone,$key);
35 4 ▶ if ($current) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current) { } 2 2 4
36 my $new = join(" ",$add_put
37 ? ( $attrs{$key},$current->[1] )
38 2 ▶ : ( $current->[1],$attrs{$key} )
Branch: 1 branch
BranchTrueFalseTotal
$add_put ? : 1 1 2
39 );
40 2 $current->[1] = $new;
41 } else {
42 $clone->attributes([
43 2 @{$clone->attributes},
44 2 [ $key, $attrs{$key} ],
45 ]);
46 }
47 }
48 2 return $clone;
49 }
50  
51 1 ▶sub set_html_attr {
Subroutine set_html_attr: called CC=3 SCAR=11.0
Pod undocumented
52 1 my ( $html_declare, %attrs ) = @_;
53 1 my $clone = clone($html_declare);
54 1 for my $key (keys %attrs) {
55 2 my $current = _get_html_attr($clone,$key);
56 2 ▶ if ($current) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current) { } 1 1 2
57 1 $current->[1] = $attrs{$key};
58 } else {
59 $clone->attributes([
60 1 @{$clone->attributes},
61 1 [ $key, $attrs{$key} ],
62 ]);
63 }
64 }
65 1 return $clone;
66 }
67  
68 7 ▶sub get_html_attr {
Subroutine get_html_attr: called CC=4 SCAR=14.2
Pod undocumented
69 7 my ( $html_declare, @attrs ) = @_;
70 7 my @values;
71 7 for my $key (@attrs) {
72 7 my $attr = _get_html_attr($html_declare, $key);
73 7 ▶ push @values, defined $attr ? $attr->[1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $attr ? : 7 0 7
74 }
75 7 ▶ return wantarray ? @values : $values[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 7 7
76 }
77  
78 13 ▶sub _get_html_attr {
Subroutine _get_html_attr: called CC=3 SCAR=11.0
79 13 my ( $html_declare, $key ) = @_;
80 13 for my $attr (@{$html_declare->attributes}) {
81 16 ▶ return $attr if $attr->[0] eq $key;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->[0] eq $key 10 6 16
82 }
83 3 return undef;
84 }
85  
86 2 1;
87  
88 __END__
« SyForm/ViewField.pm ↑ Summary SyForm/ViewRole/Bootstrap.pm »