| 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 | 51 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 51 | my $text = shift; | |||||||||||||||||||||||||||
| 10 | 51 | ▶ | my %param = @_ == 1 ? (Body => $_[0]) : @_; # escaped text is assumed. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 11 | 51 | $text->SUPER::init(%param); | |||||||||||||||||||||||||||
| 12 | 51 | my $e = $text->elem; | |||||||||||||||||||||||||||
| 13 | 51 | ▶ | if ($param{Body}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 0 | $text->body($param{Body}); | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | 51 | ▶ | if ($param{Type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 0 | $text->type($param{Type}); | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | 51 | $text; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 49 | ▶ | sub body { | ||||||||||||||||||||||||||
|
Subroutine
body: called CC=12 SCAR=33.8
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 49 | my $text = shift; | |||||||||||||||||||||||||||
| 24 | 49 | my $elem = $text->elem; | |||||||||||||||||||||||||||
| 25 | 49 | ▶ | my $type = $elem->attributes->{'{}type'} || 'text'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$elem->attributes->{'{}type'} || 'text'
MC/DC100%1/1
$elem->attributes->{'{}type'} || 'text'
$elem->attributes->{'{}type'}
Truth table100%2/2
A
A= $elem->attributes->{'{}type'}
| |||||||||||||||||||||||||||||
| 26 | 49 | ▶ | if (@_) { # set | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | my $data = shift; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ($type eq 'xhtml') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | my $node = $data; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | unless (ref $node) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | 49 | ▶ | unless (defined $text->{__body}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 49 | ▶ | if ($type eq 'xhtml') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | my @children = | ||||||||||||||||||||||||||||
| 58 | 14 | grep { ref($_) eq 'XML::Elemental::Element' } | |||||||||||||||||||||||||||
| 59 | 14 | @{$elem->contents}; | |||||||||||||||||||||||||||
| 60 | 14 | ▶ | if (@children) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 14 | my ($local) = | |||||||||||||||||||||||||||
| 62 | $children[0]->name =~ /{.*}(.+)/; # process name | ||||||||||||||||||||||||||||
| 63 | 14 | ▶ | @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"
| |||||||||||||||||||||||||||||
| 64 | if (@children == 1 && $local eq 'div'); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # $text->{__body} = '<div>'; | ||||||||||||||||||||||||||||
| 67 | 14 | my $w = XML::Atom::Syndication::Writer->new; | |||||||||||||||||||||||||||
| 68 | 14 | $w->set_prefix('', 'http://www.w3.org/1999/xhtml'); | |||||||||||||||||||||||||||
| 69 | 14 | $w->no_cdata(1); # works nicer with fringe case. see tests. | |||||||||||||||||||||||||||
| 70 | 14 | map { $text->{__body} .= $w->as_xml($_) } @children; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # $text->{__body} .= '</div>'; | ||||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||
| 74 | 0 | $text->{__body} = $elem->text_content; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 14 | ▶ | if ($] >= 5.008) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 14 | require Encode; | |||||||||||||||||||||||||||
| 78 | 14 | Encode::_utf8_on($text->{__body}); | |||||||||||||||||||||||||||
| 79 | 0 | $text->{__body} =~ s/&#x(\w{4});/chr(hex($1))/eg; | |||||||||||||||||||||||||||
| 80 | 14 | Encode::_utf8_off($text->{__body}); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } else { # escaped | ||||||||||||||||||||||||||||
| 83 | 35 | $text->{__body} = $elem->text_content; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 49 | $text->{__body}; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 11 | 1; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||