| 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
Condition100%6/6
not ref $attributes or ref $attributes ne "HASH" and ref $attributes ne "ARRAY"
ref $attributes ne "HASH" and ref $attributes ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 98 | ▶ | if (defined $attributes) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $atom and ref $atom eq "CODE"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||