Syndication/Text.pm

filter: Statementstmt 63.4% 40 / 63 Branchbran 41.6% 10 / 24 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 4 / 4 Podpod 50.0% 1 / 2 totaltotal 58.4% 59 / 101 SCAR 34.7
CC
15
Cov
58%
body
29.2
init
4.6
BEGIN
1.0
CRAP 32.1
« Syndication/Object.pm ↑ Summary Syndication/Writer.pm »
1 package XML::Atom::Syndication::Text;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 11 ▶use base qw( XML::Atom::Syndication::Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 XML::Atom::Syndication::Text->mk_accessors('attribute', 'type');
7  
8 sub init {
9 50 ▶ my $text = shift;
Subroutine init: called CC=4 SCAR=15.2
Pod undocumented
10 50 ▶ my %param = @_ == 1 ? (Body => $_[0]) : @_; # escaped text is assumed.
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 50 50
11 50 $text->SUPER::init(%param);
12 50 my $e = $text->elem;
13 50 ▶ if ($param{Body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{"Body"}) 0 50 50
14 0 $text->body($param{Body});
15 }
16 50 ▶ if ($param{Type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{"Type"}) 0 50 50
17 0 $text->type($param{Type});
18 }
19 50 $text;
20 }
21  
22 sub body {
23 48 ▶ my $text = shift;
Subroutine body: called CC=12 SCAR=33.8
Pod documented
24 48 my $elem = $text->elem;
25 48 ▶ my $type = $elem->attributes->{'{}type'} || 'text';
Condition100%2/2
$elem->attributes->{'{}type'} || 'text'
l!l
3117
MC/DC100%1/1
$elem->attributes->{'{}type'} || 'text'
$elem->attributes->{'{}type'}
Truth table100%2/2
A
A= $elem->attributes->{'{}type'}
Aresult
11
00
26 48 ▶ if (@_) { # set
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 48 48
27 0 my $data = shift;
28 0 ▶ if ($type eq 'xhtml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'xhtml') { } 0 0 0
29 0 my $node = $data;
30 0 ▶ unless (ref $node) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node) 0 0 0
31 0 my $copy =
32 '<div xmlns="http://www.w3.org/1999/xhtml">' . $data
33 . '</div>';
34 0 eval {
35 0 require XML::Elemental;
36 0 my $parser = XML::Elemental->parser;
37 0 my $xml = $parser->parse_string($copy);
38 0 $node = $xml->contents->[0];
39 };
40 0 ▶ return $text->error(
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
41 "Error parsing content body string as XML: $@")
42 if $@;
43 }
44 0 $node->parent($elem);
45 0 $elem->contents([$node]);
46 } else { # is text or html
47 0 my $text = XML::Elemental::Characters->new;
48 0 $text->data($data);
49 0 $text->parent($elem);
50 0 $elem->contents([$text]);
51 }
52 0 $text->{__body} = undef;
53 0 1;
54 } else { # get
55 48 ▶ unless (defined $text->{__body}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text->{"__body"}) 48 0 48
56 48 ▶ if ($type eq 'xhtml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'xhtml') { } 14 34 48
57 my @children =
58 14 grep { ref($_) eq 'XML::Elemental::Element' }
59 14 @{$elem->contents};
60 14 ▶ if (@children) {
Branch: 1 branch
BranchTrueFalseTotal
if (@children) { } 14 0 14
61 14 my ($local) =
62 $children[0]->name =~ /{.*}(.+)/; # process name
63 14 ▶ @children = @{$children[0]->contents}
Branch: 1 branch
BranchTrueFalseTotal
if @children == 1 and $local eq "div" 14 0 14
Condition33%1/3
@children == 1 and $local eq "div"
!ll&&!rl&&r
0014
MC/DC0%0/2
@children == 1 and $local eq "div"
@children == 1 $local eq "div"
Truth table33%1/3
A and B
A= @children == 1B= $local eq "div"
ABresult
0X0
100
111
64 if (@children == 1 && $local eq 'div');
65 14 $text->{__body} = '<div>';
66 14 my $w = XML::Atom::Syndication::Writer->new;
67 14 $w->set_prefix('', 'http://www.w3.org/1999/xhtml');
68 14 map { $text->{__body} .= $w->as_xml($_) } @children;
69 14 $text->{__body} .= '</div>';
70 } else {
71 0 $text->{__body} = $elem->text_content;
72 }
73 14 ▶ if ($] >= 5.008) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.008") 14 0 14
74 14 Encode::_utf8_on($text->{__body});
75 14 $text->{__body} =~ s/&#x(\w{4});/chr(hex($1))/eg;
76 14 Encode::_utf8_off($text->{__body});
77 }
78 } else { # escaped
79 34 $text->{__body} = $elem->text_content;
80 }
81 }
82 48 $text->{__body};
83 }
84 }
85  
86 11 1;
87  
88 __END__
« Syndication/Object.pm ↑ Summary Syndication/Writer.pm »