Feed/Actions/Fetch.pm

filter: Statementstmt 33.3% 18 / 54 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 29.4% 25 / 85 CC 17 SCAR 43.9
CC
17
Cov
24%
fetch_one
132.0
fetch
56.0
BEGIN
1.0
CRAP 80.4
« Feed/Mailbox.pm ↑ Summary Feed/Actions/List.pm »
1 package Cnutt::Feed::Actions::Fetch;
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 utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 =head1 NAME
9  
10 Cnutt::Feed::Actions::Get - Fetch some feeds as defined in the config file
11  
12 =head1 VERSION
13  
14 Version 1.0
15  
16 =cut
17  
18 2 our $VERSION = '1.0';
19  
20 =head1 DESCRIPTION
21  
22 This file is part of cnutt-feed. You should read its documentation.
23  
24 =cut
25  
26 2 ▶use Config::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use Cnutt::Feed::Mailbox;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 2 my %defaults = (
30 html => 1,
31 delete => 0,
32 verbose => 1,
33 );
34  
35 =head2 fetch_one
36  
37 Fetch only one feed
38  
39 =cut
40  
41 0 ▶sub fetch_one {
Subroutine fetch_one: not called CC=11 SCAR=48.8
Pod documented
42 0 my ($roptions, $conf, $name) = @_;
43 0 my %options = %{$roptions};
44  
45 die "Feed $name not found in $options{config}.\n"
46 0 ▶ if (!exists($conf->{$name}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $conf->{$name} 0 0 0
47  
48 # fill the blank using default value found in config file or in the
49 # code
50 0 my $url = $conf->{$name}->{url};
51 0 my $mb = $conf->{$name}->{mailbox};
52 0 $mb =~ s/^~/$ENV{HOME}/;
53  
54 0 foreach (keys %{$conf->{$name}}) {
55 0 ▶ if (!defined($options{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $options{$_}) 0 0 0
56 0 $options{$_} = $conf->{$name}->{$_};
57 }
58 }
59 0 foreach (keys %{$conf->{_}}) {
60 0 ▶ if (!defined($options{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $options{$_}) 0 0 0
61 0 $options{$_} = $conf->{_}->{$_};
62 }
63 }
64 0 foreach (keys %defaults) {
65 0 ▶ if (!defined($options{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $options{$_}) 0 0 0
66 0 $options{$_} = $defaults{$_};
67 }
68 }
69  
70 my $count = Cnutt::Feed::Mailbox->fetch($url, $mb,
71 $options{html},
72 $options{delete},
73 $options{verbose},
74 0 $name
75 );
76 0 ▶ if (defined($count)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $count) 0 0 0
77 0 ▶ print "Found $count new entries in $name\n" if $options{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"verbose"} 0 0 0
78 0 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) 0 0 0
79 0 print "\n";
80 }
81 }
82 }
83  
84 =head2 fetch
85  
86 fetch ($roptions, @names)
87  
88 By default, fetch all the feeds given in C<@names>
89  
90 If B<--all> is given, the feeds in C<@names> will be exclued.
91  
92 =cut
93  
94 0 ▶sub fetch {
Subroutine fetch: not called CC=7 SCAR=40.3
Pod documented
95 0 my ($roptions, @names) = @_;
96 0 my %options = %{$roptions};
97  
98 # read the config file
99 0 my $conf = Config::Tiny->read($options{config});
100 0 ▶ die "$Config::Tiny::errstr\n" unless $conf;
Branch: 1 branch
BranchTrueFalseTotal
unless $conf 0 0 0
101  
102 0 ▶ if ($options{all}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'all'}) { } 0 0 0
103 0 for my $name (keys %{$conf}) {
104 0 ▶ next if $name eq "_";
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "_" 0 0 0
105 0 ▶ next if grep(/$name/, @names);
Branch: 1 branch
BranchTrueFalseTotal
if grep /$name/, @names 0 0 0
106 0 fetch_one($roptions, $conf, $name);
107 }
108 }
109 else {
110 0 for (@names) {
111 0 fetch_one($roptions, $conf, $_);
112 }
113 }
114 }
115  
116 2 1;
117  
« Feed/Mailbox.pm ↑ Summary Feed/Actions/List.pm »