blib/lib/CGI/RSS.pm

filter: Statementstmt 95.1% 118 / 124 Branchbran 68.7% 22 / 32 Conditioncond 35.0% 7 / 20 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 92.3% 24 / 26 Podpod 0.0% 0 / 8 totaltotal 78.0% 171 / 219 CC 25 SCAR 13.8
CC
25
Cov
84%
header
10.1
begin_rss
6.6
__ANON__
5.0
CRAP 4.0
↑ Summary
1  
2 package CGI::RSS;
3  
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Date::Manip;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use AutoLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use CGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use vars qw'@TAGS @EXPORT_OK %EXPORT_TAGS';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 8 our $VERSION = '0.9660';
16 8 our $pubDate_format = '%a, %d %b %Y %H:%M:%S %z';
17  
18 # Make sure we have a TZ
19 8 ▶unless( eval {Date_TimeZone(); 1} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { Date_TimeZone(); 1 } }) 0 8 8
20 0 ▶ $ENV{TZ} = "UTC" if $@ =~ m/unable to determine Time Zone/i;
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /unable to determine Time Zone/i 0 0 0
21 }
22  
23 1 ▶sub pubDate_format {
Subroutine pubDate_format: called CC=1 SCAR=0.0
Pod undocumented
24 1 my $class_or_instance = shift;
25 1 my $proposed = shift;
26  
27 1 $pubDate_format = $proposed;
28 1 $pubDate_format
29 }
30  
31 50 ▶sub grok_args {
Subroutine grok_args: called CC=4 SCAR=13.9
Pod undocumented
32 50 ▶ my $this = blessed($_[0]) ? shift : __PACKAGE__->new;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) ? : 43 7 50
33 50 ▶ my $attrs = ref($_[0]) eq "HASH" ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 13 37 50
34  
35 50 ▶ if( ref($_[0]) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "ARRAY") 4 46 50
36 4 return ($this,$attrs,undef,$_[0]);
37 }
38  
39 46 return ($this,$attrs,join(" ", @_),undef);
40 }
41  
42 264 ▶sub setup_tag {
Subroutine setup_tag: called CC=1 SCAR=0.0
Pod undocumented
43 264 my $tag = shift;
44  
45 # try to mimick CGI.pm (which is very unfriendly about new tags now)
46  
47 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 264 my @these_tags = ($tag, "start_$tag", "end_$tag");
50  
51 264 push @EXPORT_OK, @these_tags;
52 264 push @{ $EXPORT_TAGS{all} }, @these_tags;
53 264 push @{ $EXPORT_TAGS{tags} }, $tag;
54  
55 264 ▶ *{ __PACKAGE__ . "::$tag" } = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
56 48 my ($this, $attrs, $contents, $subs) = grok_args(@_);
57 48 my $res;
58  
59 48 ▶ if( $subs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subs) { } 4 44 48
60 4 ▶ $res = join("", map { $this->$tag( ($attrs ? $attrs : ()), $_ ) } @$subs );
Branch: 1 branch
BranchTrueFalseTotal
$attrs ? : 8 8 16
61  
62 } else {
63 44 $res = "<$tag";
64  
65 44 ▶ if( $attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs) 10 34 44
66 10 for(values %$attrs) {
67 # XXX: this is a terrible way to do this, better than nothing for now
68 10 s/(?<!\\)"/\\"/g;
69 }
70  
71 10 $res .= " " . join(" ", map {"$_=\"$attrs->{$_}\""} keys %$attrs);
72 }
73  
74 44 $res .= ">$contents</$tag>";
75 }
76  
77 48 return $res;
78 264 };
79  
80 264 ▶ *{ __PACKAGE__ . "::start_$tag" } = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
81 2 my ($this, $attrs) = grok_args(@_);
82 2 my $res = "<$tag";
83  
84 2 ▶ if( $attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs) 1 1 2
85 1 for(values %$attrs) {
86 # XXX: this is a terrible way to do this, better than nothing for now
87 1 s/(?<!\\)"/\\"/g;
88 }
89  
90 1 $res .= " " . join(" ", map {"$_=\"$attrs->{$_}\""} keys %$attrs);
91 }
92  
93 2 return $res . ">";
94 264 };
95  
96 264 ▶ *{ __PACKAGE__ . "::end_$tag" } = sub { "</$tag>" };
Subroutine __ANON__: called CC=1 SCAR=0.0
97 }
98  
99 11 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=3 SCAR=13.6
100 11 my $this = shift;
101 11 our $AUTOLOAD;
102  
103 11 ▶ if( my ($fname) = $AUTOLOAD =~ m/::([^:]+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($fname) = $CGI::RSS::AUTOLOAD =~ /::([^:]+)$/) 11 0 11
104 11 ▶ if( CGI->can($fname) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('CGI'->can($fname)) { } 0 11 11
105 0 ▶ *{ __PACKAGE__ . "::$fname" } = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 0 my $this = shift;
107 0 return CGI->$fname(@_);
108 }
109 0 }
110  
111 else {
112 11 croak "can't figure out what to do with $fname() call";
113 }
114 }
115 }
116  
117 11 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
118 11 my $class = shift;
119 11 my $this = bless {}, $class;
120  
121 11 return $this;
122 }
123  
124 3 ▶sub date {
Subroutine date: called CC=2 SCAR=7.4
Pod undocumented
125 3 my $this = shift;
126  
127 3 ▶ if( my $pd = ParseDate($_[-1]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pd = ParseDate($_[-1])) 3 0 3
128 3 my $date = UnixDate($pd, $pubDate_format);
129 3 return $this->pubDate($date);
130 }
131  
132 0 $this->pubDate(@_);
133 }
134  
135 1 ▶sub header {
Subroutine header: called CC=7 SCAR=23.2
Pod undocumented
136 1 my $this = shift;
137  
138 1 my $charset = "UTF-8";
139 1 my $mime = "application/xml";
140  
141 1 eval {
142 8 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
143 1 ▶ local $SIG{WARN} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=0.0
144 1 my %opts = @_;
145 1 ▶ $charset = $opts{'-charset'} || $opts{charset} || $charset;
Condition33%2/6
$opts{'-charset'} || $opts{'charset'} || $charset
l!l&&r!l&&!r
010
$opts{"-charset"} or $opts{"charset"}
l!l&&r!l&&!r
001
MC/DC0%0/3
$opts{'-charset'} || $opts{'charset'} || $charset
$opts{"-charset"} $opts{"charset"} $charset
Truth table25%1/4
A or B || C
A= $opts{"-charset"}B= $opts{"charset"}C= $charset
ABCresult
1XX1
01X1
0011
0000
146 1 ▶ $mime = $opts{'-type'} || $opts{type} || (@_==1 && $_[0]) || $mime;
Condition33%4/12
$opts{'-type'} || $opts{'type'} || @_ == 1 && $_[0] || $mime
l!l&&r!l&&!r
010
$opts{"-type"} or $opts{"type"} or @_ == 1 and $_[0]
l!l&&r!l&&!r
001
$opts{"-type"} or $opts{"type"}
l!l&&r!l&&!r
001
@_ == 1 and $_[0]
!ll&&!rl&&r
100
MC/DC0%0/5
$opts{'-type'} || $opts{'type'} || @_ == 1 && $_[0] || $mime
$opts{"-type"} $opts{"type"} @_ == 1 $_[0] $mime
Truth table14%1/7
A or B or C and D || E
A= $opts{"-type"}B= $opts{"type"}C= @_ == 1D= $_[0]E= $mime
ABCDEresult
1XXXX1
01XXX1
0011X1
000X11
001011
000X00
001000
147 };
148  
149 1 return CGI::header(-type=>$mime, -charset=>$charset) . "<?xml version=\"1.0\" encoding=\"$charset\"?>\n\n";
150 }
151  
152 1 ▶sub begin_rss {
Subroutine begin_rss: called CC=6 SCAR=18.8
Pod undocumented
153 1 my $this = shift;
154 1 my $opts = $_[0];
155 1 ▶ $opts = {@_} unless ref $opts;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts 1 0 1
156  
157 # NOTE: This isn't nearly as smart as CGI.pm's argument parsing...
158 # I assume I could call it, but but I'm only mortal.
159  
160 1 ▶ my $ver = $opts->{version} || "2.0";
Condition50%1/2
$opts->{'version'} || '2.0'
l!l
01
MC/DC0%0/1
$opts->{'version'} || '2.0'
$opts->{'version'}
Truth table50%1/2
A
A= $opts->{'version'}
Aresult
11
00
161 1 my $ret = $this->start_rss({version=>$ver});
162 1 $ret .= $this->start_channel;
163 1 ▶ $ret .= $this->link($opts->{link}) if exists $opts->{link};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"link"} 1 0 1
164 1 ▶ $ret .= $this->title($opts->{title}) if exists $opts->{title};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"title"} 1 0 1
165 1 ▶ $ret .= $this->description($opts->{desc}) if exists $opts->{desc};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"desc"} 1 0 1
166  
167 1 return $ret;
168 }
169  
170 1 ▶sub finish_rss {
Subroutine finish_rss: called CC=1 SCAR=0.0
Pod undocumented
171 1 my $this = shift;
172  
173 1 return $this->end_channel . $this->end_rss;
174 }
175  
176 8 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
177 8 @TAGS = qw(
178 rss channel item
179  
180 title link description
181  
182 language copyright managingEditor webMaster pubDate lastBuildDate category generator docs
183 cloud ttl image rating textInput skipHours skipDays
184  
185 link description author category comments enclosure guid pubDate source
186  
187 pubDate url
188 );
189  
190 8 setup_tag($_) for @TAGS;
191 }
192  
193 8 1;
194  
195 __END__
↑ Summary