blib/lib/Web/Feed.pm

filter: Statementstmt 21.5% 23 / 107 Branchbran 0.0% 0 / 12 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 3 totaltotal 22.4% 31 / 138 CC 11 SCAR 30.3
CC
11
Cov
20%
rss
42.0
atom
30.0
new
2.0
CRAP 20.7
↑ Summary
1 package Web::Feed;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use DateTime::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Time::Local qw(timegm);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.12';
10  
11 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
12 1 my ($class, %data) = @_;
13 1 my $self = bless \%data, $class;
14 1 ▶ $self->{path} //= 'atom';
Condition50%1/2
$self->{"path"} //= "atom"
l!l
01
MC/DC0%0/1
$self->{"path"} //= "atom"
$self->{"path"}
Truth table50%1/2
A
A= $self->{"path"}
Aresult
11
00
15 1 return $self;
16 }
17  
18  
19 0 ▶sub atom {
Subroutine atom: not called CC=5 SCAR=34.0
Pod undocumented
20 0 my ($self) = @_;
21  
22 0 my $url = $self->{url};
23 0 $url =~ s{/*$}{};
24  
25 0 my $xml = '';
26 0 $xml .= qq{<?xml version="1.0" encoding="utf-8"?>\n};
27 0 $xml .= qq{<feed xmlns="http://www.w3.org/2005/Atom">\n};
28 0 $xml .= qq{<link href="$url/$self->{path}" rel="self" />\n};
29 0 $xml .= qq{<title>$self->{title}</title>\n};
30 0 $xml .= qq{<id>$url/</id>\n};
31 0 $xml .= qq{<updated>$self->{updated}Z</updated>\n};
32  
33 0 foreach my $e (@{ $self->{entries} }) {
34 0 $xml .= qq{<entry>\n};
35  
36 0 $xml .= qq{ <title>$e->{title}</title>\n};
37 0 $xml .= qq{ <summary type="html">$e->{summary}</summary>\n};
38 0 $xml .= qq{ <updated>$e->{updated}Z</updated>\n};
39  
40 0 $xml .= qq{ <link rel="alternate" type="text/html" href="$e->{link}" />};
41 0 my $id = $e->{id};
42 0 ▶ if (not $id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 0 0 0
43 0 $id = $e->{link};
44 0 $id =~ s/\?.*//;
45 }
46 0 $xml .= qq{ <id>$id</id>\n};
47 0 ▶ my $content = $e->{content} // '';
Condition0%0/2
$e->{"content"} // ""
l!l
00
MC/DC0%0/1
$e->{"content"} // ""
$e->{"content"}
Truth table0%0/2
A
A= $e->{"content"}
Aresult
11
00
48 0 $xml .= qq{ <content type="html">$content</content>\n};
49  
50 0 ▶ if ($e->{author}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"author"}) 0 0 0
51 0 $xml .= qq{ <author>\n};
52 0 $xml .= qq{ <name>$e->{author}{name}</name>\n};
53 #$xml .= qq{ <email>$e->{author}{email}</email>\n};
54 0 $xml .= qq{ </author>\n};
55 }
56  
57 0 $xml .= qq{</entry>\n};
58 };
59 0 $xml .= qq{</feed>\n};
60  
61 0 return $xml;
62 }
63  
64 0 ▶sub _pubDate {
Subroutine _pubDate: not called CC=1 SCAR=6.9
65 0 my ($date) = @_;
66 0 my $dt = DateTime::Tiny->from_string( "$date" ); # forced stringification
67 0 my $pubDate = POSIX::strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime timegm( $dt->second, $dt->minute, $dt->hour, $dt->day, $dt->month-1, $dt->year ));
68 0 return $pubDate;
69 }
70  
71  
72 0 ▶sub rss {
Subroutine rss: not called CC=6 SCAR=37.4
Pod undocumented
73 0 my ($self) = @_;
74  
75 0 my $url = $self->{url};
76 0 $url =~ s{/*$}{};
77 0 my $pubDate = _pubDate($self->{updated});
78  
79 # itunes specs: http://www.apple.com/itunes/podcasts/specs.html
80 0 my $xml = '';
81 0 $xml .= qq{<?xml version="1.0" encoding="UTF-8"?>\n};
82 0 $xml .= qq{<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">\n};
83 0 $xml .= qq{<channel>\n};
84 0 $xml .= qq{ <title>$self->{title}</title>\n};
85 0 $xml .= qq{ <link>$url/</link>\n};
86 0 $xml .= qq{ <pubDate>$pubDate</pubDate>\n};
87 0 $xml .= qq{ <description>$self->{description}</description>\n};
88 0 $xml .= qq{ <language>$self->{language}</language>\n};
89 0 $xml .= qq{ <copyright>$self->{copyright}</copyright>\n};
90  
91 0 $xml .= qq{ <itunes:subtitle>$self->{subtitle}</itunes:subtitle>\n};
92 0 $xml .= qq{ <itunes:author>$self->{author}</itunes:author>\n};
93 0 $xml .= qq{ <itunes:summary>$self->{summary}</itunes:summary>\n};
94 0 ▶ if ($self->{image}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"image"}) 0 0 0
95 0 $xml .= qq{ <itunes:image href="$self->{image}" />\n};
96 }
97 0 ▶ if ($self->{keywords}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"keywords"}) 0 0 0
98 0 my $keywords = join ', ', @{ $self->{keywords} };
99 0 $xml .= qq{ <itunes:keywords>$keywords</itunes:keywords>\n};
100 }
101 0 $xml .= qq{ <itunes:owner>\n};
102 0 $xml .= qq{ <itunes:name>$self->{itunes_name}</itunes:name>\n};
103 0 $xml .= qq{ <itunes:email>$self->{itunes_email}</itunes:email>\n};
104 0 $xml .= qq{ </itunes:owner>\n};
105 0 $xml .= qq{ <itunes:explicit>no</itunes:explicit>\n};
106 0 $xml .= qq{ <itunes:category text="$self->{category}" />\n};
107  
108 0 foreach my $e (@{ $self->{entries} }) {
109 0 $xml .= qq{ <item>\n};
110 0 $xml .= qq{ <title>$e->{title}</title>\n};
111 0 $xml .= qq{ <link>$e->{link}</link>\n};
112 0 $xml .= qq{ <guid>$e->{link}</guid>\n};
113 0 $xml .= qq{ <description>$e->{summary}</description>\n};
114 # $xml .= qq{ <updated>$e->{updated}Z</updated>\n};
115  
116 # $xml .= qq{ <id>$e->{id}</id>\n};
117 # $xml .= qq{ <content type="html">$e->{content}</content>\n};
118 0 ▶ if ($e->{author}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"author"}) 0 0 0
119 0 $xml .= qq{ <author>$e->{author}{name}</author>\n};
120 # $xml .= qq{ <author>\n};
121 # $xml .= qq{ <name>$e->{author}{name}</name>\n};
122 # $xml .= qq{ <email>$e->{author}{email}</email>\n};
123 # $xml .= qq{ </author>\n};
124 }
125  
126 0 ▶ if ($e->{itunes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"itunes"}) 0 0 0
127 0 my $pubDate = _pubDate($e->{updated});
128 0 $xml .= qq{ <pubDate>$pubDate</pubDate>\n};
129 0 $xml .= qq{ <itunes:author>$e->{itunes}{author}</itunes:author>\n};
130 # $xml .= qq{ <itunes:subtitle></itunes:subtitle>\n};
131 0 $xml .= qq{ <itunes:summary>$e->{itunes}{summary}</itunes:summary>\n};
132 # $xml .= qq{ <itunes:image href="http://example.com/podcasts/everything/AllAboutEverything/Episode1.jpg" />\n};
133 0 $xml .= qq{ <enclosure url="$e->{enclosure}{url}" length="$e->{enclosure}{length}" type="$e->{enclosure}{type}" />\n};
134 0 $xml .= qq{ <itunes:duration>$e->{itunes}{duration}</itunes:duration>\n};
135 }
136  
137  
138 0 $xml .= qq{ </item>\n};
139 }
140  
141 0 $xml .= qq{</channel>\n};
142 0 $xml .= qq{</rss>\n};
143  
144 0 return $xml;
145 }
146  
147 1 1;
148  
149 =pod
150  
151 =head1 NAME
152  
153 Web::Feed - generate Atom and RSS feeds and sitemaps.xml files
154  
155 =head1 DESCRIPTION
156  
157 Experimental code.
158  
159 =head1 COPYRIGHT
160  
161 (c) 2014 Gabor Szabo
162  
163 =head1 LICENSE
164  
165 This program is free software; you can redistribute it and/or
166 modify it under the same terms as Perl 5 itself.
167  
168 =cut
169  
170 # Copyright 2014 Gabor Szabo
171 # LICENSE
172 # This program is free software; you can redistribute it and/or
173 # modify it under the same terms as Perl 5 itself.
174  
175  
↑ Summary