Syndication/Content.pm

filter: Statementstmt 64.2% 54 / 84 Branchbran 50.0% 17 / 34 Conditioncond 73.3% 11 / 15 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 7 / 7 Podpod 66.6% 2 / 3 totaltotal 62.9% 95 / 151 SCAR 39.7
CC
23
Cov
62%
body
56.7
init
4.6
BEGIN
1.0
CRAP 52.8
↑ Summary Syndication/Object.pm »
1 package XML::Atom::Syndication::Content;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use base qw( XML::Atom::Syndication::Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use MIME::Base64 qw( encode_base64 decode_base64 );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 XML::Atom::Syndication::Content->mk_accessors('attribute', 'type', 'src');
10 2 XML::Atom::Syndication::Content->mk_accessors('attribute', 'mode')
11 ; # deprecated 0.3 accessors
12  
13 sub init {
14 11 ▶ my $content = shift;
Subroutine init: called CC=4 SCAR=15.2
Pod undocumented
15 11 ▶ my %param = @_ == 1 ? (Body => $_[0]) : @_; # escaped text is assumed.
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 11 11
16 11 $content->SUPER::init(%param);
17 11 my $e = $content->elem;
18 11 ▶ if ($param{Body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{"Body"}) 0 11 11
19 0 $content->body($param{Body});
20 }
21 11 ▶ if ($param{Type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{"Type"}) 0 11 11
22 0 $content->type($param{Type});
23 }
24 11 $content;
25 }
26  
27 11 ▶sub element_name { 'content' }
Subroutine element_name: called CC=1 SCAR=0.0
Pod documented
28  
29 sub body {
30 9 ▶ my $content = shift;
Subroutine body: called CC=20 SCAR=40.4
Pod documented
31 9 my $elem = $content->elem;
32 9 my $type = $elem->attributes->{'{}type'};
33 9 my $mode;
34 9 ▶ if (!defined $type || $type eq 'text' || $type eq 'html') {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $type or $type eq 'text' or $type eq 'html') { } 4 5 9
elsif ($type eq 'xhtml' or $type =~ m[^(text/xml|application/xml|text/xml-external-parsed-entity)$] or $type =~ m[[\+/]xml$]) { } 3 2 5
elsif ($type =~ m[text/.+]) { } 0 2 2
Condition100%6/6
not defined $type or $type eq "text" or $type eq "html"
l!l&&r!l&&!r
315
not defined $type or $type eq "text"
l!l&&r!l&&!r
126
MC/DC100%3/3
not defined $type or $type eq "text" or $type eq "html"
not defined $type $type eq "text" $type eq "html"
Truth table100%4/4
not(A) or B or C
A= not defined $typeB= $type eq "text"C= $type eq "html"
ABCresult
1XX1
01X1
0011
0000
35 4 $mode = 'escaped';
36 ▶ } elsif ( $type eq 'xhtml'
Condition66%4/6
$type eq "xhtml" or $type =~ m[^(text/xml|application/xml|text/xml-external-parsed-entity)$] or $type =~ m[[\+/]xml$]
l!l&&r!l&&!r
302
$type eq "xhtml" or $type =~ m[^(text/xml|application/xml|text/xml-external-parsed-entity)$]
l!l&&r!l&&!r
302
MC/DC33%1/3
$type eq "xhtml" or $type =~ m[^(text/xml|application/xml|text/xml-external-parsed-entity)$] or $type =~ m[[\+/]xml$]
$type eq "xhtml" $type =~ m[^(text/xml|application/xml|text/xml-external-parsed-entity)$] $type =~ m[[\+/]xml$]
Truth table50%2/4
A or B or C
A= $type eq "xhtml"B= $type =~ m[^(text/xml|application/xml|text/xml-external-parsed-entity)$]C= $type =~ m[[\+/]xml$]
ABCresult
1XX1
01X1
0011
0000
37 || $type =~
38 m{^(text/xml|application/xml|text/xml-external-parsed-entity)$}
39 || $type =~ m{[\+/]xml$}) {
40 3 $mode = 'xml';
41 } elsif ($type =~ m{text/.+}) {
42 0 $mode = 'escaped';
43 } else {
44 2 $mode = 'base64';
45 }
46 9 ▶ if (@_) { # set
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 9 9
47 0 my $data = shift;
48 0 ▶ if ($mode eq 'base64') { # is binary
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'base64') { } 0 0 0
elsif ($mode eq 'xml') { } 0 0 0
49 0 Encode::_utf8_off($data);
50 0 require XML::Elemental::Characters;
51 0 my $b = XML::Elemental::Characters->new;
52 0 $b->data(encode_base64($data, ''));
53 0 $b->parent($elem);
54 0 $elem->contents([$b]);
55 } elsif ($mode eq 'xml') { # is xml
56 0 my $node = $data;
57 0 ▶ unless (ref $node) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node) 0 0 0
58 0 my $copy =
59 '<div xmlns="http://www.w3.org/1999/xhtml">' . $data
60 . '</div>';
61 0 eval {
62 0 require XML::Elemental;
63 0 my $parser = XML::Elemental->parser;
64 0 my $xml = $parser->parse_string($copy);
65 0 $node = $xml->contents->[0];
66 };
67 0 ▶ return $content->error(
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
68 "Error parsing content body string as XML: $@")
69 if $@;
70 }
71 0 $node->parent($elem);
72 0 $elem->contents([$node]);
73 } else { # is text
74 0 my $text = XML::Elemental::Characters->new;
75 0 $text->data($data);
76 0 $text->parent($elem);
77 0 $elem->contents([$text]);
78 }
79 0 $content->{__body} = undef;
80 0 1;
81 } else { # get
82 9 ▶ unless (defined $content->{__body}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content->{"__body"}) 9 0 9
83 9 ▶ if ($mode eq 'xml') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'xml') { } 3 6 9
elsif ($mode eq 'base64') { } 2 4 6
84 my @children =
85 3 grep { ref($_) eq 'XML::Elemental::Element' }
86 3 @{$elem->contents};
87 3 ▶ if (@children) {
Branch: 1 branch
BranchTrueFalseTotal
if (@children) { } 3 0 3
88 3 my ($local) =
89 $children[0]->name =~ /{.*}(.+)/; # process name
90 3 ▶ @children = @{$children[0]->contents}
Branch: 1 branch
BranchTrueFalseTotal
if @children == 1 and $local eq "div" 3 0 3
Condition33%1/3
@children == 1 and $local eq "div"
!ll&&!rl&&r
003
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
91 if (@children == 1 && $local eq 'div');
92 3 $content->{__body} = '<div>';
93 3 my $w = XML::Atom::Syndication::Writer->new;
94 3 $w->set_prefix('', 'http://www.w3.org/1999/xhtml');
95 3 map { $content->{__body} .= $w->as_xml($_) } @children;
96 3 $content->{__body} .= '</div>';
97 } else {
98 0 $content->{__body} = $elem->text_content;
99 }
100 3 ▶ if ($] >= 5.008) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.008") 3 0 3
101 3 Encode::_utf8_on($content->{__body});
102 3 $content->{__body} =~ s/&#x(\w{4});/chr(hex($1))/eg;
103 3 Encode::_utf8_off($content->{__body});
104 }
105 } elsif ($mode eq 'base64') {
106 2 $content->{__body} = decode_base64($elem->text_content);
107 } else { # escaped
108 4 $content->{__body} = $elem->text_content;
109 }
110 }
111 9 $content->{__body};
112 }
113 }
114  
115 2 1;
116  
117 __END__
↑ Summary Syndication/Object.pm »