| 1 | package XML::Atom::Syndication::Content; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use base qw( XML::Atom::Syndication::Object ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use XML::Atom::Syndication::Util qw( utf8_off ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use MIME::Base64 qw( encode_base64 decode_base64 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | XML::Atom::Syndication::Content->mk_accessors('attribute', 'type', 'src'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | XML::Atom::Syndication::Content->mk_accessors('attribute', 'mode') | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ; # deprecated 0.3 accessors | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 13 | my $content = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | my %param = @_ == 1 ? (Body => $_[0]) : @_; # escaped text is assumed. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | $content->SUPER::init(%param); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 13 | my $e = $content->elem; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | ▶ | if ($param{Body}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | $content->body($param{Body}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | if ($param{Type}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $content->type($param{Type}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 13 | $content; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 14 | ▶ | sub element_name { 'content' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
element_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 11 | ▶ | sub body { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body: called CC=20 SCAR=36.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 11 | my $content = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 11 | my $elem = $content->elem; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | my $type = $elem->attributes->{'{}type'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 11 | my $mode; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | ▶ | if (!defined $type || $type eq 'text' || $type eq 'html') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%6/6
not defined $type or $type eq "text" or $type eq "html"
not defined $type or $type eq "text"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | $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$]
$type eq "xhtml" or $type =~ m[^(text/xml|application/xml|text/xml-external-parsed-entity)$]
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$]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 11 | ▶ | if (@_) { # set | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if ($mode eq 'base64') { # is binary | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | my $text = XML::Elemental::Characters->new; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | $text->data($data); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | $text->parent($elem); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $elem->contents([$text]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | $content->{__body} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } else { # get | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 10 | ▶ | unless (defined $content->{__body}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 10 | ▶ | if ($mode eq 'xml') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | my @children = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | grep { ref($_) eq 'XML::Elemental::Element' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | @{$elem->contents}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | ▶ | if (@children) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | my ($local) = | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | $children[0]->name =~ /{.*}(.+)/; # process name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | @children = @{$children[0]->contents} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@children == 1 and $local eq "div"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | if (@children == 1 && $local eq 'div'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # $content->{__body} = '<div>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | my $w = XML::Atom::Syndication::Writer->new; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | $w->set_prefix('', 'http://www.w3.org/1999/xhtml'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | map { $content->{__body} .= $w->as_xml($_) } @children; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # $content->{__body} .= '</div>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $content->{__body} = $elem->text_content; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | ▶ | if ($] >= 5.008) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | Encode::_utf8_on($content->{__body}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $content->{__body} =~ s/&#x(\w{4});/chr(hex($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | Encode::_utf8_off($content->{__body}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } elsif ($mode eq 'base64') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | $content->{__body} = decode_base64($elem->text_content); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } else { # escaped | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | $content->{__body} = $elem->text_content; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 10 | $content->{__body}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||