lib/Kwiki/FetchRSS.pm

filter: Statementstmt 38.9% 30 / 77 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 46.1% 6 / 13 Podpod 0.0% 0 / 6 totaltotal 27.9% 36 / 129 CC 13 SCAR 34.0
CC
13
Cov
29%
get_feed
72.0
get_content
30.0
to_html
6.0
CRAP 30.1
↑ Summary
1 package Kwiki::FetchRSS;
2 1 ▶use Kwiki::Plugin '-Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Kwiki::Installer '-base';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '0.08';
6  
7 1 const class_id => 'fetchrss';
8 1 const class_title => 'Fetch RSS';
9 1 const config_file => 'fetchrss.yaml';
10 1 const css_file => 'fetchrss.css';
11 1 field 'cache';
12 1 field 'error';
13 1 field 'expire';
14 1 field 'timeout' => -init => '$self->hub->config->fetchrss_ua_timeout';
15  
16 0 ▶sub register {
Subroutine register: not called CC=1 SCAR=6.9
Pod undocumented
17 0 my $registry = shift;
18 0 $registry->add( wafl => fetchrss => 'Kwiki::FetchRSS::Wafl' );
19 }
20  
21 0 ▶sub cache_dir {
Subroutine cache_dir: not called CC=1 SCAR=6.9
Pod undocumented
22 0 $self->plugin_directory;
23 }
24  
25 0 ▶sub get_content {
Subroutine get_content: not called CC=5 SCAR=34.0
Pod undocumented
26 0 my $url = shift;
27 0 my $content;
28  
29 0 require LWP::UserAgent;
30 0 my $ua = LWP::UserAgent->new();
31 0 $ua->timeout($self->timeout);
32 0 ▶ if (defined($self->hub->config->fetchrss_proxy) and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->hub->config->fetchrss_proxy and $self->hub->config->fetchrss_proxy ne "") 0 0 0
Condition0%0/3
defined $self->hub->config->fetchrss_proxy and $self->hub->config->fetchrss_proxy ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->hub->config->fetchrss_proxy and $self->hub->config->fetchrss_proxy ne ""
defined $self->hub->config->fetchrss_proxy $self->hub->config->fetchrss_proxy ne ""
Truth table0%0/3
A and B
A= defined $self->hub->config->fetchrss_proxyB= $self->hub->config->fetchrss_proxy ne ""
ABresult
0X0
100
111
33 $self->hub->config->fetchrss_proxy ne '' ) {
34 0 $ua->proxy([ 'http' ], $self->hub->config->fetchrss_proxy);
35 }
36 0 my $response = $ua->get($url);
37 0 ▶ if ($response->is_success()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
38 0 $content = $response->content();
39 0 ▶ if (length($content)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $content) { } 0 0 0
40 0 $self->cache->set( $url, $content, $self->expire );
41 } else {
42 0 $self->error('zero length response');
43 }
44 } else {
45 0 $self->error($response->status_line);
46 }
47 0 return $content;
48 }
49  
50 0 ▶sub setup_cache {
Subroutine setup_cache: not called CC=1 SCAR=6.9
Pod undocumented
51 0 require Cache::FileCache;
52 0 $self->cache(Cache::FileCache->new( {
53 namespace => $self->class_id,
54 cache_root => $self->cache_dir,
55 cache_depth => 1,
56 cache_umask => 002,
57 } ));
58 }
59  
60 0 ▶sub get_cached_result {
Subroutine get_cached_result: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my $name = shift;
62 0 return($self->cache->get($name));
63 }
64  
65 0 ▶sub get_feed { my ($url, $expire) = @_;
Subroutine get_feed: not called CC=8 SCAR=42.8
Pod undocumented
66  
67 0 require XML::Feed;
68  
69 0 ▶ $self->expire($expire
Branch: 1 branch
BranchTrueFalseTotal
$expire ? : 0 0 0
70 ? $expire
71 : $self->hub->config->fetchrss_default_expire()
72 );
73 0 $self->setup_cache;
74  
75 0 my $content = $self->get_cached_result($url);
76 0 ▶ if ( !defined($content) or !length($content) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content and length $content) 0 0 0
Condition0%0/3
defined $content and length $content
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content and length $content
defined $content length $content
Truth table0%0/3
A and B
A= defined $contentB= length $content
ABresult
0X0
100
111
77 0 $content = $self->get_content($url);
78 }
79  
80 0 ▶ if (defined($content) and length($content)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content and length $content) 0 0 0
Condition0%0/3
defined $content and length $content
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content and length $content
defined $content length $content
Truth table0%0/3
A and B
A= defined $contentB= length $content
ABresult
0X0
100
111
81 0 my $feed;
82 # XXX needs to be an eval here, sometimes the parse
83 # make poop on bad input
84 0 eval {
85 0 ▶ $feed = XML::Feed->parse(\$content) or die XML::Feed->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$feed = "XML::Feed"->parse(\$content) or die "XML::Feed"->errstr 0 0 0
86 };
87 0 ▶ return $feed unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
88 0 $self->error("xml parser error: $@");
89 }
90 0 return {error => $self->error};
91 }
92  
93 package Kwiki::FetchRSS::Wafl;
94 1 ▶use Spoon::Formatter;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 1 ▶use base 'Spoon::Formatter::WaflPhrase';
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 0 ▶sub to_html {
Subroutine to_html: not called CC=2 SCAR=17.9
98 0 my ($url, $full, $expire) = split(/,?\s+/, $self->arguments);
99 0 ▶ return $self->wafl_error unless $url;
Branch: 1 branch
BranchTrueFalseTotal
unless $url 0 0 0
100 0 my $feed = $self->hub->fetchrss->get_feed($url, $expire);
101 0 $self->hub->template->process('fetchrss.html', full => $full,
102 method => $self->method, fetchrss_url => $url,
103 feed => $feed);
104 }
105  
106  
107 1 1;
108  
109 package Kwiki::FetchRSS;
110  
111 1 1;
112  
113 1 __DATA__
↑ Summary