blib/lib/Net/UPnP/AV/RSS.pm

filter: Statementstmt 100% 48 / 48 Branchbran 85.7% 12 / 14 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 89.7% 70 / 78 CC 10 SCAR 15.5
CC
10
Cov
94%
_entity
8.1
_text
3.0
BEGIN
1.0
CRAP 4.7
« blib/lib/Net/UPnP/Service.pm ↑ Summary blib/lib/Net/UPnP/ActionResponse.pm »
1 package Net::UPnP::AV::RSS;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Encode qw(decode FB_CROAK);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 82 ▶sub _text {
Subroutine _text: called CC=3 SCAR=11.0
8 82 my ($value) = @_;
9 82 ▶ return '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 82 82
10 82 ▶ return $value if utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($value) 20 62 82
11 62 return decode('UTF-8', $value, FB_CROAK);
12 }
13  
14 # XML 1.0 text and quoted attributes share these escaping requirements.
15 # Invalid XML characters have no representable numeric entity: replace them.
16 63 ▶sub _escape {
Subroutine _escape: called CC=1 SCAR=0.0
17 63 my ($value) = @_;
18 63 $value = _text($value);
19 63 $value =~ s/[^\x09\x0a\x0d\x20-\x{d7ff}\x{e000}-\x{fffd}\x{10000}-\x{10ffff}]/?/g;
20 63 $value =~ s/&/&/g;
21 63 $value =~ s/</&lt;/g;
22 63 $value =~ s/>/&gt;/g;
23 63 $value =~ s/"/&quot;/g;
24 63 $value =~ s/'/&apos;/g;
25 63 $value =~ s/\r/&#13;/g;
26 63 $value =~ s/\n/&#10;/g;
27 63 $value =~ s/\t/&#9;/g;
28 63 return $value;
29 }
30  
31 27 ▶sub _entity {
Subroutine _entity: called CC=8 SCAR=20.9
32 27 my ($entity) = @_;
33 27 my %named = (amp => '&', lt => '<', gt => '>', quot => '"', apos => "'");
34 27 ▶ return $named{$entity} if exists $named{$entity};
Branch: 1 branch
BranchTrueFalseTotal
if exists $named{$entity} 17 10 27
35 10 my $hex = $entity =~ s/\A#x//i;
36 10 $entity =~ s/\A#//;
37 10 $entity =~ s/\A0+//;
38 10 ▶ return '?' if length($entity) > ($hex ? 6 : 7);
Branch: 2 branches
BranchTrueFalseTotal
if length $entity > ($hex ? 6 : 7) 2 8 10
$hex ? : 4 6 10
39 8 ▶ my $number = $hex ? hex($entity || '0') : 0 + ($entity || '0');
Branch: 1 branch
BranchTrueFalseTotal
$hex ? : 4 4 8
Condition50%2/4
$entity || '0'
l!l
40
$entity || '0'
l!l
40
MC/DC0%0/1
$entity || '0'
$entity
MC/DC0%0/1
$entity || '0'
$entity
Truth table50%1/2
A
A= $entity
Aresult
11
00
Truth table50%1/2
A
A= $entity
Aresult
11
00
40 8 ▶ return '?' if $number > 0x10ffff;
Branch: 1 branch
BranchTrueFalseTotal
if $number > 1114111 0 8 8
41 8 return chr($number);
42 }
43  
44 3 ▶sub header {
Subroutine header: called CC=1 SCAR=0.0
Pod undocumented
45 3 my (%args) = @_;
46 my ($title, $language, $description, $link) =
47 3 map { _escape($args{$_}) } qw(title language description link);
48 3 return <<"RSS";
49 <?xml version="1.0" encoding="utf-8"?>
50 <rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" version="2.0">
51 <channel>
52 <title>$title</title>
53 <language>$language</language>
54 <description>$description</description>
55 <link>$link</link>
56 RSS
57 }
58  
59 19 ▶sub item {
Subroutine item: called CC=1 SCAR=0.0
Pod undocumented
60 19 my (%args) = @_;
61 # ContentDirectory titles retain one layer of DIDL entities after the
62 # outer SOAP Result is decoded. Decode exactly once, then escape as data.
63 19 my $title = _text($args{title});
64 17 $title =~ s/&(#x[0-9a-fA-F]+|#[0-9]+|amp|lt|gt|quot|apos);/_entity($1)/ge;
65 17 $title = _escape($title);
66 17 my $link = _escape($args{link});
67 17 my $size = _escape($args{size});
68 17 return <<"RSS";
69 <item>
70 <title>$title</title>
71 <guid isPermalink="false">$link</guid>
72 <enclosure url="$link" length="$size" type="video/mp4" />
73 </item>
74 RSS
75 }
76  
77 2 1;
« blib/lib/Net/UPnP/Service.pm ↑ Summary blib/lib/Net/UPnP/ActionResponse.pm »