blib/lib/Fern.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 87.5% 14 / 16 Conditioncond 88.8% 8 / 9 MC/DCmcdc 80.0% 4 / 5 Subroutinesub 100% 15 / 15 Podpod 100% 4 / 4 totaltotal 95.1% 98 / 103 CC 12 SCAR 8.8
CC
12
Cov
95%
_parse_attributes_and_content
5.0
render_tag_and_metadata
3.0
__ANON__
2.1
CRAP 2.4
↑ Summary
1 package Fern;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our @EXPORT = qw(tag empty_element_tag render_tag render_tag_and_metadata);
6  
7 110 ▶sub _parse_attributes_and_content {
Subroutine _parse_attributes_and_content: called CC=5 SCAR=16.1
8 110 my $attributes = shift;
9 110 my @content = @_;
10  
11 110 ▶ if (!ref($attributes) || (ref($attributes) ne 'HASH' && ref($attributes) ne 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $attributes or ref $attributes ne "HASH" and ref $attributes ne "ARRAY") 98 12 110
Condition100%6/6
not ref $attributes or ref $attributes ne "HASH" and ref $attributes ne "ARRAY"
l!l&&r!l&&!r
90812
ref $attributes ne "HASH" and ref $attributes ne "ARRAY"
!ll&&!rl&&r
1118
MC/DC100%3/3
not ref $attributes or ref $attributes ne "HASH" and ref $attributes ne "ARRAY"
not ref $attributes ref $attributes ne "HASH" ref $attributes ne "ARRAY"
Truth table100%4/4
not(A) or B and C
A= not ref $attributesB= ref $attributes ne "HASH"C= ref $attributes ne "ARRAY"
ABCresult
1XX1
0111
00X0
0100
12 98 ▶ if (defined $attributes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attributes) 16 82 98
13 16 unshift @content, $attributes;
14 }
15 98 $attributes = {};
16 }
17  
18 110 return ($attributes, @content);
19 }
20  
21 142 ▶sub render_tag_and_metadata {
Subroutine render_tag_and_metadata: called CC=3 SCAR=11.1
Pod documented
22 142 my ($atom, @params) = @_;
23 142 ▶ return ref($atom) && ref($atom) eq 'CODE' ? ($atom->(@params)) : ($atom);
Branch: 1 branch
BranchTrueFalseTotal
ref $atom && ref $atom eq 'CODE' ? : 111 31 142
Condition66%2/3
ref $atom and ref $atom eq "CODE"
!ll&&!rl&&r
310111
MC/DC50%1/2
ref $atom and ref $atom eq "CODE"
ref $atom ref $atom eq "CODE"
Truth table66%2/3
A and B
A= ref $atomB= ref $atom eq "CODE"
ABresult
0X0
100
111
24 }
25  
26 105 ▶sub render_tag {
Subroutine render_tag: called CC=1 SCAR=0.0
Pod documented
27 105 my ($atom, @params) = @_;
28 105 return (render_tag_and_metadata($atom, @params))[0];
29 }
30  
31 18 ▶sub _stringify_key_value_pair {
Subroutine _stringify_key_value_pair: called CC=1 SCAR=0.0
32 18 my ($key, $value, @params) = @_;
33 18 return $key . '="' . render_tag($value, @params) . '"';
34 }
35  
36 110 ▶sub _stringify_attribute_hash {
Subroutine _stringify_attribute_hash: called CC=2 SCAR=6.9
37 110 my ($attribute_hash, @params) = @_;
38 110 ▶ return '' if (!keys %$attribute_hash);
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$attribute_hash 99 11 110
39 11 return ' ' . join(' ', map { _stringify_key_value_pair($_, $attribute_hash->{$_}, @params) } keys %$attribute_hash);
40 }
41  
42 1 ▶sub _stringify_attribute_array {
Subroutine _stringify_attribute_array: called CC=2 SCAR=7.0
43 1 my ($attribute_array, @params) = @_;
44 1 ▶ return '' if !@$attribute_array;
Branch: 1 branch
BranchTrueFalseTotal
unless @$attribute_array 0 1 1
45 1 return ' ' . join(' ', map { _stringify_key_value_pair($attribute_array->[2 * $_], $attribute_array->[2 * $_ + 1], @params) } (0 .. @$attribute_array / 2 - 1));
46 }
47  
48 111 ▶sub _stringify_attributes {
Subroutine _stringify_attributes: called CC=2 SCAR=6.9
49 111 my ($attributes, @params) = @_;
50 111 ▶ if (ref($attributes) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attributes eq 'HASH') { } 110 1 111
51 110 return _stringify_attribute_hash($attributes, @params);
52 }
53 else {
54 1 return _stringify_attribute_array($attributes, @params);
55 }
56 }
57  
58 111 ▶sub _stringify_content {
Subroutine _stringify_content: called CC=2 SCAR=6.9
59 111 my ($content, @params) = @_;
60 111 my @all_content = map { [render_tag_and_metadata($_, @params)] } @$content;
61 return (
62 37 @all_content ? join('', map {$_->[0]} @all_content) : '',
63 111 ▶ map {@$_[1..$#$_]} @all_content,
Branch: 1 branch
BranchTrueFalseTotal
@all_content ? : 27 84 111
64 );
65 }
66  
67 5 ▶sub empty_element_tag {
Subroutine empty_element_tag: called CC=1 SCAR=0.1
Pod documented
68 5 my $tag_name = shift;
69 5 my ($attributes, @content) = _parse_attributes_and_content(@_);
70  
71 5 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
72 5 my ($stringified_content, @metadata) = _stringify_content(\@content, @_);
73 5 ▶ if ($stringified_content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stringified_content) { } 0 5 5
74 0 return +("<$tag_name" . _stringify_attributes($attributes, @_) . ">$stringified_content</$tag_name>", @metadata);
75 }
76 else {
77 5 return +("<$tag_name" . _stringify_attributes($attributes, @_) . " />", @metadata);
78 }
79 5 };
80 }
81  
82 105 ▶sub tag {
Subroutine tag: called CC=1 SCAR=0.0
Pod documented
83 105 my $tag_name = shift;
84 105 my ($attributes, @content) = _parse_attributes_and_content(@_);
85  
86 106 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
87 106 my ($stringified_content, @metadata) = _stringify_content(\@content, @_);
88 return +(
89 106 "<$tag_name" . _stringify_attributes($attributes, @_) . ">" .
90 $stringified_content .
91 "</$tag_name>",
92 @metadata
93 );
94 105 };
95 }
96  
97 1 1;
98  
99 __END__
↑ Summary