Noss.pm

filter: Statementstmt 9.1% 99 / 1079 Branchbran 0.1% 1 / 584 Conditioncond 0.0% 0 / 311 MC/DCmcdc 0.0% 0 / 178 Subroutinesub 22.9% 25 / 109 Podpod 94.7% 18 / 19 totaltotal 6.2% 143 / 2280 CC 445 SCAR 70.2
CC
445
Cov
5%
_read_config
5256.0
init
2550.0
update
930.0
CRAP 1114.3
↑ Summary Noss/Curl.pm »
1 package WWW::Noss;
2 1 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '2.05';
6  
7 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Getopt::Long qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use List::Util qw(max uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use WWW::Noss::Curl qw(curl curl_error http_status_string);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use WWW::Noss::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use WWW::Noss::FeedConfig;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use WWW::Noss::FeedReader qw(discover_feeds);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use WWW::Noss::Forker;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use WWW::Noss::GroupConfig;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use WWW::Noss::Home qw(home);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use WWW::Noss::Lynx qw(lynx_dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use WWW::Noss::OPML;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use WWW::Noss::TextToHtml qw(escape_html);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use WWW::Noss::Util qw(dir resolve_url);
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 my $PRGNAM = 'noss';
33 1 my $PRGVER = $VERSION;
34  
35 # TODO: Command aliases?
36  
37 1 my %COMMANDS = (
38 'update' => \&update,
39 'reload' => \&reload,
40 'read' => \&read_post,
41 'open' => \&open_post,
42 'cat' => \&cat,
43 'list' => \&look,
44 'unread' => \&unread,
45 'mark' => \&mark,
46 'post' => \&post,
47 'feeds' => \&feeds,
48 'groups' => \&groups,
49 'clean' => \&clean,
50 'discover' => \&discover,
51 'export' => \&export_opml,
52 'import' => \&import_opml,
53 'help' => \&help,
54 );
55  
56 1 my $DOT_LOCAL = File::Spec->catfile(home, '.local/share');
57 1 my $DOT_CONFIG = File::Spec->catfile(home, '.config');
58  
59 1 my $DEFAULT_AGENT = "$PRGNAM/$PRGVER ($^O; perl $^V)";
60 1 ▶my $DEFAULT_PAGER = $^O eq 'MSWin32' ? 'more' : 'less';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 1 1
61 1 my $DEFAULT_FORKS = 10;
62 1 my $DEFAULT_WIDTH = 80;
63  
64 1 my %VALID_SORTS = map { $_ => 1 } qw(
65 feed
66 title
67 date
68 );
69  
70 1 my $Z_FMT = '%c';
71 1 my $Z_UNK = strftime($Z_FMT, localtime 0) =~ s/\w/?/gr;
72  
73 1 my $RATE_RX = qr/^\d+[kmg]?$/i;
74  
75 my %POST_FMT_CODES = (
76 0 ▶ '%' => sub { '%' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 0 ▶ 'f' => sub { $_[0]->{ feed } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 ▶ 'i' => sub { $_[0]->{ nossid } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
79 0 ▶ 't' => sub { $_[0]->{ displaytitle } // ''},
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"displaytitle"} // ""
l!l
00
MC/DC0%0/1
$_[0]{"displaytitle"} // ""
$_[0]{"displaytitle"}
Truth table0%0/2
A
A= $_[0]{"displaytitle"}
Aresult
11
00
80 0 ▶ 'u' => sub { $_[0]->{ link } // 'N/A' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"link"} // "N/A"
l!l
00
MC/DC0%0/1
$_[0]{"link"} // "N/A"
$_[0]{"link"}
Truth table0%0/2
A
A= $_[0]{"link"}
Aresult
11
00
81 0 ▶ 'a' => sub { $_[0]->{ author } // 'N/A' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"author"} // "N/A"
l!l
00
MC/DC0%0/1
$_[0]{"author"} // "N/A"
$_[0]{"author"}
Truth table0%0/2
A
A= $_[0]{"author"}
Aresult
11
00
82 0 ▶ 'c' => sub { join ', ', @{ $_[0]->{ category } } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 ▶ 's' => sub { $_[0]->{ status } eq 'read' ? 'r' : 'U' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'status'} eq 'read' ? : 0 0 0
84 0 ▶ 'S' => sub { $_[0]->{ status } eq 'read' ? 'read' : 'unread' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'status'} eq 'read' ? : 0 0 0
85 0 ▶ 'P' => sub { $_[0]->{ summary } // '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"summary"} // ""
l!l
00
MC/DC0%0/1
$_[0]{"summary"} // ""
$_[0]{"summary"}
Truth table0%0/2
A
A= $_[0]{"summary"}
Aresult
11
00
86 0 ▶ 'C' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
87 0 ▶ strftime('%c', localtime($_[0]->{ updated } // $_[0]->{ published } // return 'N/A'))
Condition0%0/5
($_[0]{"updated"} // $_[0]{"published"}) // (return "N/A")
l!l
00
$_[0]{"updated"} // $_[0]{"published"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($_[0]{"updated"} // $_[0]{"published"}) // (return "N/A")
$_[0]{"updated"} $_[0]{"published"}
Truth table0%0/3
A // B
A= $_[0]{"updated"}B= $_[0]{"published"}
ABresult
1X1
011
000
88 },
89 0 ▶ 'd' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
90 0 ▶ strftime('%d', localtime($_[0]->{ updated } // $_[0]->{ published } // return '??'))
Condition0%0/5
($_[0]{"updated"} // $_[0]{"published"}) // (return "??")
l!l
00
$_[0]{"updated"} // $_[0]{"published"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($_[0]{"updated"} // $_[0]{"published"}) // (return "??")
$_[0]{"updated"} $_[0]{"published"}
Truth table0%0/3
A // B
A= $_[0]{"updated"}B= $_[0]{"published"}
ABresult
1X1
011
000
91 },
92 0 ▶ 'w' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
93 0 ▶ strftime('%a', localtime($_[0]->{ updated } // $_[0]->{ published } // return '???'))
Condition0%0/5
($_[0]{"updated"} // $_[0]{"published"}) // (return "???")
l!l
00
$_[0]{"updated"} // $_[0]{"published"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($_[0]{"updated"} // $_[0]{"published"}) // (return "???")
$_[0]{"updated"} $_[0]{"published"}
Truth table0%0/3
A // B
A= $_[0]{"updated"}B= $_[0]{"published"}
ABresult
1X1
011
000
94 },
95 0 ▶ 'W' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
96 0 ▶ strftime('%A', localtime($_[0]->{ updated } // $_[0]->{ published } // return '???'))
Condition0%0/5
($_[0]{"updated"} // $_[0]{"published"}) // (return "???")
l!l
00
$_[0]{"updated"} // $_[0]{"published"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($_[0]{"updated"} // $_[0]{"published"}) // (return "???")
$_[0]{"updated"} $_[0]{"published"}
Truth table0%0/3
A // B
A= $_[0]{"updated"}B= $_[0]{"published"}
ABresult
1X1
011
000
97 },
98 0 ▶ 'm' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
99 0 ▶ strftime('%b', localtime($_[0]->{ updated } // $_[0]->{ published } // return '???'))
Condition0%0/5
($_[0]{"updated"} // $_[0]{"published"}) // (return "???")
l!l
00
$_[0]{"updated"} // $_[0]{"published"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($_[0]{"updated"} // $_[0]{"published"}) // (return "???")
$_[0]{"updated"} $_[0]{"published"}
Truth table0%0/3
A // B
A= $_[0]{"updated"}B= $_[0]{"published"}
ABresult
1X1
011
000
100 },
101 0 ▶ 'M' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
102 0 ▶ strftime('%B', localtime($_[0]->{ updated } // $_[0]->{ published } // return '???'))
Condition0%0/5
($_[0]{"updated"} // $_[0]{"published"}) // (return "???")
l!l
00
$_[0]{"updated"} // $_[0]{"published"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($_[0]{"updated"} // $_[0]{"published"}) // (return "???")
$_[0]{"updated"} $_[0]{"published"}
Truth table0%0/3
A // B
A= $_[0]{"updated"}B= $_[0]{"published"}
ABresult
1X1
011
000
103 },
104 0 ▶ 'n' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
105 0 ▶ strftime('%m', localtime($_[0]->{ updated } // $_[0]->{ published } // return '??'))
Condition0%0/5
($_[0]{"updated"} // $_[0]{"published"}) // (return "??")
l!l
00
$_[0]{"updated"} // $_[0]{"published"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($_[0]{"updated"} // $_[0]{"published"}) // (return "??")
$_[0]{"updated"} $_[0]{"published"}
Truth table0%0/3
A // B
A= $_[0]{"updated"}B= $_[0]{"published"}
ABresult
1X1
011
000
106 },
107 0 ▶ 'y' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
108 0 ▶ strftime('%g', localtime($_[0]->{ updated } // $_[0]->{ published } // return '??'))
Condition0%0/5
($_[0]{"updated"} // $_[0]{"published"}) // (return "??")
l!l
00
$_[0]{"updated"} // $_[0]{"published"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($_[0]{"updated"} // $_[0]{"published"}) // (return "??")
$_[0]{"updated"} $_[0]{"published"}
Truth table0%0/3
A // B
A= $_[0]{"updated"}B= $_[0]{"published"}
ABresult
1X1
011
000
109 },
110 0 ▶ 'Y' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
111 0 ▶ strftime('%G', localtime($_[0]->{ updated } // $_[0]->{ published } // return '????'))
Condition0%0/5
($_[0]{"updated"} // $_[0]{"published"}) // (return "????")
l!l
00
$_[0]{"updated"} // $_[0]{"published"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($_[0]{"updated"} // $_[0]{"published"}) // (return "????")
$_[0]{"updated"} $_[0]{"published"}
Truth table0%0/3
A // B
A= $_[0]{"updated"}B= $_[0]{"published"}
ABresult
1X1
011
000
112 },
113 0 ▶ 'z' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
114 0 ▶ my $t = $_[0]->{ updated } // $_[0]->{ published };
Condition0%0/3
$_[0]{"updated"} // $_[0]{"published"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]{"updated"} // $_[0]{"published"}
$_[0]{"updated"} $_[0]{"published"}
Truth table0%0/3
A // B
A= $_[0]{"updated"}B= $_[0]{"published"}
ABresult
1X1
011
000
115 0 ▶ if (defined $t) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) { } 0 0 0
116 0 return strftime($Z_FMT, localtime $t);
117 } else {
118 0 return $Z_UNK;
119 }
120 },
121 1 );
122  
123 my %FEED_FMT_CODES = (
124 0 ▶ '%' => sub { '%' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
125 0 ▶ 'f' => sub { $_[0]->{ nossname } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 0 ▶ 'l' => sub { $_[0]->{ nosslink } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
127 0 ▶ 't' => sub { $_[0]->{ title } // '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"title"} // ""
l!l
00
MC/DC0%0/1
$_[0]{"title"} // ""
$_[0]{"title"}
Truth table0%0/2
A
A= $_[0]{"title"}
Aresult
11
00
128 0 ▶ 'u' => sub { $_[0]->{ link } // 'N/A' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"link"} // "N/A"
l!l
00
MC/DC0%0/1
$_[0]{"link"} // "N/A"
$_[0]{"link"}
Truth table0%0/2
A
A= $_[0]{"link"}
Aresult
11
00
129 0 ▶ 'e' => sub { $_[0]->{ description } // '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"description"} // ""
l!l
00
MC/DC0%0/1
$_[0]{"description"} // ""
$_[0]{"description"}
Truth table0%0/2
A
A= $_[0]{"description"}
Aresult
11
00
130 0 ▶ 'a' => sub { $_[0]->{ author } // 'N/A' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"author"} // "N/A"
l!l
00
MC/DC0%0/1
$_[0]{"author"} // "N/A"
$_[0]{"author"}
Truth table0%0/2
A
A= $_[0]{"author"}
Aresult
11
00
131 0 ▶ 'c' => sub { join ', ', @{ $_[0]->{ category } // [] } },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"category"} // []
l!l
00
MC/DC0%0/1
$_[0]{"category"} // []
$_[0]{"category"}
Truth table0%0/2
A
A= $_[0]{"category"}
Aresult
11
00
132 0 ▶ 'p' => sub { $_[0]->{ posts } // 0},
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"posts"} // 0
l!l
00
MC/DC0%0/1
$_[0]{"posts"} // 0
$_[0]{"posts"}
Truth table0%0/2
A
A= $_[0]{"posts"}
Aresult
11
00
133 0 ▶ 'r' => sub { ($_[0]->{ posts } // 0) - ($_[0]->{ unread } // 0) },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Condition0%0/4
$_[0]{"posts"} // 0
l!l
00
$_[0]{"unread"} // 0
l!l
00
MC/DC0%0/1
$_[0]{"posts"} // 0
$_[0]{"posts"}
MC/DC0%0/1
$_[0]{"unread"} // 0
$_[0]{"unread"}
Truth table0%0/2
A
A= $_[0]{"posts"}
Aresult
11
00
Truth table0%0/2
A
A= $_[0]{"unread"}
Aresult
11
00
134 0 ▶ 'U' => sub { $_[0]->{ unread } // 0},
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{"unread"} // 0
l!l
00
MC/DC0%0/1
$_[0]{"unread"} // 0
$_[0]{"unread"}
Truth table0%0/2
A
A= $_[0]{"unread"}
Aresult
11
00
135 0 ▶ 'C' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
136 0 ▶ strftime('%c', localtime($_[0]->{ updated } // return 'N/A'))
Condition0%0/2
$_[0]{"updated"} // (return "N/A")
l!l
00
MC/DC0%0/1
$_[0]{"updated"} // (return "N/A")
$_[0]{"updated"}
Truth table0%0/2
A
A= $_[0]{"updated"}
Aresult
11
00
137 },
138 0 ▶ 'd' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
139 0 ▶ strftime('%d', localtime($_[0]->{ updated } // return '??'))
Condition0%0/2
$_[0]{"updated"} // (return "??")
l!l
00
MC/DC0%0/1
$_[0]{"updated"} // (return "??")
$_[0]{"updated"}
Truth table0%0/2
A
A= $_[0]{"updated"}
Aresult
11
00
140 },
141 0 ▶ 'w' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
142 0 ▶ strftime('%a', localtime($_[0]->{ updated } // return '???'))
Condition0%0/2
$_[0]{"updated"} // (return "???")
l!l
00
MC/DC0%0/1
$_[0]{"updated"} // (return "???")
$_[0]{"updated"}
Truth table0%0/2
A
A= $_[0]{"updated"}
Aresult
11
00
143 },
144 0 ▶ 'W' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
145 0 ▶ strftime('%A', localtime($_[0]->{ updated } // return '???'))
Condition0%0/2
$_[0]{"updated"} // (return "???")
l!l
00
MC/DC0%0/1
$_[0]{"updated"} // (return "???")
$_[0]{"updated"}
Truth table0%0/2
A
A= $_[0]{"updated"}
Aresult
11
00
146 },
147 0 ▶ 'm' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
148 0 ▶ strftime('%b', localtime($_[0]->{ updated } // return '???'))
Condition0%0/2
$_[0]{"updated"} // (return "???")
l!l
00
MC/DC0%0/1
$_[0]{"updated"} // (return "???")
$_[0]{"updated"}
Truth table0%0/2
A
A= $_[0]{"updated"}
Aresult
11
00
149 },
150 0 ▶ 'M' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
151 0 ▶ strftime('%B', localtime($_[0]->{ updated } // return '???'))
Condition0%0/2
$_[0]{"updated"} // (return "???")
l!l
00
MC/DC0%0/1
$_[0]{"updated"} // (return "???")
$_[0]{"updated"}
Truth table0%0/2
A
A= $_[0]{"updated"}
Aresult
11
00
152 },
153 0 ▶ 'n' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
154 0 ▶ strftime('%m', localtime($_[0]->{ updated } // return '??'))
Condition0%0/2
$_[0]{"updated"} // (return "??")
l!l
00
MC/DC0%0/1
$_[0]{"updated"} // (return "??")
$_[0]{"updated"}
Truth table0%0/2
A
A= $_[0]{"updated"}
Aresult
11
00
155 },
156 0 ▶ 'y' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
157 0 ▶ strftime('%g', localtime($_[0]->{ updated } // return '??'))
Condition0%0/2
$_[0]{"updated"} // (return "??")
l!l
00
MC/DC0%0/1
$_[0]{"updated"} // (return "??")
$_[0]{"updated"}
Truth table0%0/2
A
A= $_[0]{"updated"}
Aresult
11
00
158 },
159 0 ▶ 'Y' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
160 0 ▶ strftime('%G', localtime($_[0]->{ updated } // return '????'))
Condition0%0/2
$_[0]{"updated"} // (return "????")
l!l
00
MC/DC0%0/1
$_[0]{"updated"} // (return "????")
$_[0]{"updated"}
Truth table0%0/2
A
A= $_[0]{"updated"}
Aresult
11
00
161 },
162 0 ▶ 'z' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
163 0 my $t = $_[0]->{ updated };
164 0 ▶ if (defined $t) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) { } 0 0 0
165 0 return strftime($Z_FMT, localtime $t);
166 } else {
167 0 return $Z_UNK;
168 }
169 },
170 1 );
171  
172 1 my $DEFAULT_READ_FMT = <<'HERE';
173 <h1>%f - %t</h1>
174  
175 <div>
176 %P
177 </div>
178  
179 <p>
180 Link: %u
181 </p>
182  
183 <p>
184 Updated: %z
185 </p>
186  
187 HERE
188  
189 1 my $DEFAULT_POST_FMT = <<'HERE';
190 <14>%f<0>:<15>%i<0>
191 <16>Title<0>: %t
192 <16>Link<0>: %u
193 <16>Author<0>: %a
194 <16>Tags<0>: %c
195 <16>Updated<0>: %z
196 <16>Status<0>: %S
197 HERE
198  
199 1 my $DEFAULT_FEED_FMT = <<'HERE';
200 <14>%f<0>
201 <16>Title<0>: %t
202 <16>Source<0>: %l
203 <16>Link<0>: %u
204 <16>Author<0>: %a
205 <16>Updated<0>: %z
206 <16>Posts<0>: %p
207 <16>Unread<0>: %U/%p
208  
209 HERE
210  
211 1 my %DOESNT_NEED_FEED = map { $_ => 1 } qw(
212 discover import help
213 );
214  
215 1 my $COLOR_CODE_RX = qr/(?:1[0-6]|[0-9])/;
216  
217 1 my %COLOR_CODES = (
218 0 => 'clear',
219 1 => 'black',
220 2 => 'red',
221 3 => 'green',
222 4 => 'yellow',
223 5 => 'blue',
224 6 => 'magenta',
225 7 => 'cyan',
226 8 => 'white',
227 9 => 'bold black',
228 10 => 'bold red',
229 11 => 'bold green',
230 12 => 'bold yellow',
231 13 => 'bold blue',
232 14 => 'bold magenta',
233 15 => 'bold cyan',
234 16 => 'bold white',
235 );
236  
237 0 ▶sub _HELP {
Subroutine _HELP: not called CC=2 SCAR=17.9
238  
239 0 my ($fh, $rt) = @_;
240  
241 0 pod2usage(
242 -exitval => 'NOEXIT',
243 -verbose => 99,
244 -sections => 'SYNOPSIS',
245 -output => \$fh,
246 );
247  
248 0 ▶ if (defined $rt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rt) 0 0 0
249 0 exit $rt;
250 }
251  
252 }
253  
254 0 ▶sub _VER {
Subroutine _VER: not called CC=2 SCAR=17.9
255  
256 0 my ($fh, $rt) = @_;
257  
258 0 print { $fh } <<"HERE";
259 $PRGNAM - $PRGVER
260  
261 Copyright (C) 2025-2026 Samuel Young
262  
263 This program is free software: you can redistribute it and/or modify
264 it under the terms of the GNU General Public License as published by
265 the Free Software Foundation, either version 3 of the License, or
266 (at your option) any later version.
267 HERE
268  
269 0 ▶ if (defined $rt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rt) 0 0 0
270 0 exit $rt;
271 }
272  
273 }
274  
275 0 ▶sub _set_z_fmt {
Subroutine _set_z_fmt: not called CC=1 SCAR=6.9
276  
277 0 my ($z) = @_;
278  
279 0 $Z_FMT = $z;
280 0 $Z_UNK = strftime($Z_FMT, localtime 0) =~ s/\w/?/gr;
281  
282 }
283  
284 0 ▶sub _default_data_dir {
Subroutine _default_data_dir: not called CC=5 SCAR=34.0
285  
286 0 my $data;
287  
288 0 ▶ if (exists $ENV{ NOSS_DATA }) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $ENV{'NOSS_DATA'}) { } 0 0 0
elsif (exists $ENV{'XDG_DATA_HOME'} and -d $ENV{'XDG_DATA_HOME'}) { } 0 0 0
elsif (-d $DOT_LOCAL) { } 0 0 0
289 0 $data = $ENV{ NOSS_DATA };
290 ▶ } elsif (exists $ENV{ XDG_DATA_HOME } and -d $ENV{ XDG_DATA_HOME }) {
Condition0%0/3
exists $ENV{"XDG_DATA_HOME"} and -d $ENV{"XDG_DATA_HOME"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $ENV{"XDG_DATA_HOME"} and -d $ENV{"XDG_DATA_HOME"}
exists $ENV{"XDG_DATA_HOME"} -d $ENV{"XDG_DATA_HOME"}
Truth table0%0/3
A and B
A= exists $ENV{"XDG_DATA_HOME"}B= -d $ENV{"XDG_DATA_HOME"}
ABresult
0X0
100
111
291 0 $data = File::Spec->catfile($ENV{ XDG_DATA_HOME }, $PRGNAM);
292 } elsif (-d $DOT_LOCAL) {
293 0 $data = File::Spec->catfile($DOT_LOCAL, $PRGNAM);
294 } else {
295 0 $data = File::Spec->catfile(home, ".$PRGNAM");
296 }
297  
298 0 return $data;
299  
300 }
301  
302 0 ▶sub _default_config {
Subroutine _default_config: not called CC=9 SCAR=45.0
303  
304 0 my $cf;
305  
306 0 ▶ if (exists $ENV{ NOSS_CONFIG }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"NOSS_CONFIG"}) 0 0 0
307 0 return $ENV{ NOSS_CONFIG };
308 }
309  
310 0 ▶ if (exists $ENV{ XDG_CONFIG_HOME }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"XDG_CONFIG_HOME"}) 0 0 0
311  
312 $cf = File::Spec->catfile(
313 $ENV{ XDG_CONFIG_HOME },
314 0 $PRGNAM,
315 "$PRGNAM.conf"
316 );
317 0 ▶ return $cf if -f $cf;
Branch: 1 branch
BranchTrueFalseTotal
if -f $cf 0 0 0
318  
319 $cf = File::Spec->catfile(
320 $ENV{ XDG_CONFIG_HOME },
321 0 "$PRGNAM.conf"
322 );
323 0 ▶ return $cf if -f $cf;
Branch: 1 branch
BranchTrueFalseTotal
if -f $cf 0 0 0
324  
325 }
326  
327 0 ▶ if (-d $DOT_CONFIG) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $DOT_CONFIG) 0 0 0
328  
329 0 $cf = File::Spec->catfile(
330 $DOT_CONFIG,
331 $PRGNAM,
332 "$PRGNAM.conf"
333 );
334 0 ▶ return $cf if -f $cf;
Branch: 1 branch
BranchTrueFalseTotal
if -f $cf 0 0 0
335  
336 0 $cf = File::Spec->catfile(
337 $DOT_CONFIG,
338 "$PRGNAM.conf"
339 );
340 0 ▶ return $cf if -f $cf;
Branch: 1 branch
BranchTrueFalseTotal
if -f $cf 0 0 0
341  
342 }
343  
344 0 $cf = File::Spec->catfile(home, ".$PRGNAM.conf");
345  
346 0 ▶ return $cf if -f $cf;
Branch: 1 branch
BranchTrueFalseTotal
if -f $cf 0 0 0
347  
348 0 return undef;
349  
350 }
351  
352 0 ▶sub _default_feeds {
Subroutine _default_feeds: not called CC=9 SCAR=45.0
353  
354 0 my $ff;
355  
356 0 ▶ if (exists $ENV{ NOSS_FEEDS }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"NOSS_FEEDS"}) 0 0 0
357 0 return $ENV{ NOSS_FEEDS };
358 }
359  
360 0 ▶ if (exists $ENV{ XDG_CONFIG_HOME }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"XDG_CONFIG_HOME"}) 0 0 0
361  
362 $ff = File::Spec->catfile(
363 $ENV{ XDG_CONFIG_HOME },
364 0 $PRGNAM,
365 "$PRGNAM.feeds"
366 );
367 0 ▶ return $ff if -f $ff;
Branch: 1 branch
BranchTrueFalseTotal
if -f $ff 0 0 0
368  
369 $ff = File::Spec->catfile(
370 $ENV{ XDG_CONFIG_HOME },
371 0 "$PRGNAM.feeds"
372 );
373 0 ▶ return $ff if -f $ff;
Branch: 1 branch
BranchTrueFalseTotal
if -f $ff 0 0 0
374  
375 }
376  
377 0 ▶ if (-d $DOT_CONFIG) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $DOT_CONFIG) 0 0 0
378  
379 0 $ff = File::Spec->catfile(
380 $DOT_CONFIG,
381 $PRGNAM,
382 "$PRGNAM.feeds"
383 );
384 0 ▶ return $ff if -f $ff;
Branch: 1 branch
BranchTrueFalseTotal
if -f $ff 0 0 0
385  
386 0 $ff = File::Spec->catfile(
387 $DOT_CONFIG,
388 "$PRGNAM.feeds"
389 );
390 0 ▶ return $ff if -f $ff;
Branch: 1 branch
BranchTrueFalseTotal
if -f $ff 0 0 0
391  
392 }
393  
394 0 $ff = File::Spec->catfile(home, ".$PRGNAM.feeds");
395 0 ▶ return $ff if -f $ff;
Branch: 1 branch
BranchTrueFalseTotal
if -f $ff 0 0 0
396  
397 0 return undef;
398  
399 }
400  
401 0 ▶sub _read_config {
Subroutine _read_config: not called CC=72 SCAR=85.7
402  
403 0 my ($self) = @_;
404  
405 0 my $cd = dirname(File::Spec->rel2abs($self->{ ConfFile }));
406  
407 open my $fh, '<', $self->{ ConfFile }
408 0 ▶ or die "Failed to open $self->{ ConfFile } for reading: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->{"ConfFile"} or die qq[Failed to open $self->{"ConfFile"} for reading: $!\n] 0 0 0
409 0 my $slurp = do { local $/ = undef; readline $fh };
410 0 close $fh;
411  
412 0 my $json_obj = JSON->new->relaxed;
413 0 my $json = $json_obj->decode($slurp);
414  
415 0 ▶ unless (ref $json eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $json eq "HASH") 0 0 0
416 0 die "$self->{ ConfFile } is not a valid $PRGNAM configuration file\n";
417 }
418  
419 0 ▶ if (defined $json->{ feeds }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"feeds"}) 0 0 0
420 0 ▶ if (not ref $json->{ feeds }) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $json->{'feeds'}) { } 0 0 0
421 0 my $p = $json->{ feeds } =~ s/^~/@{[ home ]}/r;
422 $self->{ FeedFile } //=
423 File::Spec->file_name_is_absolute($p)
424 ? $json->{ feeds }
425 0 ▶ : File::Spec->catfile($cd, $p);
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($p) ? : 0 0 0
Condition0%0/3
$self->{"FeedFile"} //= "File::Spec"->file_name_is_absolute($p) ? $json->{"feeds"} : "File::Spec"->catfile($cd, $p)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"FeedFile"} //= "File::Spec"->file_name_is_absolute($p) ? $json->{"feeds"} : "File::Spec"->catfile($cd, $p)
$self->{"FeedFile"} "File::Spec"->file_name_is_absolute($p) ? $json->{"feeds"} : "File::Spec"->catfile($cd, $p)
Truth table0%0/3
A //= B
A= $self->{"FeedFile"}B= "File::Spec"->file_name_is_absolute($p) ? $json->{"feeds"} : "File::Spec"->catfile($cd, $p)
ABresult
1X1
011
000
426 } else {
427 0 warn "'feeds' is not a string, ignoring\n";
428 }
429 }
430  
431 0 ▶ if (defined $json->{ data }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"data"}) 0 0 0
432 0 ▶ if (not ref $json->{ data }) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $json->{'data'}) { } 0 0 0
433 0 my $p = $json->{ data } =~ s/^~/@{[ home ]}/r;
434 $self->{ DataDir } //=
435 File::Spec->file_name_is_absolute($p)
436 ? $json->{ data }
437 0 ▶ : File::Spec->catfile($cd, $p);
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($p) ? : 0 0 0
Condition0%0/3
$self->{"DataDir"} //= "File::Spec"->file_name_is_absolute($p) ? $json->{"data"} : "File::Spec"->catfile($cd, $p)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"DataDir"} //= "File::Spec"->file_name_is_absolute($p) ? $json->{"data"} : "File::Spec"->catfile($cd, $p)
$self->{"DataDir"} "File::Spec"->file_name_is_absolute($p) ? $json->{"data"} : "File::Spec"->catfile($cd, $p)
Truth table0%0/3
A //= B
A= $self->{"DataDir"}B= "File::Spec"->file_name_is_absolute($p) ? $json->{"data"} : "File::Spec"->catfile($cd, $p)
ABresult
1X1
011
000
438 } else {
439 0 warn "'data' is not a string, ignoring\n";
440 }
441 }
442  
443 0 ▶ if (defined $json->{ downloads }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"downloads"}) 0 0 0
444 0 ▶ if ($json->{ downloads } =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{'downloads'} =~ /^\d+$/u) { } 0 0 0
445 0 ▶ $self->{ Forks } //= $json->{ downloads };
Condition0%0/3
$self->{"Forks"} //= $json->{"downloads"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Forks"} //= $json->{"downloads"}
$self->{"Forks"} $json->{"downloads"}
Truth table0%0/3
A //= B
A= $self->{"Forks"}B= $json->{"downloads"}
ABresult
1X1
011
000
446 } else {
447 0 warn "'downloads' ($json->{ downloads }) is not an integar, ignoring\n";
448 }
449 }
450  
451 0 ▶ if (defined $json->{ pager }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"pager"}) 0 0 0
452 0 ▶ if (not ref $self->{ pager }) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $self->{'pager'}) { } 0 0 0
453 0 ▶ $self->{ Pager } //= $json->{ pager };
Condition0%0/3
$self->{"Pager"} //= $json->{"pager"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Pager"} //= $json->{"pager"}
$self->{"Pager"} $json->{"pager"}
Truth table0%0/3
A //= B
A= $self->{"Pager"}B= $json->{"pager"}
ABresult
1X1
011
000
454 } else {
455 0 warn "'pager' is not a string, ignoring\n";
456 }
457 }
458  
459 0 ▶ if (defined $json->{ browser }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"browser"}) 0 0 0
460 0 ▶ if (not ref $self->{ browser }) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $self->{'browser'}) { } 0 0 0
461 0 ▶ $self->{ Browser } //= $json->{ browser };
Condition0%0/3
$self->{"Browser"} //= $json->{"browser"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Browser"} //= $json->{"browser"}
$self->{"Browser"} $json->{"browser"}
Truth table0%0/3
A //= B
A= $self->{"Browser"}B= $json->{"browser"}
ABresult
1X1
011
000
462 } else {
463 0 warn "'browser' is not a string, ignoring\n";
464 }
465 }
466  
467 0 ▶ if (defined $json->{ limit_rate }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"limit_rate"}) 0 0 0
468 0 ▶ if ($self->{ RateLimit } =~ $RATE_RX) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'RateLimit'} =~ /$RATE_RX/u) { } 0 0 0
469 0 ▶ $self->{ RateLimit } //= $json->{ limit_rate };
Condition0%0/3
$self->{"RateLimit"} //= $json->{"limit_rate"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"RateLimit"} //= $json->{"limit_rate"}
$self->{"RateLimit"} $json->{"limit_rate"}
Truth table0%0/3
A //= B
A= $self->{"RateLimit"}B= $json->{"limit_rate"}
ABresult
1X1
011
000
470 } else {
471 0 warn "limit_rate' ($json->{ limit_rate }) is not a valid speed, ignoring\n";
472 }
473 }
474  
475 0 ▶ if (defined $json->{ user_agent }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"user_agent"}) 0 0 0
476 0 ▶ if (ref $json->{ user_agent }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json->{'user_agent'}) { } 0 0 0
477 0 warn "'user_agent' is not a string, ignoring\n";
478 } else {
479 0 ▶ $self->{ UserAgent } //= $json->{ user_agent };
Condition0%0/3
$self->{"UserAgent"} //= $json->{"user_agent"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"UserAgent"} //= $json->{"user_agent"}
$self->{"UserAgent"} $json->{"user_agent"}
Truth table0%0/3
A //= B
A= $self->{"UserAgent"}B= $json->{"user_agent"}
ABresult
1X1
011
000
480 }
481 }
482  
483 0 ▶ if (defined $json->{ timeout }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"timeout"}) 0 0 0
484 0 ▶ if ($json->{ timeout } =~ /^\d+(\.\d+)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{'timeout'} =~ /^\d+(\.\d+)?$/u) { } 0 0 0
485 0 ▶ $self->{ Timeout } //= $json->{ timeout };
Condition0%0/3
$self->{"Timeout"} //= $json->{"timeout"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Timeout"} //= $json->{"timeout"}
$self->{"Timeout"} $json->{"timeout"}
Truth table0%0/3
A //= B
A= $self->{"Timeout"}B= $json->{"timeout"}
ABresult
1X1
011
000
486 } else {
487 0 warn "'timeout' ($json->{ timeout }) is not numerical, ignoring\n";
488 }
489 }
490  
491 0 ▶ if (defined $json->{ proxy }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"proxy"}) 0 0 0
492 0 ▶ if (ref $json->{ proxy }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json->{'proxy'}) { } 0 0 0
493 0 warn "'proxy' is not a string, ignoring\n";
494 } else {
495 0 ▶ $self->{ Proxy } //= $json->{ proxy };
Condition0%0/3
$self->{"Proxy"} //= $json->{"proxy"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Proxy"} //= $json->{"proxy"}
$self->{"Proxy"} $json->{"proxy"}
Truth table0%0/3
A //= B
A= $self->{"Proxy"}B= $json->{"proxy"}
ABresult
1X1
011
000
496 }
497 }
498  
499 0 ▶ if (defined $json->{ proxy_user }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"proxy_user"}) 0 0 0
500 0 ▶ if ($json->{ proxy_user } =~ /^[^:]+:[^:]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{'proxy_user'} =~ /^[^:]+:[^:]+$/u) { } 0 0 0
501 0 ▶ $self->{ ProxyUser } //= $json->{ proxy_user };
Condition0%0/3
$self->{"ProxyUser"} //= $json->{"proxy_user"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ProxyUser"} //= $json->{"proxy_user"}
$self->{"ProxyUser"} $json->{"proxy_user"}
Truth table0%0/3
A //= B
A= $self->{"ProxyUser"}B= $json->{"proxy_user"}
ABresult
1X1
011
000
502 } else {
503 0 warn "'proxy_user' ($json->{ proxy_user }) is not a valid proxy user string, ignoring\n";
504 }
505 }
506  
507 0 ▶ if (defined $json->{ sort }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"sort"}) 0 0 0
508 0 ▶ if (exists $VALID_SORTS{ $json->{ sort } }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $VALID_SORTS{$json->{'sort'}}) { } 0 0 0
509 0 ▶ $self->{ Sort } //= $json->{ sort };
Condition0%0/3
$self->{"Sort"} //= $json->{"sort"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Sort"} //= $json->{"sort"}
$self->{"Sort"} $json->{"sort"}
Truth table0%0/3
A //= B
A= $self->{"Sort"}B= $json->{"sort"}
ABresult
1X1
011
000
510 } else {
511 0 warn sprintf "'sort' must be one of the following: %s\n", join(', ', sort keys %VALID_SORTS);
512 }
513 }
514  
515 0 ▶ if (defined $json->{ line_width }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"line_width"}) 0 0 0
516 0 ▶ if ($json->{ line_width } =~ /^\d+$/ and $json->{ line_width } > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{'line_width'} =~ /^\d+$/u and $json->{'line_width'} > 0) { } 0 0 0
Condition0%0/3
$json->{"line_width"} =~ /^\d+$/u and $json->{"line_width"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$json->{"line_width"} =~ /^\d+$/u and $json->{"line_width"} > 0
$json->{"line_width"} =~ /^\d+$/u $json->{"line_width"} > 0
Truth table0%0/3
A and B
A= $json->{"line_width"} =~ /^\d+$/uB= $json->{"line_width"} > 0
ABresult
0X0
100
111
517 0 ▶ $self->{ LineWidth } //= $json->{ line_width };
Condition0%0/3
$self->{"LineWidth"} //= $json->{"line_width"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"LineWidth"} //= $json->{"line_width"}
$self->{"LineWidth"} $json->{"line_width"}
Truth table0%0/3
A //= B
A= $self->{"LineWidth"}B= $json->{"line_width"}
ABresult
1X1
011
000
518 } else {
519 0 warn "'line_width' must be an integar greater than 0, ignoring\n";
520 }
521 }
522  
523 0 ▶ if (defined $json->{ list_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"list_format"}) 0 0 0
524 0 ▶ if (ref $json->{ list_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json->{'list_format'}) { } 0 0 0
525 0 warn "'list_format' is not a format string, ignoring\n";
526 } else {
527 0 ▶ $self->{ ListFmt } //= $json->{ list_format };
Condition0%0/3
$self->{"ListFmt"} //= $json->{"list_format"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ListFmt"} //= $json->{"list_format"}
$self->{"ListFmt"} $json->{"list_format"}
Truth table0%0/3
A //= B
A= $self->{"ListFmt"}B= $json->{"list_format"}
ABresult
1X1
011
000
528 }
529 }
530  
531 0 ▶ if (defined $json->{ read_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"read_format"}) 0 0 0
532 0 ▶ if (ref $json->{ read_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json->{'read_format'}) { } 0 0 0
533 0 warn "'read_format' is not a format string, ignoring\n";
534 } else {
535 0 ▶ $self->{ ReadFmt } //= $json->{ read_format };
Condition0%0/3
$self->{"ReadFmt"} //= $json->{"read_format"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ReadFmt"} //= $json->{"read_format"}
$self->{"ReadFmt"} $json->{"read_format"}
Truth table0%0/3
A //= B
A= $self->{"ReadFmt"}B= $json->{"read_format"}
ABresult
1X1
011
000
536 }
537 }
538  
539 0 ▶ if (defined $json->{ post_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"post_format"}) 0 0 0
540 0 ▶ if (ref $json->{ post_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json->{'post_format'}) { } 0 0 0
541 0 warn "'post_format' is not a format string, ignoring\n";
542 } else {
543 0 ▶ $self->{ PostFmt } //= $json->{ post_format };
Condition0%0/3
$self->{"PostFmt"} //= $json->{"post_format"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"PostFmt"} //= $json->{"post_format"}
$self->{"PostFmt"} $json->{"post_format"}
Truth table0%0/3
A //= B
A= $self->{"PostFmt"}B= $json->{"post_format"}
ABresult
1X1
011
000
544 }
545 }
546  
547 0 ▶ if (defined $json->{ feeds_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"feeds_format"}) 0 0 0
548 0 ▶ if (ref $json->{ feeds_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json->{'feeds_format'}) { } 0 0 0
549 0 warn "'feeds_format' is not a format string, ignoring\n";
550 } else {
551 0 ▶ $self->{ FeedsFmt } //= $json->{ feeds_fmt };
Condition0%0/3
$self->{"FeedsFmt"} //= $json->{"feeds_fmt"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"FeedsFmt"} //= $json->{"feeds_fmt"}
$self->{"FeedsFmt"} $json->{"feeds_fmt"}
Truth table0%0/3
A //= B
A= $self->{"FeedsFmt"}B= $json->{"feeds_fmt"}
ABresult
1X1
011
000
552 }
553 }
554  
555 0 ▶ if (defined $json->{ autoclean }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"autoclean"}) 0 0 0
556 0 ▶ $self->{ AutoClean } //= !! $json->{ autoclean };
Condition0%0/2
$self->{"AutoClean"} //= !!$json->{"autoclean"}
l!l
00
MC/DC0%0/1
$self->{"AutoClean"} //= !!$json->{"autoclean"}
$self->{"AutoClean"}
Truth table0%0/2
A
A= $self->{"AutoClean"}
Aresult
11
00
557 }
558  
559 0 ▶ if (defined $json->{ time_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"time_format"}) 0 0 0
560 0 ▶ if (ref $json->{ time_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json->{'time_format'}) { } 0 0 0
561 0 warn "'time_format' is not a format string, ignoring\n";
562 } else {
563 0 ▶ $self->{ TimeFmt } //= $json->{ time_format };
Condition0%0/3
$self->{"TimeFmt"} //= $json->{"time_format"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"TimeFmt"} //= $json->{"time_format"}
$self->{"TimeFmt"} $json->{"time_format"}
Truth table0%0/3
A //= B
A= $self->{"TimeFmt"}B= $json->{"time_format"}
ABresult
1X1
011
000
564 }
565 }
566  
567 0 ▶ if (defined $json->{ list_limit }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"list_limit"}) 0 0 0
568 0 ▶ if ($json->{ list_limit } =~ /^-?\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{'list_limit'} =~ /^-?\d+$/u) { } 0 0 0
569 0 ▶ $self->{ ListLimit } //= $json->{ list_limit };
Condition0%0/3
$self->{"ListLimit"} //= $json->{"list_limit"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ListLimit"} //= $json->{"list_limit"}
$self->{"ListLimit"} $json->{"list_limit"}
Truth table0%0/3
A //= B
A= $self->{"ListLimit"}B= $json->{"list_limit"}
ABresult
1X1
011
000
570 } else {
571 0 warn "'list_limit' ($json->{ list_limit }) is not an integar, ignoring\n";
572 }
573 }
574  
575 0 ▶ if (defined $json->{ colors }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"colors"}) 0 0 0
576 0 ▶ if (ref $json->{ colors } ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json->{'colors'} ne 'HASH') { } 0 0 0
577 0 warn "'colors' is not a key-value map, ignoring\n";
578 } else {
579 0 for my $k (keys %{ $json->{ colors } }) {
580 0 ▶ if (not exists $self->{ ColorMap }{ $k }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"ColorMap"}{$k}) 0 0 0
581 0 warn "'$k' is not a valid color code, ignoring\n";
582 0 next;
583 }
584 0 $self->{ ColorMap }{ $k } = $json->{ colors }{ $k };
585 }
586 }
587 }
588  
589 0 ▶ if (defined $json->{ list_unread_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"list_unread_format"}) 0 0 0
590 0 ▶ if (ref $json->{ list_unread_format }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json->{'list_unread_format'}) { } 0 0 0
591 0 warn "'list_unread_format' is not a format string, ignoring\n";
592 } else {
593 0 ▶ $self->{ ListUnreadFmt } //= $json->{ list_unread_format };
Condition0%0/3
$self->{"ListUnreadFmt"} //= $json->{"list_unread_format"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ListUnreadFmt"} //= $json->{"list_unread_format"}
$self->{"ListUnreadFmt"} $json->{"list_unread_format"}
Truth table0%0/3
A //= B
A= $self->{"ListUnreadFmt"}B= $json->{"list_unread_format"}
ABresult
1X1
011
000
594 }
595 }
596  
597 0 ▶ if (defined $json->{ colored_output }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $json->{"colored_output"}) 0 0 0
598 # If true, set to undef so that noss can automatically disable the use
599 # of color when not writing to a terminal.
600 0 ▶ $self->{ UseColor } //= $json->{ colored_output } ? undef : 0;
Branch: 1 branch
BranchTrueFalseTotal
$json->{'colored_output'} ? : 0 0 0
Condition0%0/2
$self->{"UseColor"} //= $json->{"colored_output"} ? undef : 0
l!l
00
MC/DC0%0/1
$self->{"UseColor"} //= $json->{"colored_output"} ? undef : 0
$self->{"UseColor"}
Truth table0%0/2
A
A= $self->{"UseColor"}
Aresult
11
00
601 }
602  
603 0 return 1;
604  
605 }
606  
607 # Note to a confused future self:
608 # When adding a new feed parameter, the following locations should be updated:
609 # * This _feed_params subroutine
610 # * BaseConfig attributes
611 # * FeedConfig group attribute initialization
612 # * (Base|Feed|Group)Config documentation
613 # * FeedConfig tests
614 # * Feed configuration section in manual
615 0 ▶sub _feed_params {
Subroutine _feed_params: not called CC=27 SCAR=66.3
616  
617 0 my ($ref) = @_;
618  
619 0 my %params;
620  
621 0 ▶ if (defined $ref->{ limit }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"limit"}) 0 0 0
622 0 ▶ if ($ref->{ limit } =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{'limit'} =~ /^\d+$/u) { } 0 0 0
623 0 $params{ limit } = $ref->{ limit };
624 } else {
625 0 warn "'limit' ($ref->{ limit }) is not an integar, ignoring\n";
626 }
627 }
628  
629 0 ▶ if (defined $ref->{ respect_skip }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"respect_skip"}) 0 0 0
630 0 $params{ respect_skip } = !! $ref->{ respect_skip };
631 }
632  
633 0 ▶ if (defined $ref->{ include_title }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"include_title"}) 0 0 0
634 0 ▶ if (ref $ref->{ include_title } eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref->{'include_title'} eq 'ARRAY') { } 0 0 0
elsif (not ref $ref->{'include_title'}) { } 0 0 0
635 0 $params{ include_title } = [ map { _arg2rx($_) } @{ $ref->{ include_title } } ];
636 } elsif (not ref $ref->{ include_title }) {
637 0 $params{ include_title } = [ _arg2rx($ref->{ include_title }) ];
638 } else {
639 0 warn "'include_title' is not an array or string, ignoring\n";
640 }
641 }
642  
643 0 ▶ if (defined $ref->{ exclude_title }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"exclude_title"}) 0 0 0
644 0 ▶ if (ref $ref->{ exclude_title } eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref->{'exclude_title'} eq 'ARRAY') { } 0 0 0
elsif (not ref $ref->{'exclude_title'}) { } 0 0 0
645 0 $params{ exclude_title } = [ map { _arg2rx($_) } @{ $ref->{ exclude_title } } ];
646 } elsif (not ref $ref->{ exclude_title }) {
647 0 $params{ exclude_title } = [ _arg2rx($ref->{ exclude_title }) ];
648 } else {
649 0 warn "'exclude_title' is not an array or string, ignoring\n";
650 }
651 }
652  
653 0 ▶ if (defined $ref->{ include_content }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"include_content"}) 0 0 0
654 0 ▶ if (ref $ref->{ include_content } eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref->{'include_content'} eq 'ARRAY') { } 0 0 0
elsif (not ref $ref->{'include_content'}) { } 0 0 0
655 0 $params{ include_content } = [ map { _arg2rx($_) } @{ $ref->{ include_content } } ];
656 } elsif (not ref $ref->{ include_content }) {
657 0 $params{ include_content } = [ _arg2rx($ref->{ include_content }) ];
658 } else {
659 0 warn "'include_content' is not an array or string, ignoring\n";
660 }
661 }
662  
663 0 ▶ if (defined $ref->{ exclude_content }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"exclude_content"}) 0 0 0
664 0 ▶ if (ref $ref->{ exclude_content } eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref->{'exclude_content'} eq 'ARRAY') { } 0 0 0
elsif (not ref $ref->{'exclude_content'}) { } 0 0 0
665 0 $params{ exclude_content } = [ map { _arg2rx($_) } @{ $ref->{ exclude_content } } ];
666 } elsif (not ref $ref->{ exclude_content }) {
667 0 $params{ exclude_content } = [ _arg2rx($ref->{ exclude_content }) ];
668 } else {
669 0 warn "'exclude_content' is not an array or string, ignoring\n";
670 }
671 }
672  
673 0 ▶ if (defined $ref->{ include_tags }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"include_tags"}) 0 0 0
674 0 ▶ if (ref $ref->{ include_tags } eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref->{'include_tags'} eq 'ARRAY') { } 0 0 0
elsif (not ref $ref->{'include_tags'}) { } 0 0 0
675 0 $params{ include_tags } = $ref->{ include_tags };
676 } elsif (not ref $ref->{ include_tags }) {
677 0 $params{ include_tags } = [ $ref->{ include_tags } ];
678 } else {
679 0 warn "'include_tags' is not an array or string, ignoring\n";
680 }
681 }
682  
683 0 ▶ if (defined $ref->{ exclude_tags }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"exclude_tags"}) 0 0 0
684 0 ▶ if (ref $ref->{ exclude_tags } eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref->{'exclude_tags'} eq 'ARRAY') { } 0 0 0
elsif (not ref $ref->{'exclude_tags'}) { } 0 0 0
685 0 $params{ exclude_tags } = $ref->{ exclude_tags };
686 } elsif (not ref $ref->{ exclude_tags }) {
687 0 $params{ exclude_tags } = [ $ref->{ exclude_tags } ];
688 } else {
689 0 warn "'exclude_tags' is not an array or string, ignoring\n";
690 }
691 }
692  
693 0 ▶ if (defined $ref->{ autoread }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"autoread"}) 0 0 0
694 0 $params{ autoread } = !! $ref->{ autoread };
695 }
696  
697 0 ▶ if (defined $ref->{ default_update }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"default_update"}) 0 0 0
698 0 $params{ default_update } = !! $ref->{ default_update };
699 }
700  
701 0 ▶ if (defined $ref->{ hidden }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"hidden"}) 0 0 0
702 0 $params{ hidden } = !! $ref->{ hidden };
703 }
704  
705 0 ▶ if (defined $ref->{ open }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"open"}) 0 0 0
706 0 $params{ open } = $ref->{ open };
707 }
708  
709 0 ▶ if (defined $ref->{ user_agent }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{"user_agent"}) 0 0 0
710 0 $params{ user_agent } = $ref->{ user_agent };
711 }
712  
713 0 return %params;
714  
715 }
716  
717 0 ▶sub _read_feed_file {
Subroutine _read_feed_file: not called CC=27 SCAR=66.3
718  
719 0 my ($self) = @_;
720  
721 open my $fh, '<', $self->{ FeedFile }
722 0 ▶ or die "Failed to open $self->{ FeedFile } for reading: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->{"FeedFile"} or die qq[Failed to open $self->{"FeedFile"} for reading: $!\n] 0 0 0
723 0 my $slurp = do { local $/ = undef; readline $fh };
724 0 close $fh;
725  
726 0 my $json_obj = JSON->new->relaxed;
727 0 my $json = $json_obj->decode($slurp);
728  
729 0 ▶ unless (ref $json eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $json eq "HASH") 0 0 0
730 0 die "$self->{ FeedFile } is not a valid feed file\n";
731 }
732  
733 0 ▶ unless (exists $json->{ feeds }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $json->{"feeds"}) 0 0 0
734 0 die "Failed to read $self->{ FeedFile }: missing 'feeds' list\n";
735 }
736  
737 0 my $feeds = $json->{ feeds };
738 0 ▶ my $groups = $json->{ groups } // {};
Condition0%0/2
$json->{"groups"} // {}
l!l
00
MC/DC0%0/1
$json->{"groups"} // {}
$json->{"groups"}
Truth table0%0/2
A
A= $json->{"groups"}
Aresult
11
00
739 0 ▶ my $default = $json->{ default } // {};
Condition0%0/2
$json->{"default"} // {}
l!l
00
MC/DC0%0/1
$json->{"default"} // {}
$json->{"default"}
Truth table0%0/2
A
A= $json->{"default"}
Aresult
11
00
740  
741 0 ▶ unless (ref $feeds eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $feeds eq "HASH") 0 0 0
742 0 die "Failed to read $self->{ FeedFile }: 'feeds' must be a key-value map\n";
743 }
744  
745 0 ▶ unless (ref $groups eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $groups eq "HASH") 0 0 0
746 0 die "Failed to read $self->{ FeedFile }: 'groups' must be a key-value map\n";
747 }
748  
749 0 ▶ unless (ref $default eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $default eq "HASH") 0 0 0
750 0 die "Failed to read $self->{ FeedFile }: 'default' must be a key-value map\n";
751 }
752  
753 0 for my $k (keys %$groups) {
754 0 ▶ unless ($k =~ /^\w+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($k =~ /^\w+$/u) 0 0 0
755 0 warn "'$k' is not a valid feed group: name contains invalid characters, ignoring\n";
756 0 delete $groups->{ $k };
757 }
758 0 ▶ if (exists $feeds->{ $k }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $feeds->{$k}) 0 0 0
759 0 die "'$k' is both the name of a feed and group\n";
760 }
761 }
762  
763 0 for my $k (keys %$feeds) {
764 0 ▶ unless ($k =~ /^\w+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($k =~ /^\w+$/u) 0 0 0
765 0 warn "'$k' is not a valid feed name: contains invalid characters, ignoring\n";
766 0 delete $feeds->{ $k };
767 }
768 }
769  
770  
771 0 ▶ if (%$default) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$default) 0 0 0
772 0 my %params = _feed_params($default);
773 0 $self->{ DefaultGroup } = WWW::Noss::GroupConfig->new(
774 name => ':all',
775 feeds => [ keys %$feeds ],
776 %params
777 );
778 }
779  
780 0 for my $k (keys %$groups) {
781 0 my $g = $groups->{ $k };
782  
783 0 ▶ if (ref $g eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $g eq 'ARRAY') { } 0 0 0
elsif (ref $g ne 'HASH') { } 0 0 0
784 0 $g = { feeds => $g };
785 } elsif (ref $g ne 'HASH') {
786 0 warn "'$k' is neither a feed list or key-value map, skipping\n";
787 0 next;
788 }
789  
790 0 ▶ unless (ref $g->{ feeds } eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $g->{"feeds"} eq "ARRAY") 0 0 0
791 0 warn "'$k' group does not contain a feed list, skipping\n";
792 0 next;
793 }
794  
795 0 my %params = _feed_params($g);
796  
797 $self->{ Groups }{ $k } = WWW::Noss::GroupConfig->new(
798 name => $k,
799 feeds => $g->{ feeds },
800 0 %params
801 );
802  
803 }
804  
805 0 for my $k (keys %$feeds) {
806 0 my $f = $feeds->{ $k };
807  
808 0 ▶ if (not ref $f and defined $f) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $f and defined $f) { } 0 0 0
elsif (ref $f ne 'HASH') { } 0 0 0
Condition0%0/3
not ref $f and defined $f
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $f and defined $f
not ref $f defined $f
Truth table0%0/3
not(A) and B
A= not ref $fB= defined $f
ABresult
0X0
100
111
809 0 $f = { feed => $f };
810 } elsif (ref $f ne 'HASH') {
811 0 warn "'$k' is neither a feed link or a key-value map, skipping\n";
812 0 next;
813 }
814  
815 0 ▶ unless (exists $f->{ feed }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $f->{"feed"}) 0 0 0
816 0 warn "'$k' feed does not contain a feed link, skipping\n";
817 0 next;
818 }
819  
820 0 ▶ if (ref $f->{ feed } or not defined $f->{ feed }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $f->{"feed"} or not defined $f->{"feed"}) 0 0 0
Condition0%0/3
ref $f->{"feed"} or not defined $f->{"feed"}
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $f->{"feed"} or not defined $f->{"feed"}
ref $f->{"feed"} not defined $f->{"feed"}
Truth table0%0/3
A or not(B)
A= ref $f->{"feed"}B= not defined $f->{"feed"}
ABresult
1X1
011
000
821 0 warn "'$k' feed link is not a string, skipping\n";
822 0 next;
823 }
824  
825 0 my @groups = grep { $_->has_feed($k) } values %{ $self->{ Groups } };
826  
827 0 my %params = _feed_params($f);
828  
829 $self->{ Feeds }{ $k } = WWW::Noss::FeedConfig->new(
830 name => $k,
831 feed => $f->{ feed },
832 default => $self->{ DefaultGroup },
833 groups => \@groups,
834 path => File::Spec->catfile($self->{ FeedDir }, "$k.feed"),
835 etag => File::Spec->catfile($self->{ EtagDir }, "$k.etag"),
836 0 retry_cache => File::Spec->catfile($self->{ RetryDir }, "$k.retry"),
837 %params
838 );
839  
840 }
841  
842 0 ▶ unless (%{ $self->{ Feeds } }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%{$self->{"Feeds"};}) 0 0 0
843 0 die "$PRGNAM found no feeds in $self->{ FeedFile }\n";
844 }
845  
846 0 return 1;
847  
848 }
849  
850 0 ▶sub _arg2rx {
Subroutine _arg2rx: not called CC=2 SCAR=17.9
851  
852 0 my ($str) = @_;
853  
854 0 ▶ if ($str =~ /^\/(.*)\/$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ m[^/(.*)/$]u) { } 0 0 0
855 0 return qr/$1/i;
856 } else {
857 0 return qr/\Q$str\E/i;
858 }
859  
860 }
861  
862 0 ▶sub _fmt {
Subroutine _fmt: not called CC=7 SCAR=40.3
863  
864 0 my ($fmt, $codes, $colors) = @_;
865 0 ▶ $colors //= {};
Condition0%0/2
$colors //= {}
l!l
00
MC/DC0%0/1
$colors //= {}
$colors
Truth table0%0/2
A
A= $colors
Aresult
11
00
866  
867 0 ▶ $fmt .= "\n" unless $fmt =~ /\n$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $fmt =~ /\n$/u 0 0 0
868  
869 0 my @subs;
870 0 my $colored = 0;
871  
872 0 $fmt =~ s{(?<Fmt>%(?:[+\-]?\d+)?.)|(?<Color><$COLOR_CODE_RX>)}{
873 0 ▶ if (defined $+{ Fmt }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $+{'Fmt'}) { } 0 0 0
874 0 my $code = substr $+{ Fmt }, 1;
875 0 my $c = chop $code;
876 0 ▶ unless (exists $codes->{ $c }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $codes->{$c}) 0 0 0
877 0 die "'%$code$c' is not a valid formatting code\n";
878 }
879 0 push @subs, $codes->{ $c };
880 0 '%' . $code . 's';
881 } else {
882 0 my $code = substr $+{ Color }, 1, -1;
883 0 ▶ if (not exists $colors->{ $code }) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $colors->{$code}) { } 0 0 0
884 0 $+{ Color };
885 } else {
886 0 $colored = 1;
887 0 color($colors->{ $code });
888 }
889 }
890 }ge;
891  
892 0 ▶ if ($colored) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colored) 0 0 0
893 0 $fmt .= color('reset');
894 }
895  
896 0 ▶ return sub { sprintf $fmt, map { $_->($_[0]) } @subs };
Subroutine __ANON__: not called CC=1 SCAR=6.9
897  
898 }
899  
900 0 ▶sub _rm_color_codes {
Subroutine _rm_color_codes: not called CC=1 SCAR=6.9
901  
902 0 my ($str) = @_;
903  
904 0 return $str =~ s/<$COLOR_CODE_RX>//gr;
905  
906 }
907  
908 0 ▶sub err {
Subroutine err: not called CC=3 SCAR=24.8
Pod undocumented
909  
910 0 my ($self, @args) = @_;
911  
912 0 my $err = join '', @args;
913  
914 0 ▶ if ($self->{ UseColor } and -t STDERR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'UseColor'} and -t STDERR) { } 0 0 0
Condition0%0/3
$self->{"UseColor"} and -t STDERR
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"UseColor"} and -t STDERR
$self->{"UseColor"} -t STDERR
Truth table0%0/3
A and B
A= $self->{"UseColor"}B= -t STDERR
ABresult
0X0
100
111
915 0 warn colored($err, 'bold red') . "\n";
916 } else {
917 0 warn "$err\n";
918 }
919  
920 }
921  
922 0 ▶sub _get_feed {
Subroutine _get_feed: not called CC=22 SCAR=62.3
923  
924 0 my ($self, $feed) = @_;
925  
926 0 ▶ if ($feed->feed =~ /^file:\/\//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($feed->feed =~ m[^file://]u) { } 0 0 0
elsif ($feed->feed =~ m[^shell://]u) { } 0 0 0
927  
928 0 my $f = $feed->feed =~ s/^file:\/\///r;
929  
930 0 $f =~ s/^~/@{[ home ]}/;
931  
932 0 ▶ unless (File::Spec->file_name_is_absolute($f)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($f)) 0 0 0
933 $f = File::Spec->catfile(
934 0 dirname($self->{ FeedFile }),
935 $f
936 );
937 }
938  
939 0 ▶ copy($f, $feed->path)
Branch: 1 branch
BranchTrueFalseTotal
copy($f, $feed->path) or die sprintf("Failed to copy %s to %s: %s\n", $f, $feed->path, $!) 0 0 0
940 or die sprintf "Failed to copy %s to %s: %s\n", $f, $feed->path, $!;
941 # Copy over access and mod times
942 0 utime((stat($f))[8, 9], $feed->path);
943  
944 0 return $feed->path;
945  
946 } elsif ($feed->feed =~ /^shell:\/\//) {
947  
948 0 my $cmd = $feed->feed =~ s/^shell:\/\///r;
949  
950 0 ▶ open my $fh, '>', $feed->path
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $feed->path or die sprintf("Failed to open %s for writing: %s\n", $feed->path, $!) 0 0 0
951 or die sprintf "Failed to open %s for writing: %s\n", $feed->path, $!;
952  
953 # cd into feed file directory, so that shell command is ran from said
954 # directory.
955 0 my $cwd = cwd;
956  
957 chdir dirname($self->{ FeedFile })
958 0 ▶ or die "Failed to chdir to $self->{ FeedFile }: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir dirname($self->{"FeedFile"}) or die qq[Failed to chdir to $self->{"FeedFile"}: $!\n] 0 0 0
959  
960 0 my $qx = qx/$cmd/;
961  
962 0 ▶ unless ($? >> 8 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($? >> 8 == 0) 0 0 0
963 0 ▶ chdir $cwd or die "Failed to chdir to $cwd: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $cwd or die "Failed to chdir to ${cwd}: $!\n" 0 0 0
964 0 die "Failed to execute '$cmd'\n";
965 }
966  
967 0 print { $fh } $qx;
968  
969 0 close $fh;
970  
971 0 ▶ chdir $cwd or die "Failed to chdir to $cwd: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $cwd or die "Failed to chdir to ${cwd}: $!\n" 0 0 0
972  
973 0 return $feed->path;
974  
975 # Otherwise, just try to curl the URL
976 } else {
977  
978 my ($rt, $resp, $head) = curl(
979 $feed->feed,
980 $feed->path,
981 verbose => 0,
982 remote_time => 1,
983 etag_save => $feed->etag,
984 limit_rate => $self->{ RateLimit },
985 user_agent => $feed->user_agent // $self->{ UserAgent },
986 timeout => $self->{ Timeout },
987 fail => 1,
988 proxy => $self->{ Proxy },
989 proxy_user => $self->{ ProxyUser },
990 (
991 0 ▶ !$self->{ Unconditional } && -f $feed->path
Branch: 2 branches
BranchTrueFalseTotal
!$self->{'Unconditional'} && -f $feed->path ? : 0 0 0
-s $feed->etag ? : 0 0 0
Condition0%0/6
$feed->user_agent // $self->{"UserAgent"}
l!l&&r!l&&!r
000
not $self->{"Unconditional"} and -f $feed->path
!ll&&!rl&&r
000
MC/DC0%0/2
$feed->user_agent // $self->{"UserAgent"}
$feed->user_agent $self->{"UserAgent"}
MC/DC0%0/2
not $self->{"Unconditional"} and -f $feed->path
not $self->{"Unconditional"} -f $feed->path
Truth table0%0/3
A // B
A= $feed->user_agentB= $self->{"UserAgent"}
ABresult
1X1
011
000
Truth table0%0/3
not(A) and B
A= not $self->{"Unconditional"}B= -f $feed->path
ABresult
0X0
100
111
992 ? (
993 time_cond => $feed->path,
994 etag_compare => (-s $feed->etag ? $feed->etag : undef),
995 )
996 : ()
997 ),
998 redirect => 1,
999 compressed => 1,
1000 );
1001  
1002 0 ▶ if (defined $resp and $resp->[1] eq '429') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resp and $resp->[1] eq 429) 0 0 0
Condition0%0/3
defined $resp and $resp->[1] eq 429
!ll&&!rl&&r
000
MC/DC0%0/2
defined $resp and $resp->[1] eq 429
defined $resp $resp->[1] eq 429
Truth table0%0/3
A and B
A= defined $respB= $resp->[1] eq 429
ABresult
0X0
100
111
1003 0 my $retry = $head->{ 'retry-after' };
1004 0 ▶ if (defined $retry and $retry =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $retry and $retry =~ /^\d+$/u) 0 0 0
Condition0%0/3
defined $retry and $retry =~ /^\d+$/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $retry and $retry =~ /^\d+$/u
defined $retry $retry =~ /^\d+$/u
Truth table0%0/3
A and B
A= defined $retryB= $retry =~ /^\d+$/u
ABresult
0X0
100
111
1005 0 $feed->set_retry($retry + time);
1006 }
1007 }
1008  
1009 0 ▶ if ($rt != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rt != 0) 0 0 0
1010 0 my $e;
1011 0 ▶ if (defined $resp and $resp->[1] =~ /^[45]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resp and $resp->[1] =~ /^[45]/u) { } 0 0 0
Condition0%0/3
defined $resp and $resp->[1] =~ /^[45]/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $resp and $resp->[1] =~ /^[45]/u
defined $resp $resp->[1] =~ /^[45]/u
Truth table0%0/3
A and B
A= defined $respB= $resp->[1] =~ /^[45]/u
ABresult
0X0
100
111
1012 0 ▶ $e = "$resp->[1] " . ($resp->[2] || http_status_string($resp->[1]));
Condition0%0/3
$resp->[2] || http_status_string($resp->[1])
l!l&&r!l&&!r
000
MC/DC0%0/2
$resp->[2] || http_status_string($resp->[1])
$resp->[2] http_status_string($resp->[1])
Truth table0%0/3
A || B
A= $resp->[2]B= http_status_string($resp->[1])
ABresult
1X1
011
000
1013 } else {
1014 0 $e = curl_error($rt);
1015 }
1016 0 die "$e\n";
1017 }
1018  
1019 0 return $feed->path;
1020  
1021 }
1022  
1023 }
1024  
1025 0 ▶sub update {
Subroutine update: not called CC=30 SCAR=68.4
Pod documented
1026  
1027 0 my ($self) = @_;
1028  
1029 # --hard implies --unconditional
1030 0 ▶ if ($self->{ HardReload }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"HardReload"}) 0 0 0
1031 0 $self->{ Unconditional } = 1;
1032 }
1033  
1034 0 my @updates;
1035  
1036 0 ▶ if (@{ $self->{ Args } }) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$self->{'Args'};}) { } 0 0 0
elsif ($self->{'NonDefaults'}) { } 0 0 0
1037 0 my %feedset;
1038 0 for my $arg (@{ $self->{ Args } }) {
1039 0 ▶ if (exists $self->{ Feeds }{ $arg }) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'Feeds'}{$arg}) { } 0 0 0
elsif ($self->{'Groups'}{$arg}) { } 0 0 0
1040 0 $feedset{ $arg } = 1;
1041 } elsif ($self->{ Groups }{ $arg }) {
1042 0 for my $k (@{ $self->{ Groups }{ $arg }->feeds }) {
1043 0 $feedset{ $k } = 1;
1044 }
1045 } else {
1046 0 warn "'$arg' is not the name of a feed or feed group, skipping\n";
1047 }
1048 }
1049 0 @updates = keys %feedset;
1050 } elsif ($self->{ NonDefaults }) {
1051 0 @updates = keys %{ $self->{ Feeds } };
1052 } else {
1053 @updates =
1054 0 grep { $self->{ Feeds }{ $_ }->default_update }
1055 0 keys %{ $self->{ Feeds } };
1056 }
1057  
1058 0 ▶ if ($self->{ NewOnly }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"NewOnly"}) 0 0 0
1059 0 @updates = grep { !$self->{ DB }->has_feed($_) } @updates;
1060 }
1061  
1062 0 ▶ unless (@updates) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@updates) 0 0 0
1063 0 die "No feeds can be updated\n";
1064 }
1065  
1066 0 @updates = map { [ $_, $self->{ DB }->skip($_) ] } @updates;
1067  
1068 0 my @change;
1069  
1070 0 my $forker = WWW::Noss::Forker->new($self->{ Forks });
1071 0 ▶ $forker->run_on_finish(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1072 0 ▶ push @change, ${ $_[2] } if defined $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[2] 0 0 0
1073 0 });
1074 0 DOWNLOAD: for my $u (@updates) {
1075  
1076 0 ▶ $forker->start and next DOWNLOAD;
Branch: 1 branch
BranchTrueFalseTotal
$forker->start and next DOWNLOAD 0 0 0
1077  
1078 0 my ($name, $skip) = @$u;
1079 0 my $feed = $self->{ Feeds }{ $name };
1080  
1081 0 ▶ if ($feed->respect_skip and !$self->{ Unconditional } and $skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feed->respect_skip and not $self->{"Unconditional"} and $skip) 0 0 0
Condition0%0/6
$feed->respect_skip and not $self->{"Unconditional"} and $skip
!ll&&!rl&&r
000
$feed->respect_skip and not $self->{"Unconditional"}
!ll&&!rl&&r
000
MC/DC0%0/3
$feed->respect_skip and not $self->{"Unconditional"} and $skip
$feed->respect_skip not $self->{"Unconditional"} $skip
Truth table0%0/4
A and not(B) and C
A= $feed->respect_skipB= not $self->{"Unconditional"}C= $skip
ABCresult
0XX0
10X0
1100
1111
1082 0 say "Skipping $name";
1083 0 $forker->finish;
1084 0 last;
1085 }
1086  
1087 0 ▶ if ($feed->respect_skip and !$self->{ Unconditional } and !$feed->can_we_retry) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feed->respect_skip and not $self->{"Unconditional"} and not $feed->can_we_retry) 0 0 0
Condition0%0/6
$feed->respect_skip and not $self->{"Unconditional"} and not $feed->can_we_retry
!ll&&!rl&&r
000
$feed->respect_skip and not $self->{"Unconditional"}
!ll&&!rl&&r
000
MC/DC0%0/3
$feed->respect_skip and not $self->{"Unconditional"} and not $feed->can_we_retry
$feed->respect_skip not $self->{"Unconditional"} not $feed->can_we_retry
Truth table0%0/4
A and not(B) and not(C)
A= $feed->respect_skipB= not $self->{"Unconditional"}C= not $feed->can_we_retry
ABCresult
0XX0
10X0
1100
1111
1088 0 say "Skipping $name; performed too many requests";
1089 0 $forker->finish;
1090 0 last;
1091 }
1092  
1093 0 my $changed = 0;
1094  
1095 0 ▶ my $oldmod = -f $feed->path ? (stat($feed->path))[9] : 0;
Branch: 1 branch
BranchTrueFalseTotal
-f $feed->path ? : 0 0 0
1096  
1097 0 eval { $self->_get_feed($feed) };
1098  
1099 0 ▶ if ($@ ne '' or not -f $feed->path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne '' or not -f $feed->path) { } 0 0 0
Condition0%0/3
$@ ne "" or not -f $feed->path
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ ne "" or not -f $feed->path
$@ ne "" not -f $feed->path
Truth table0%0/3
A or not(B)
A= $@ ne ""B= not -f $feed->path
ABresult
1X1
011
000
1100 0 ▶ my $e = $@ || 'unknown error';
Condition0%0/2
$@ || 'unknown error'
l!l
00
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
1101 0 chomp $e;
1102 0 $self->err(sprintf "Failed to fetch %s: %s", $feed->feed, $e);
1103 } else {
1104 0 printf "Fetched %s\n", $feed->feed;
1105 0 my $newmod = (stat($feed->path))[9];
1106 0 $changed = $newmod != $oldmod;
1107 }
1108  
1109 0 ▶ if ($self->{ HardReload }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'HardReload'}) { } 0 0 0
1110 0 $forker->finish(0, \$name);
1111 } else {
1112 0 ▶ $forker->finish(0, $changed ? \$name : undef);
Branch: 1 branch
BranchTrueFalseTotal
$changed ? : 0 0 0
1113 }
1114  
1115 }
1116  
1117 0 $forker->wait_all_children;
1118  
1119 0 my %feed_updates;
1120  
1121 0 for my $c (@change) {
1122  
1123 0 my $new = eval {
1124 0 ▶ if ($self->{ HardReload }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"HardReload"}) 0 0 0
1125 0 $self->{ DB }->del_feeds($c);
1126 }
1127 0 $self->{ DB }->load_feed($self->{ Feeds }{ $c });
1128 };
1129  
1130 0 ▶ if ($@ ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne "") 0 0 0
1131 0 my $e = $@;
1132 0 chomp $e;
1133 0 $self->err("Error updating $c: $e, skipping");
1134 0 next;
1135 }
1136  
1137 0 ▶ next if $new == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $new == 0 0 0 0
1138 0 $feed_updates{ $c } = $new;
1139  
1140 }
1141  
1142 0 ▶ if (%feed_updates) {
Branch: 1 branch
BranchTrueFalseTotal
if (%feed_updates) { } 0 0 0
1143 0 for my $k (sort keys %feed_updates) {
1144 0 say "$k: $feed_updates{ $k } new posts";
1145 }
1146 } else {
1147 0 say "No new posts";
1148 }
1149  
1150 0 return 1;
1151  
1152 }
1153  
1154 0 ▶sub reload {
Subroutine reload: not called CC=16 SCAR=56.1
Pod documented
1155  
1156 0 my ($self) = @_;
1157  
1158 0 my @reloads;
1159  
1160 0 ▶ if (@{ $self->{ Args } }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'Args'};}) { } 0 0 0
1161 0 my %feedset;
1162 0 for my $arg (@{ $self->{ Args } }) {
1163 0 ▶ if (exists $self->{ Feeds }{ $arg }) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'Feeds'}{$arg}) { } 0 0 0
elsif (exists $self->{'Groups'}{$arg}) { } 0 0 0
1164 0 $feedset{ $arg } = 1;
1165 } elsif (exists $self->{ Groups }{ $arg }) {
1166 0 for my $k (@{ $self->{ Groups }{ $arg }->feeds }) {
1167 0 $feedset{ $k } = 1;
1168 }
1169 } else {
1170 0 warn "'$arg' is not the name of a feed or feed group, skipping\n";
1171 }
1172 }
1173  
1174 0 for my $f (keys %feedset) {
1175 0 ▶ if (-f $self->{ Feeds }{ $f }->path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $self->{'Feeds'}{$f}->path) { } 0 0 0
1176 0 push @reloads, $f;
1177 } else {
1178 0 $self->err("'$f' does not have a local feed file, skipping");
1179 }
1180 }
1181  
1182 } else {
1183 @reloads =
1184 0 grep { -f $self->{ Feeds }{ $_ }->path }
1185 0 keys %{ $self->{ Feeds } };
1186 }
1187  
1188 0 ▶ unless (@reloads) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@reloads) 0 0 0
1189 0 say "No feeds to reload";
1190 0 return 1;
1191 }
1192  
1193 0 my %feed_updates;
1194  
1195 0 for my $r (@reloads) {
1196  
1197 0 my $new = eval {
1198 0 ▶ if ($self->{ HardReload }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"HardReload"}) 0 0 0
1199 0 $self->{ DB }->del_feeds($r);
1200 }
1201 0 $self->{ DB }->load_feed($self->{ Feeds }{ $r });
1202 };
1203  
1204 0 ▶ unless (defined $new) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new) 0 0 0
1205 0 my $e = $@;
1206 0 chomp $e;
1207 0 ▶ if ($e ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($e ne '') { } 0 0 0
1208 0 $self->err("Failed to reload $r: $e, skipping");
1209 } else {
1210 0 $self->err("Failed to reload $r, skipping");
1211 }
1212 0 next;
1213 }
1214  
1215 0 ▶ next if $new == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $new == 0 0 0 0
1216 0 $feed_updates{ $r } = $new;
1217  
1218 }
1219  
1220 0 ▶ if (%feed_updates) {
Branch: 1 branch
BranchTrueFalseTotal
if (%feed_updates) { } 0 0 0
1221 0 for my $k (sort keys %feed_updates) {
1222 0 say "$k: $feed_updates{ $k } new posts";
1223 }
1224 } else {
1225 0 say "No new posts";
1226 }
1227  
1228 0 return 1;
1229  
1230 }
1231  
1232 0 ▶sub read_post {
Subroutine read_post: not called CC=14 SCAR=53.5
Pod documented
1233  
1234 0 my ($self) = @_;
1235  
1236 0 my $feed_name = shift @{ $self->{ Args} };
1237  
1238 0 ▶ unless (defined $feed_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $feed_name) 0 0 0
1239 0 die "'$self->{ Cmd }' requires a feed name as argument\n";
1240 }
1241  
1242 0 ▶ unless (exists $self->{ Feeds }{ $feed_name }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"Feeds"}{$feed_name}) 0 0 0
1243 0 die "'$feed_name' is not the name of a feed\n";
1244 }
1245  
1246 0 my $id = shift @{ $self->{ Args } };
1247  
1248 0 my $post;
1249  
1250 0 ▶ if (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) { } 0 0 0
1251 0 ▶ if ($id !~ /^-?\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id =~ /^-?\d+$/u) 0 0 0
1252 0 die "Post ID must be an integar\n";
1253 }
1254 0 $post = $self->{ DB }->post($feed_name, $id);
1255 0 ▶ unless (defined $post) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $post) 0 0 0
1256 0 die "'$feed_name:$id' does not exist\n";
1257 }
1258 } else {
1259 0 $post = $self->{ DB }->first_unread($feed_name);
1260 0 ▶ unless (defined $post) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $post) 0 0 0
1261 0 say "$feed_name has no unread posts, please manually specify a post ID";
1262 0 return 1;
1263 }
1264 }
1265  
1266 0 $self->{ ReadFmt } = _rm_color_codes($self->{ ReadFmt });
1267  
1268 0 my $fmt = do {
1269 0 my %fmt_codes = %POST_FMT_CODES;
1270 0 for my $f (keys %fmt_codes) {
1271 0 ▶ next if $f eq 'P';
Branch: 1 branch
BranchTrueFalseTotal
if $f eq "P" 0 0 0
1272 0 ▶ $fmt_codes{ $f } = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1273 0 escape_html($POST_FMT_CODES{ $f }->($_[0]))
1274 0 };
1275 }
1276 0 _fmt($self->{ ReadFmt }, \%fmt_codes);
1277 };
1278  
1279 0 my $dump;
1280  
1281 0 ▶ if ($self->{ ReadHtml }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ReadHtml'}) { } 0 0 0
1282  
1283 0 $dump = $fmt->($post);
1284  
1285 } else {
1286  
1287 0 my ($tmp_html_fh, $tmp_html_nm) = tempfile(UNLINK => 1);
1288 0 print { $tmp_html_fh } $fmt->($post);
1289 0 close $tmp_html_fh;
1290  
1291 0 $dump = lynx_dump($tmp_html_nm, width => $self->{ LineWidth });
1292  
1293 }
1294  
1295  
1296 0 ▶ if ($self->{ Stdout }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'Stdout'}) { } 0 0 0
1297  
1298 0 say $dump;
1299  
1300 } else {
1301  
1302 0 my ($tmp_lynx_fh, $tmp_lynx_nm) = tempfile(UNLINK => 1);
1303 0 print { $tmp_lynx_fh } $dump;
1304 0 close $tmp_lynx_fh;
1305  
1306 0 system "$self->{ Pager } $tmp_lynx_nm";
1307  
1308 0 ▶ unless ($? >> 8 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($? >> 8 == 0) 0 0 0
1309 0 die "Failed to run less on $tmp_lynx_nm\n";
1310 }
1311  
1312 }
1313  
1314 0 ▶ unless ($self->{ NoMark }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"NoMark"}) 0 0 0
1315 $self->{ DB }->mark('read', $feed_name, $post->{ nossid })
1316 0 ▶ or die "Failed to mark '$feed_name:$post->{ nossid }' as read";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"DB"}->mark("read", $feed_name, $post->{"nossid"}) or die qq[Failed to mark '${feed_name}:$post->{"nossid"}' as read] 0 0 0
1317 }
1318  
1319 0 return 1;
1320  
1321  
1322 }
1323  
1324 0 ▶sub open_post {
Subroutine open_post: not called CC=14 SCAR=53.5
Pod documented
1325  
1326 0 my ($self) = @_;
1327  
1328 0 my $feed_name = shift @{ $self->{ Args} };
1329  
1330 0 ▶ unless (defined $feed_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $feed_name) 0 0 0
1331 0 die "'open' requires a feed name as argument\n";
1332 }
1333  
1334 0 ▶ unless (exists $self->{ Feeds }{ $feed_name }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"Feeds"}{$feed_name}) 0 0 0
1335 0 die "'$feed_name' is not the name of a feed\n";
1336 }
1337  
1338 0 my $id = shift @{ $self->{ Args } };
1339  
1340 0 my $post;
1341 my $url;
1342  
1343 0 ▶ if (not defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $id) { } 0 0 0
1344 0 my $feed_info = $self->{ DB }->feed($feed_name);
1345 0 ▶ if (not defined $feed_info) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $feed_info) 0 0 0
1346 0 die "$feed_name does not exist in noss's database, perhaps try running the update command?\n";
1347 }
1348 0 $url = $feed_info->{ link };
1349 0 ▶ if (not defined $url) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $url) 0 0 0
1350 0 die "$feed_name does not have a homepage URL\n";
1351 }
1352 } else {
1353 0 ▶ if ($id !~ /^-?\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id =~ /^-?\d+$/u) 0 0 0
1354 0 die "Post ID must be an integar\n";
1355 }
1356 0 $post = $self->{ DB }->post($feed_name, $id);
1357 0 ▶ if (not defined $post) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $post) 0 0 0
1358 0 die "'$feed_name:$id' does not exist\n";
1359 }
1360 0 $url = $post->{ link };
1361 0 ▶ if (not defined $url) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $url) 0 0 0
1362 0 die "Cannot open $feed_name:$id: Has no post URL\n";
1363 }
1364 }
1365  
1366 0 ▶ my $browser = $self->{ Feeds }{ $feed_name }->open_cmd // $self->{ Browser };
Condition0%0/3
$self->{"Feeds"}{$feed_name}->open_cmd // $self->{"Browser"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Feeds"}{$feed_name}->open_cmd // $self->{"Browser"}
$self->{"Feeds"}{$feed_name}->open_cmd $self->{"Browser"}
Truth table0%0/3
A // B
A= $self->{"Feeds"}{$feed_name}->open_cmdB= $self->{"Browser"}
ABresult
1X1
011
000
1367 0 system "$browser $url";
1368  
1369 0 ▶ unless ($? >> 8 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($? >> 8 == 0) 0 0 0
1370 0 die "Failed to open $url with $browser\n";
1371 }
1372  
1373 0 ▶ if (defined $id and not $self->{ NoMark }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and not $self->{"NoMark"}) 0 0 0
Condition0%0/3
defined $id and not $self->{"NoMark"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $id and not $self->{"NoMark"}
defined $id not $self->{"NoMark"}
Truth table0%0/3
A and not(B)
A= defined $idB= not $self->{"NoMark"}
ABresult
0X0
100
111
1374 $self->{ DB }->mark('read', $feed_name, $post->{ nossid })
1375 0 ▶ or die "Failed to mark '$feed_name:$id' as read";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"DB"}->mark("read", $feed_name, $post->{"nossid"}) or die "Failed to mark '${feed_name}:${id}' as read" 0 0 0
1376 }
1377  
1378 0 return 1;
1379  
1380 }
1381  
1382 0 ▶sub cat {
Subroutine cat: not called CC=1 SCAR=6.9
Pod documented
1383  
1384 0 my ($self) = @_;
1385  
1386 0 $self->{ Stdout } = 1;
1387 0 $self->read_post;
1388  
1389 0 return 1;
1390  
1391 }
1392  
1393 0 ▶sub look {
Subroutine look: not called CC=16 SCAR=56.1
Pod documented
1394  
1395 0 my ($self) = @_;
1396  
1397 0 my @feeds;
1398  
1399 0 ▶ if (@{ $self->{ Args } }) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$self->{'Args'};}) { } 0 0 0
elsif ($self->{'ShowHidden'}) { } 0 0 0
1400 0 my %feedset;
1401 0 for my $arg (@{ $self->{ Args } }) {
1402 0 ▶ if (exists $self->{ Feeds }{ $arg }) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'Feeds'}{$arg}) { } 0 0 0
elsif (exists $self->{'Groups'}{$arg}) { } 0 0 0
1403 0 $feedset{ $arg } = 1;
1404 } elsif (exists $self->{ Groups }{ $arg }) {
1405 0 for my $k (@{ $self->{ Groups }{ $arg }->feeds }) {
1406 0 $feedset{ $k } = 1;
1407 }
1408 } else {
1409 0 warn "'$arg' is not the name of a feed or feed group, skipping\n";
1410 }
1411 }
1412 0 @feeds = keys %feedset;
1413 } elsif ($self->{ ShowHidden }) {
1414 0 @feeds = keys %{ $self->{ Feeds } };
1415 } else {
1416 @feeds =
1417 0 grep { not $self->{ Feeds }{ $_ }->hidden }
1418 0 keys %{ $self->{ Feeds } };
1419 }
1420  
1421 my $titlerx =
1422 defined $self->{ Title }
1423 ? _arg2rx($self->{ Title })
1424 0 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'Title'} ? : 0 0 0
1425 0 my @contrx = map { _arg2rx($_) } @{ $self->{ Content } };
1426  
1427 0 ▶ unless (@feeds) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@feeds) 0 0 0
1428 0 return 1;
1429 }
1430  
1431 0 ▶ my $idlen = length($self->{ DB }->largest_id(@feeds) // 0);
Condition0%0/2
$self->{"DB"}->largest_id(@feeds) // 0
l!l
00
MC/DC0%0/1
$self->{"DB"}->largest_id(@feeds) // 0
$self->{"DB"}->largest_id(@feeds)
Truth table0%0/2
A
A= $self->{"DB"}->largest_id(@feeds)
Aresult
11
00
1432 0 ▶ my $feedlen = max(map { length } @feeds) // 1;
Condition0%0/2
&max(map({length $_;} @feeds)) // 1
l!l
00
MC/DC0%0/1
&max(map({length $_;} @feeds)) // 1
&max(map({length $_;} @feeds))
Truth table0%0/2
A
A= &max(map({length $_;} @feeds))
Aresult
11
00
1433  
1434 0 my $readfmt = do {
1435 0 my $fmt = $self->{ ListFmt };
1436 0 ▶ if (not defined $fmt) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fmt) 0 0 0
1437 0 $fmt = sprintf "<7>%%s <6>%%-%df <3>%%%di <8>%%t", $feedlen, $idlen;
1438 }
1439 0 ▶ if (!$self->{ UseColor }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"UseColor"}) 0 0 0
1440 0 $fmt = _rm_color_codes($fmt);
1441 }
1442 0 _fmt($fmt, \%POST_FMT_CODES, $self->{ ColorMap });
1443 };
1444 0 my $unreadfmt = do {
1445 0 my $fmt = $self->{ ListUnreadFmt };
1446 0 ▶ if (not defined $fmt) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fmt) 0 0 0
1447 0 ▶ if (defined $self->{ ListFmt }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'ListFmt'}) { } 0 0 0
1448 0 $fmt = $self->{ ListFmt };
1449 } else {
1450 0 $fmt = sprintf "<15>%%s <14>%%-%df <11>%%%di <16>%%t", $feedlen, $idlen;
1451 }
1452 }
1453 0 ▶ if (!$self->{ UseColor }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"UseColor"}) 0 0 0
1454 0 $fmt = _rm_color_codes($fmt);
1455 }
1456 0 _fmt($fmt, \%POST_FMT_CODES, $self->{ ColorMap });
1457 };
1458  
1459 0 ▶ my $callback = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1460 0 ▶ print $_[0]->{ status } eq 'read'
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'status'} eq 'read' ? : 0 0 0
1461 ? $readfmt->($_[0])
1462 : $unreadfmt->($_[0]);
1463 0 };
1464  
1465 $self->{ DB }->look(
1466 title => $titlerx,
1467 feeds => \@feeds,
1468 status => $self->{ Status },
1469 0 tags => [ map { qr/\Q$_\E/i } @{ $self->{ Tags } } ],
1470 content => \@contrx,
1471 order => $self->{ Sort },
1472 reverse => $self->{ Reverse },
1473 limit => $self->{ ListLimit },
1474 0 callback => $callback,
1475 );
1476  
1477 0 return 1;
1478  
1479 }
1480  
1481 0 ▶sub unread {
Subroutine unread: not called CC=1 SCAR=6.9
Pod documented
1482  
1483 0 my ($self) = @_;
1484  
1485 0 $self->{ Status } = 'unread';
1486  
1487 0 $self->look;
1488  
1489 0 return 1;
1490  
1491 }
1492  
1493 0 ▶sub mark {
Subroutine mark: not called CC=17 SCAR=57.2
Pod documented
1494  
1495 0 my ($self) = @_;
1496  
1497 0 my $status = shift @{ $self->{ Args } };
1498  
1499 0 ▶ unless (defined $status) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $status) 0 0 0
1500 0 die "'mark' requires a status as argument\n";
1501 }
1502  
1503 0 ▶ unless ($status =~ /^(un)?read$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($status =~ /^(un)?read$/u) 0 0 0
1504 0 die "status must either be 'read' or 'unread'\n";
1505 }
1506  
1507 0 my @feeds;
1508 my @posts;
1509  
1510 0 my $targ = shift @{ $self->{ Args } };
1511  
1512 0 ▶ if (not defined $targ and not $self->{ MarkAll }) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $targ || $self->{'MarkAll'}) { } 0 0 0
elsif (defined $targ and $self->{'MarkAll'}) { } 0 0 0
Condition0%0/3
defined $targ || $self->{'MarkAll'}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $targ || $self->{'MarkAll'}
defined $targ $self->{'MarkAll'}
Truth table0%0/3
A || B
A= defined $targB= $self->{'MarkAll'}
ABresult
1X1
011
000
1513 0 die "mark requires a feed name or group as argument\n";
1514 ▶ } elsif (defined $targ and $self->{ MarkAll }) {
Condition0%0/3
defined $targ and $self->{"MarkAll"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $targ and $self->{"MarkAll"}
defined $targ $self->{"MarkAll"}
Truth table0%0/3
A and B
A= defined $targB= $self->{"MarkAll"}
ABresult
0X0
100
111
1515 0 die "mark --all should not be given a feed name or group as argument\n";
1516 }
1517  
1518 0 ▶ if ($self->{ MarkAll }) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'MarkAll'}) { } 0 0 0
elsif (exists $self->{'Groups'}{$targ}) { } 0 0 0
elsif (exists $self->{'Feeds'}{$targ}) { } 0 0 0
1519 0 @feeds = keys %{ $self->{ Feeds } };
1520 0 @posts = ();
1521 } elsif (exists $self->{ Groups }{ $targ }) {
1522 0 @feeds = @{ $self->{ Groups }{ $targ }->feeds };
1523 0 @posts = ();
1524 } elsif (exists $self->{ Feeds }{ $targ }) {
1525 0 @feeds = ($targ);
1526 0 for my $p (@{ $self->{ Args } }) {
1527 0 ▶ unless ($p =~ /^(?<from>-?[0-9]+)(-(?<to>-?[0-9]+))?$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($p =~ /^(?<from>-?[0-9]+)(-(?<to>-?[0-9]+))?$/u) 0 0 0
1528 0 die "'$p' is not a post argument\n";
1529 }
1530 0 my ($from, $to) = @+{ qw(from to) };
1531 0 ▶ $to //= $from;
Condition0%0/3
$to //= $from
l!l&&r!l&&!r
000
MC/DC0%0/2
$to //= $from
$to $from
Truth table0%0/3
A //= B
A= $toB= $from
ABresult
1X1
011
000
1532 0 ▶ if ($from < 0 xor $to < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from < 0 xor $to < 0) 0 0 0
Condition0%0/4
$from < 0 xor $to < 0
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
$from < 0 xor $to < 0
$from < 0 $to < 0
Truth table0%0/4
A xor B
A= $from < 0B= $to < 0
ABresult
110
101
011
000
1533 0 die "cannot mix negative and positive post arguments\n";
1534 }
1535 0 ▶ push @posts, (
Branch: 1 branch
BranchTrueFalseTotal
$from < $to ? : 0 0 0
1536 $from < $to
1537 ? ($from .. $to)
1538 : ($to .. $from)
1539 );
1540 }
1541 } else {
1542 0 die "'$targ' is not the name of a feed or group\n";
1543 }
1544  
1545 0 my $num = 0;
1546  
1547 0 for my $f (@feeds) {
1548 0 my $n = $self->{ DB }->mark($status, $f, @posts);
1549 0 $num += $n;
1550 }
1551  
1552 0 say "$num posts updated";
1553  
1554 0 return 1;
1555  
1556 }
1557  
1558 0 ▶sub post {
Subroutine post: not called CC=7 SCAR=40.3
Pod documented
1559  
1560 0 my ($self) = @_;
1561  
1562 0 my $feed = shift @{ $self->{ Args } };
1563 0 my $id = shift @{ $self->{ Args } };
1564  
1565 0 ▶ if (not defined $feed or not defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $feed and defined $id) 0 0 0
Condition0%0/3
defined $feed and defined $id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $feed and defined $id
defined $feed defined $id
Truth table0%0/3
A and B
A= defined $feedB= defined $id
ABresult
0X0
100
111
1566 0 die "post requires a feed name and post ID as argument\n";
1567 }
1568  
1569 0 ▶ unless (exists $self->{ Feeds }{ $feed }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"Feeds"}{$feed}) 0 0 0
1570 0 die "'$feed' is not the name of a feed\n";
1571 }
1572  
1573 0 ▶ unless ($id =~ /^-?\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id =~ /^-?\d+$/u) 0 0 0
1574 0 die "Post ID must be an integar\n";
1575 }
1576  
1577 0 my $post = $self->{ DB }->post($feed, $id);
1578  
1579 0 ▶ unless (defined $post) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $post) 0 0 0
1580 0 die "'$feed:$id' does not exist\n";
1581 }
1582  
1583 0 ▶ if (!$self->{ UseColor }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"UseColor"}) 0 0 0
1584 0 $self->{ PostFmt } = _rm_color_codes($self->{ PostFmt });
1585 }
1586  
1587 my $fmt = _fmt(
1588 $self->{ PostFmt },
1589 \%POST_FMT_CODES,
1590 $self->{ ColorMap }
1591 0 );
1592  
1593 0 print $fmt->($post);
1594  
1595 0 return 1;
1596  
1597 }
1598  
1599 0 ▶sub feeds {
Subroutine feeds: not called CC=10 SCAR=47.0
Pod documented
1600  
1601 0 my ($self) = @_;
1602  
1603 0 my @feeds;
1604  
1605 0 ▶ if (@{ $self->{ Args } }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'Args'};}) { } 0 0 0
1606 0 my %feedset;
1607 0 for my $a (@{ $self->{ Args } }) {
1608 0 ▶ if (exists $self->{ Feeds }{ $a }) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'Feeds'}{$a}) { } 0 0 0
elsif (exists $self->{'Groups'}{$a}) { } 0 0 0
1609 0 $feedset{ $a } = 1;
1610 } elsif (exists $self->{ Groups }{ $a }) {
1611 0 for my $f (@{ $self->{ Groups }{ $a }->feeds }) {
1612 0 $feedset{ $f } = 1;
1613 }
1614 } else {
1615 0 warn "'$a' is not the name of a feed or group, skipping\n";
1616 }
1617 }
1618 0 @feeds = sort keys %feedset;
1619 } else {
1620 0 @feeds = sort keys %{ $self->{ Feeds } };
1621 }
1622  
1623 0 ▶ unless (@feeds) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@feeds) 0 0 0
1624 0 die "No feeds can be printed\n";
1625 }
1626  
1627 0 ▶ if (!$self->{ UseColor }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"UseColor"}) 0 0 0
1628 0 $self->{ FeedsFmt } = _rm_color_codes($self->{ FeedsFmt });
1629 }
1630  
1631 0 my $cb = _fmt($self->{ FeedsFmt }, \%FEED_FMT_CODES, $self->{ ColorMap });
1632  
1633 0 for my $n (@feeds) {
1634  
1635 0 my $f = $self->{ DB }->feed($n, post_info => 1);
1636  
1637 $f //= {
1638 nossname => $self->{ Feeds }{ $n }->name,
1639 0 ▶ nosslink => $self->{ Feeds }{ $n }->feed,
Condition0%0/2
$f //= {"nossname", $self->{"Feeds"}{$n}->name, "nosslink", $self->{"Feeds"}{$n}->feed}
l!l
00
MC/DC0%0/1
$f //= {"nossname", $self->{"Feeds"}{$n}->name, "nosslink", $self->{"Feeds"}{$n}->feed}
$f
Truth table0%0/2
A
A= $f
Aresult
11
00
1640 };
1641  
1642 0 print $cb->($f);
1643  
1644 }
1645  
1646 0 return 1;
1647  
1648 }
1649  
1650 0 ▶sub groups {
Subroutine groups: not called CC=10 SCAR=47.0
Pod documented
1651  
1652 0 my ($self) = @_;
1653  
1654 0 my @groups;
1655  
1656 0 ▶ if (@{ $self->{ Args } }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'Args'};}) { } 0 0 0
1657 0 for my $a (@{ $self->{ Args } }) {
1658 0 ▶ if (exists $self->{ Groups }{ $a }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'Groups'}{$a}) { } 0 0 0
1659 0 push @groups, $a;
1660 } else {
1661 0 warn "'$a' is not the name of a feed group, skipping\n";
1662 }
1663 }
1664 } else {
1665 0 @groups = sort keys %{ $self->{ Groups } };
1666 }
1667  
1668 0 ▶ unless (@groups) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@groups) 0 0 0
1669 0 die "No feed groups can be printed\n";
1670 }
1671  
1672 0 for my $i (0 .. $#groups) {
1673  
1674 my @feeds =
1675 0 grep { exists $self->{ Feeds }{ $_ } }
1676 0 @{ $self->{ Groups }{ $groups[$i] }->feeds };
1677  
1678 0 ▶ @feeds = ('(none)') unless @feeds;
Branch: 1 branch
BranchTrueFalseTotal
unless @feeds 0 0 0
1679  
1680 0 say $groups[$i];
1681  
1682 0 ▶ unless ($self->{ Brief }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"Brief"}) 0 0 0
1683 0 for my $f (@feeds) {
1684 0 say " $f";
1685 }
1686 0 ▶ print "\n" unless $i == $#groups;
Branch: 1 branch
BranchTrueFalseTotal
unless $i == $#groups 0 0 0
1687 }
1688  
1689 }
1690  
1691 0 return 1;
1692  
1693 }
1694  
1695 0 ▶sub clean {
Subroutine clean: not called CC=10 SCAR=47.0
Pod documented
1696  
1697 0 my ($self) = @_;
1698  
1699 0 for my $f (dir($self->{ FeedDir })) {
1700  
1701 0 ▶ next unless $f =~ /\.feed$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $f =~ /\.feed$/u 0 0 0
1702  
1703 0 my $feed = (fileparse($f, qr/\.[^.]*/))[0];
1704  
1705 0 ▶ unless (exists $self->{ Feeds }{ $feed }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"Feeds"}{$feed}) 0 0 0
1706 0 ▶ unlink $f or warn "Failed to unlink $f\n";
Branch: 1 branch
BranchTrueFalseTotal
unlink $f or warn "Failed to unlink $f\n" 0 0 0
1707 }
1708  
1709 }
1710  
1711 0 for my $f (dir($self->{ EtagDir })) {
1712  
1713 0 ▶ next unless $f =~ /\.etag/;
Branch: 1 branch
BranchTrueFalseTotal
unless $f =~ /\.etag/u 0 0 0
1714  
1715 0 my $feed = (fileparse($f, qr/\.[^.]*/))[0];
1716  
1717 0 ▶ unless (exists $self->{ Feeds }{ $feed }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"Feeds"}{$feed}) 0 0 0
1718 0 ▶ unlink $f or warn "Failed to unlink $f\n";
Branch: 1 branch
BranchTrueFalseTotal
unlink $f or warn "Failed to unlink $f\n" 0 0 0
1719 }
1720  
1721 }
1722  
1723 0 my @dbfeeds = $self->{ DB }->feeds;
1724  
1725 my @clean =
1726 0 grep { not exists $self->{ Feeds }{ $_ } }
1727 0 map { $_->{ nossname } }
1728 0 $self->{ DB }->feeds;
1729  
1730 0 ▶ if (@clean) {
Branch: 1 branch
BranchTrueFalseTotal
if (@clean) 0 0 0
1731 0 $self->{ DB }->del_feeds(@clean);
1732 }
1733  
1734 0 $self->{ DB }->vacuum;
1735  
1736 0 return 1;
1737  
1738 }
1739  
1740 0 ▶sub discover {
Subroutine discover: not called CC=5 SCAR=34.0
Pod documented
1741  
1742 0 my ($self) = @_;
1743  
1744 0 my $url = shift @{ $self->{ Args } };
1745 0 ▶ if (not defined $url) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $url) 0 0 0
1746 0 die "discover requires a URL as argument\n";
1747 }
1748  
1749 0 my $tmp = do {
1750 0 my ($h, $p) = tempfile(UNLINK => 1);
1751 0 close $h;
1752 0 $p;
1753 };
1754  
1755 my ($rt, undef, undef) = curl(
1756 $url, $tmp,
1757 user_agent => $self->{ UserAgent },
1758 limit_rate => $self->{ RateLimit },
1759 timeout => $self->{ Timeout },
1760 fail => 1,
1761 proxy => $self->{ Proxy },
1762 proxy_user => $self->{ ProxyUser },
1763 0 redirect => 1,
1764 );
1765  
1766 0 ▶ if ($rt != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rt != 0) 0 0 0
1767 0 die sprintf "Failed to curl %s: %s\n", $url, curl_error($rt);
1768 }
1769  
1770 0 my @feeds = discover_feeds($tmp);
1771 0 ▶ if (!@feeds) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@feeds) 0 0 0
1772 0 say "No feeds found in $url";
1773 0 return 1;
1774 }
1775  
1776 0 @feeds = uniq sort map { resolve_url($_, $url) } @feeds;
1777 0 for my $f (@feeds) {
1778 0 say $f;
1779 }
1780  
1781 0 return 1;
1782  
1783 }
1784  
1785 0 ▶sub export_opml {
Subroutine export_opml: not called CC=5 SCAR=34.0
Pod documented
1786  
1787 0 my ($self) = @_;
1788  
1789 0 my $to = shift @{ $self->{ Args } };
1790  
1791 0 my @feeds;
1792  
1793 0 for my $f (values %{ $self->{ Feeds } }) {
1794 0 ▶ next if $f->feed =~ /^(file|shell):\/\// and !$self->{ ExportSpec };
Branch: 1 branch
BranchTrueFalseTotal
if $f->feed =~ m[^(file|shell)://]u and not $self->{"ExportSpec"} 0 0 0
Condition0%0/3
$f->feed =~ m[^(file|shell)://]u and not $self->{"ExportSpec"}
!ll&&!rl&&r
000
MC/DC0%0/2
$f->feed =~ m[^(file|shell)://]u and not $self->{"ExportSpec"}
$f->feed =~ m[^(file|shell)://]u not $self->{"ExportSpec"}
Truth table0%0/3
A and not(B)
A= $f->feed =~ m[^(file|shell)://]uB= not $self->{"ExportSpec"}
ABresult
0X0
100
111
1795 push @feeds, {
1796 title => $f->name,
1797 xml_url => $f->feed,
1798 0 groups => [ map { $_->name } @{ $f->groups } ],
1799 };
1800 }
1801  
1802 0 my $opml = WWW::Noss::OPML->from_perl(
1803 title => "$PRGNAM Feed List",
1804 feeds => \@feeds,
1805 );
1806  
1807 0 ▶ if (defined $to) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to) { } 0 0 0
1808 0 $opml->to_file($to, folders => !$self->{ NoGroups });
1809 0 say "Wrote OPML to $to";
1810 } else {
1811 0 $opml->to_fh(*STDOUT, folders => !$self->{ NoGroups });
1812 }
1813  
1814 0 return 1;
1815  
1816 }
1817  
1818 # TODO: --merge option?
1819 0 ▶sub import_opml {
Subroutine import_opml: not called CC=14 SCAR=53.5
Pod documented
1820  
1821 0 my ($self) = @_;
1822  
1823 0 my $file = shift @{ $self->{ Args } };
1824  
1825 0 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
1826 0 die "import requires an OPML file as argument\n";
1827 }
1828  
1829 0 my $to = shift @{ $self->{ Args } };
1830  
1831 0 my $json = {
1832 default => {},
1833 groups => {},
1834 feeds => {},
1835 };
1836  
1837 0 my $opml = WWW::Noss::OPML->from_xml($file);
1838  
1839 my %groupset =
1840 0 map { $_ =~ s/\W//gr => {} }
1841 0 ▶ map { @{ $_->{ groups } // [] } }
Condition0%0/2
$_->{"groups"} // []
l!l
00
MC/DC0%0/1
$_->{"groups"} // []
$_->{"groups"}
Truth table0%0/2
A
A= $_->{"groups"}
Aresult
11
00
1842 0 @{ $opml->feeds };
1843  
1844 0 for my $f (@{ $opml->feeds }) {
1845  
1846 0 my $name = $f->{ title } =~ s/\W//gr;
1847  
1848 0 ▶ if (exists $json->{ feeds }{ $name } and $f->{ xml_url } ne $json->{ feeds }{ $name }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $json->{"feeds"}{$name} and $f->{"xml_url"} ne $json->{"feeds"}{$name}) 0 0 0
Condition0%0/3
exists $json->{"feeds"}{$name} and $f->{"xml_url"} ne $json->{"feeds"}{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $json->{"feeds"}{$name} and $f->{"xml_url"} ne $json->{"feeds"}{$name}
exists $json->{"feeds"}{$name} $f->{"xml_url"} ne $json->{"feeds"}{$name}
Truth table0%0/3
A and B
A= exists $json->{"feeds"}{$name}B= $f->{"xml_url"} ne $json->{"feeds"}{$name}
ABresult
0X0
100
111
1849 0 warn "'$name' feed name conflict, $json->{ feeds }{ $name } will be lost\n";
1850 }
1851  
1852 0 ▶ if (exists $groupset{ $name }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $groupset{$name}) 0 0 0
1853 0 warn "'$name' group name conflict, $name group will be lost\n";
1854 0 delete $groupset{ $name };
1855 }
1856  
1857 0 $json->{ feeds }{ $name } = $f->{ xml_url };
1858  
1859 0 ▶ for my $g (@{ $f->{ groups } // [] }) {
Condition0%0/2
$f->{"groups"} // []
l!l
00
MC/DC0%0/1
$f->{"groups"} // []
$f->{"groups"}
Truth table0%0/2
A
A= $f->{"groups"}
Aresult
11
00
1860 0 $g =~ s/\W//g;
1861 0 ▶ next unless exists $groupset{ $g };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $groupset{$g} 0 0 0
1862 0 $groupset{ $g }->{ $name } = 1;
1863 }
1864  
1865 }
1866  
1867 0 ▶ unless ($self->{ NoGroups }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"NoGroups"}) 0 0 0
1868 0 for my $g (keys %groupset) {
1869 0 $json->{ groups }{ $g } = [ sort keys %{ $groupset{ $g } } ];
1870 }
1871 }
1872  
1873 0 my $json_obj = JSON->new->pretty->canonical;
1874  
1875 0 ▶ if (defined $to) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to) { } 0 0 0
1876 0 ▶ open my $fh, '>', $to
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $to or die "Failed to open $to for writing: $!\n" 0 0 0
1877 or die "Failed to open $to for writing: $!\n";
1878 0 print { $fh } $json_obj->encode($json);
1879 0 close $fh;
1880 0 say "Wrote JSON to $to";
1881 } else {
1882 0 print $json_obj->encode($json);
1883 }
1884  
1885 0 return 1;
1886  
1887 }
1888  
1889 0 ▶sub help {
Subroutine help: not called CC=3 SCAR=24.8
Pod documented
1890  
1891 0 my ($self) = @_;
1892  
1893 0 my $cmd = shift @{ $self->{ Args } };
1894  
1895 0 ▶ if (not defined $cmd) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cmd) 0 0 0
1896 0 pod2usage(
1897 -exitval => 'NOEXIT',
1898 -verbose => 99,
1899 -sections => [
1900 'NAME', 'SYNOPSIS', 'DESCRIPTION', 'COMMANDS',
1901 'GLOBAL OPTIONS', 'CONFIGURATION', 'ENVIRONMENT'
1902 ],
1903 -output => \*STDOUT,
1904 );
1905 0 return 1;
1906 }
1907  
1908 0 $cmd = lc $cmd;
1909  
1910 0 ▶ if (not exists $COMMANDS{ $cmd }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $COMMANDS{$cmd}) 0 0 0
1911 0 die "'$cmd' is not a command\n";
1912 }
1913  
1914 pod2usage(
1915 0 -exitval => 'NOEXIT',
1916 -verbose => 99,
1917 -sections => "COMMANDS/$cmd",
1918 -output => \*STDOUT,
1919 );
1920  
1921 0 return 1;
1922  
1923 }
1924  
1925 0 ▶sub init {
Subroutine init: not called CC=50 SCAR=78.4
Pod documented
1926  
1927 0 my ($class, @argv) = @_;
1928  
1929 # Handle NO_COLOR ourselves instead of Term::ANSIColor so that it can be
1930 # overridden by -C|--color.
1931 0 my $color_default = undef;
1932 0 ▶ if (exists $ENV{ NO_COLOR }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"NO_COLOR"}) 0 0 0
1933 0 ▶ $color_default = $ENV{ NO_COLOR } ne '' ? 0 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'NO_COLOR'} ne '' ? : 0 0 0
1934 0 delete $ENV{ NO_COLOR };
1935 }
1936  
1937 0 my $self = {
1938 Cmd => undef,
1939 Args => [],
1940 DataDir => undef,
1941 FeedDir => undef,
1942 EtagDir => undef,
1943 FeedFile => undef,
1944 ConfFile => undef,
1945 Feeds => {},
1946 Groups => {},
1947 DefaultGroup => undef,
1948 DB => undef,
1949 AutoClean => undef,
1950 TimeFmt => undef,
1951 UseColor => $color_default,
1952 ColorMap => { %COLOR_CODES },
1953 RetryDir => undef,
1954 # update
1955 NewOnly => 0,
1956 NonDefaults => 0,
1957 Forks => undef,
1958 Unconditional => 0,
1959 RateLimit => undef,
1960 UserAgent => undef,
1961 Timeout => undef,
1962 Proxy => undef,
1963 ProxyUser => undef,
1964 HardReload => 0, # reload, too
1965 # read
1966 Pager => undef,
1967 NoMark => 0, # open, too
1968 Stdout => 0,
1969 LineWidth => undef,
1970 ReadFmt => undef,
1971 ReadHtml => 0,
1972 # open
1973 Browser => undef,
1974 # look/unread
1975 Title => undef,
1976 Tags => [],
1977 Status => undef, # look only
1978 Content => [],
1979 Sort => undef,
1980 Reverse => 0,
1981 ListLimit => undef,
1982 ShowHidden => 0,
1983 ListFmt => undef,
1984 ListUnreadFmt => undef,
1985 # mark
1986 MarkAll => 0,
1987 # post
1988 PostFmt => undef,
1989 # feeds
1990 Brief => 0, # groups, too
1991 FeedsFmt => undef,
1992 # export/import
1993 NoGroups => 0,
1994 ExportSpec => 0,
1995 };
1996  
1997 0 Getopt::Long::config('bundling');
1998 0 Getopt::Long::config('pass_through');
1999 GetOptionsFromArray(\@argv,
2000 'config|c=s' => \$self->{ ConfFile },
2001 'data|D=s' => \$self->{ DataDir },
2002 'feeds|f=s' => \$self->{ FeedFile },
2003 0 ▶ 'autoclean|A:s' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
2004 0 ▶ if ($_[1] eq '' or $_[1] eq '1') {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[1] eq '' or $_[1] eq '1') { } 0 0 0
elsif ($_[1] eq '0') { } 0 0 0
Condition0%0/3
$_[1] eq "" or $_[1] eq 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[1] eq "" or $_[1] eq 1
$_[1] eq "" $_[1] eq 1
Truth table0%0/3
A or B
A= $_[1] eq ""B= $_[1] eq 1
ABresult
1X1
011
000
2005 0 $self->{ AutoClean } = 1;
2006 } elsif ($_[1] eq '0') {
2007 0 $self->{ AutoClean } = 0;
2008 } else {
2009 0 $self->{ AutoClean } = 1;
2010 0 unshift @argv, $_[1];
2011 }
2012 },
2013 'time-format|z=s' => \$self->{ TimeFmt },
2014 0 ▶ 'color|C:s' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
2015 0 ▶ if ($_[1] eq '' or $_[1] eq '1') {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[1] eq '' or $_[1] eq '1') { } 0 0 0
elsif ($_[1] eq '0') { } 0 0 0
Condition0%0/3
$_[1] eq "" or $_[1] eq 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[1] eq "" or $_[1] eq 1
$_[1] eq "" $_[1] eq 1
Truth table0%0/3
A or B
A= $_[1] eq ""B= $_[1] eq 1
ABresult
1X1
011
000
2016 0 $self->{ UseColor } = 1;
2017 } elsif ($_[1] eq '0') {
2018 0 $self->{ UseColor } = 0;
2019 } else {
2020 0 $self->{ UseColor } = 1;
2021 0 unshift @argv, $_[1];
2022 }
2023 },
2024 0 ▶ 'no-color' => sub { $self->{ UseColor } = 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2025 # update
2026 'new-only' => \$self->{ NewOnly },
2027 'non-defaults' => \$self->{ NonDefaults },
2028 'downloads=i' => \$self->{ Forks },
2029 'unconditional' => \$self->{ Unconditional },
2030 'limit-rate=s' => \$self->{ RateLimit },
2031 'user-agent=s' => \$self->{ UserAgent },
2032 'timeout=f' => \$self->{ Timeout },
2033 'proxy=s' => \$self->{ Proxy },
2034 'proxy-user=s' => \$self->{ ProxyUser },
2035 'hard' => \$self->{ HardReload },
2036 # read
2037 'pager=s' => \$self->{ Pager },
2038 'no-mark' => \$self->{ NoMark }, # open, too
2039 'stdout' => \$self->{ Stdout },
2040 'width=i' => \$self->{ LineWidth },
2041 'read-format=s' => \$self->{ ReadFmt },
2042 'html' => \$self->{ ReadHtml },
2043 # open
2044 'browser=s' => \$self->{ Browser },
2045 # look/unread
2046 'title=s' => \$self->{ Title },
2047 'tag=s' => $self->{ Tags },
2048 'status=s' => \$self->{ Status }, # look only
2049 'content=s' => $self->{ Content },
2050 'sort=s' => \$self->{ Sort },
2051 'reverse' => \$self->{ Reverse },
2052 'list-limit=i' => \$self->{ ListLimit },
2053 'hidden' => \$self->{ ShowHidden },
2054 0 ▶ 'list-format=s' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2055 0 $self->{ ListFmt } = $_[1];
2056 0 $self->{ ListUnreadFmt } = $_[1];
2057 },
2058 # mark
2059 'all' => \$self->{ MarkAll },
2060 # post
2061 'post-format=s' => \$self->{ PostFmt },
2062 # feeds
2063 'brief' => \$self->{ Brief }, # groups, too
2064 'feeds-format=s' => \$self->{ FeedsFmt },
2065 # export/import
2066 'no-groups' => \$self->{ NoGroups },
2067 'export-special' => \$self->{ ExportSpec },
2068 # misc
2069 0 ▶ 'help|h' => sub { _HELP(*STDOUT, 0) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2070 0 ▶ 'version|v' => sub { _VER(*STDOUT, 0) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
2071 0 ▶ '<>' => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
2072 0 ▶ if (not defined $self->{ Cmd } and $_[0] !~ /^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'Cmd'} || $_[0] =~ /^-/u) { } 0 0 0
Condition0%0/3
defined $self->{'Cmd'} || $_[0] =~ /^-/u
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $self->{'Cmd'} || $_[0] =~ /^-/u
defined $self->{'Cmd'} $_[0] =~ /^-/u
Truth table0%0/3
A || B
A= defined $self->{'Cmd'}B= $_[0] =~ /^-/u
ABresult
1X1
011
000
2073 0 $self->{ Cmd } = $_[0];
2074 } else {
2075 0 ▶ if ($_[0] =~ /^[\-0-9]+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0] =~ /^[\-0-9]+$/u) { } 0 0 0
elsif (not $_[0] =~ /^-/u) { } 0 0 0
2076 # So that negative post arguments (-1, -2, etc.) do not get
2077 # treated like CLI flags.
2078 0 push @{ $self->{ Args } }, $_[0];
2079 } elsif ($_[0] !~ /^-/) {
2080 0 push @{ $self->{ Args } }, $_[0];
2081 } else {
2082 0 warn "Unknown option: $_[0]\n";
2083 0 _HELP(*STDERR, 1);
2084 }
2085 }
2086 },
2087 0 ▶ ) or _HELP(*STDERR, 1);
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray(\@argv, "config|c=s", \$self->{"ConfFile"}, "data|D=s", \$self->{"DataDir"}, "feeds|f=s", \$self->{"FeedFile"}, "autoclean|A:s", sub { if ($_[1] eq "" or $_[1] eq 1) { $self->{"AutoClean"} = 1; } elsif ($_[1] eq 0) { $self->{"AutoClean"} = 0; } else { $self->{"AutoClean"} = 1; unshift @argv, $_[1]; } ; } , "time-format|z=s", \$self->{"TimeFmt"}, "color|C:s", sub { if ($_[1] eq "" or $_[1] eq 1) { $self->{"UseColor"} = 1; } elsif ($_[1] eq 0) { $self->{"UseColor"} = 0; } else { $self->{"UseColor"} = 1; unshift @argv, $_[1]; } ; } , "no-color", sub { $self->{"UseColor"} = 0; } , "new-only", \$self->{"NewOnly"}, "non-defaults", \$self->{"NonDefaults"}, "downloads=i", \$self->{"Forks"}, "unconditional", \$self->{"Unconditional"}, "limit-rate=s", \$self->{"RateLimit"}, "user-agent=s", \$self->{"UserAgent"}, "timeout=f", \$self->{"Timeout"}, "proxy=s", \$self->{"Proxy"}, "proxy-user=s", \$self->{"ProxyUser"}, "hard", \$self->{"HardReload"}, "pager=s", \$self->{"Pager"}, "no-mark", \$self->{"NoMark"}, "stdout", \$self->{"Stdout"}, "width=i", \$self->{"LineWidth"}, "read-format=s", \$self->{"ReadFmt"}, "html", \$self->{"ReadHtml"}, "browser=s", \$self->{"Browser"}, "title=s", \$self->{"Title"}, "tag=s", $self->{"Tags"}, "status=s", \$self->{"Status"}, "content=s", $self->{"Content"}, "sort=s", \$self->{"Sort"}, "reverse", \$self->{"Reverse"}, "list-limit=i", \$self->{"ListLimit"}, "hidden", \$self->{"ShowHidden"}, "list-format=s", sub { $self->{"ListFmt"} = $_[1]; $self->{"ListUnreadFmt"} = $_[1]; } , "all", \$self->{"MarkAll"}, "post-format=s", \$self->{"PostFmt"}, "brief", \$self->{"Brief"}, "feeds-format=s", \$self->{"FeedsFmt"}, "no-groups", \$self->{"NoGroups"}, "export-special", \$self->{"ExportSpec"}, "help|h", sub { _HELP(*STDOUT, 0); } , "version|v", sub { _VER(*STDOUT, 0); } , "<>", sub { if (not defined $self->{"Cmd"} || $_[0] =~ /^-/u) { $self->{"Cmd"} = $_[0]; } else { if ($_[0] =~ /^[\-0-9]+$/u) { push @{$$self{"Args"};}, $_[0]; } elsif (not $_[0] =~ /^-/u) { push @{$$self{"Args"};}, $_[0]; } else { warn "Unknown option: $_[0]\n"; _HELP(*STDERR, 1); } ; } ; } ) or _HELP(*STDERR, 1) 0 0 0
2088  
2089 0 bless $self, $class;
2090  
2091 0 ▶ if (not defined $self->{ Cmd }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"Cmd"}) 0 0 0
2092 0 _HELP(*STDERR, 0);
2093 }
2094  
2095 0 ▶ unless (exists $COMMANDS{ $self->{ Cmd } }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $COMMANDS{$self->{"Cmd"}}) 0 0 0
2096 0 die "'$self->{ Cmd }' is not a valid command\n";
2097 }
2098  
2099 0 ▶ $self->{ ConfFile } //= _default_config;
Condition0%0/3
$self->{"ConfFile"} //= _default_config()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ConfFile"} //= _default_config()
$self->{"ConfFile"} _default_config()
Truth table0%0/3
A //= B
A= $self->{"ConfFile"}B= _default_config()
ABresult
1X1
011
000
2100  
2101 0 ▶ if ($self->{ Brief } and $self->{ Cmd } eq 'feeds') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Brief"} and $self->{"Cmd"} eq "feeds") 0 0 0
Condition0%0/3
$self->{"Brief"} and $self->{"Cmd"} eq "feeds"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"Brief"} and $self->{"Cmd"} eq "feeds"
$self->{"Brief"} $self->{"Cmd"} eq "feeds"
Truth table0%0/3
A and B
A= $self->{"Brief"}B= $self->{"Cmd"} eq "feeds"
ABresult
0X0
100
111
2102 0 $self->{ FeedsFmt } = '%f';
2103 }
2104  
2105 0 ▶ if (defined $self->{ ConfFile }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"ConfFile"}) 0 0 0
2106 0 $self->_read_config;
2107 }
2108  
2109 0 ▶ $self->{ DataDir } //= _default_data_dir;
Condition0%0/3
$self->{"DataDir"} //= _default_data_dir()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"DataDir"} //= _default_data_dir()
$self->{"DataDir"} _default_data_dir()
Truth table0%0/3
A //= B
A= $self->{"DataDir"}B= _default_data_dir()
ABresult
1X1
011
000
2110  
2111 0 ▶ unless (-d $self->{ DataDir }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $self->{"DataDir"}) 0 0 0
2112 mkdir $self->{ DataDir }
2113 0 ▶ or die "Failed to mkdir $self->{ DataDir }: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $self->{"DataDir"} or die qq[Failed to mkdir $self->{"DataDir"}: $!\n] 0 0 0
2114 }
2115  
2116 $self->{ FeedDir } = File::Spec->catfile(
2117 $self->{ DataDir },
2118 0 'feeds'
2119 );
2120  
2121 0 ▶ unless (-d $self->{ FeedDir }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $self->{"FeedDir"}) 0 0 0
2122 mkdir $self->{ FeedDir }
2123 0 ▶ or die "Failed to mkdir $self->{ FeedDir }: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $self->{"FeedDir"} or die qq[Failed to mkdir $self->{"FeedDir"}: $!\n] 0 0 0
2124 }
2125  
2126 $self->{ EtagDir } = File::Spec->catfile(
2127 0 $self->{ DataDir }, 'etag'
2128 );
2129 0 ▶ unless (-d $self->{ EtagDir }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $self->{"EtagDir"}) 0 0 0
2130 mkdir $self->{ EtagDir }
2131 0 ▶ or die "Failed to mkdir $self->{ EtagDir }: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $self->{"EtagDir"} or die qq[Failed to mkdir $self->{"EtagDir"}: $!\n] 0 0 0
2132 }
2133  
2134 $self->{ RetryDir } = File::Spec->catfile(
2135 0 $self->{ DataDir }, 'retry'
2136 );
2137 0 ▶ if (not -d $self->{ RetryDir }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $self->{"RetryDir"}) 0 0 0
2138 0 ▶ unlink $self->{ RetryDir } if -f $self->{ RetryDir };
Branch: 1 branch
BranchTrueFalseTotal
if -f $self->{"RetryDir"} 0 0 0
2139 mkdir $self->{ RetryDir }
2140 0 ▶ or die "Failed to mkdir $self->{ RetryDir }: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $self->{"RetryDir"} or die qq[Failed to mkdir $self->{"RetryDir"}: $!\n] 0 0 0
2141 }
2142  
2143 0 ▶ unless (exists $DOESNT_NEED_FEED{ $self->{ Cmd } }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $DOESNT_NEED_FEED{$self->{"Cmd"}}) 0 0 0
2144 0 ▶ $self->{ FeedFile } //= _default_feeds;
Condition0%0/3
$self->{"FeedFile"} //= _default_feeds()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"FeedFile"} //= _default_feeds()
$self->{"FeedFile"} _default_feeds()
Truth table0%0/3
A //= B
A= $self->{"FeedFile"}B= _default_feeds()
ABresult
1X1
011
000
2145 0 ▶ unless (defined $self->{ FeedFile }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"FeedFile"}) 0 0 0
2146 0 die "$PRGNAM could not find a feeds file to read a feed list from\n";
2147 }
2148 0 ▶ unless (-f $self->{ FeedFile }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $self->{"FeedFile"}) 0 0 0
2149 0 die "$self->{ FeedFile } does not exist\n";
2150 }
2151 # For _get_url 'file://' links, to know the file's relative directory if
2152 # the url is not absolute.
2153 0 $self->{ FeedFile } = File::Spec->rel2abs($self->{ FeedFile });
2154 0 $self->_read_feed_file;
2155 }
2156  
2157 0 ▶ $self->{ Forks } //= $DEFAULT_FORKS;
Condition0%0/3
$self->{"Forks"} //= $DEFAULT_FORKS
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Forks"} //= $DEFAULT_FORKS
$self->{"Forks"} $DEFAULT_FORKS
Truth table0%0/3
A //= B
A= $self->{"Forks"}B= $DEFAULT_FORKS
ABresult
1X1
011
000
2158  
2159 0 ▶ unless ($self->{ Forks } > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"Forks"} > 0) 0 0 0
2160 0 die "Download count must be greater than 0\n";
2161 }
2162  
2163 0 ▶ $self->{ AutoClean } //= 0;
Condition0%0/2
$self->{"AutoClean"} //= 0
l!l
00
MC/DC0%0/1
$self->{"AutoClean"} //= 0
$self->{"AutoClean"}
Truth table0%0/2
A
A= $self->{"AutoClean"}
Aresult
11
00
2164 0 ▶ $self->{ UserAgent } //= $DEFAULT_AGENT;
Condition0%0/3
$self->{"UserAgent"} //= $DEFAULT_AGENT
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"UserAgent"} //= $DEFAULT_AGENT
$self->{"UserAgent"} $DEFAULT_AGENT
Truth table0%0/3
A //= B
A= $self->{"UserAgent"}B= $DEFAULT_AGENT
ABresult
1X1
011
000
2165 0 ▶ $self->{ Pager } //= $ENV{ PAGER } // $DEFAULT_PAGER;
Condition0%0/6
$self->{"Pager"} //= $ENV{"PAGER"} // $DEFAULT_PAGER
l!l&&r!l&&!r
000
$ENV{"PAGER"} // $DEFAULT_PAGER
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"Pager"} //= $ENV{"PAGER"} // $DEFAULT_PAGER
$self->{"Pager"} $ENV{"PAGER"} $DEFAULT_PAGER
Truth table0%0/4
A //= B // C
A= $self->{"Pager"}B= $ENV{"PAGER"}C= $DEFAULT_PAGER
ABCresult
1XX1
01X1
0011
0000
2166 0 ▶ $self->{ Browser } //= $ENV{ BROWSER } // 'lynx';
Condition0%0/4
$self->{"Browser"} //= $ENV{"BROWSER"} // "lynx"
l!l
00
$ENV{"BROWSER"} // "lynx"
l!l
00
MC/DC0%0/1
$self->{"Browser"} //= $ENV{"BROWSER"} // "lynx"
$self->{"Browser"}
Truth table0%0/2
A
A= $self->{"Browser"}
Aresult
11
00
2167 0 ▶ $self->{ ListLimit } //= 0;
Condition0%0/2
$self->{"ListLimit"} //= 0
l!l
00
MC/DC0%0/1
$self->{"ListLimit"} //= 0
$self->{"ListLimit"}
Truth table0%0/2
A
A= $self->{"ListLimit"}
Aresult
11
00
2168 0 ▶ $self->{ LineWidth } //= $DEFAULT_WIDTH;
Condition0%0/3
$self->{"LineWidth"} //= $DEFAULT_WIDTH
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"LineWidth"} //= $DEFAULT_WIDTH
$self->{"LineWidth"} $DEFAULT_WIDTH
Truth table0%0/3
A //= B
A= $self->{"LineWidth"}B= $DEFAULT_WIDTH
ABresult
1X1
011
000
2169 0 ▶ $self->{ ReadFmt } //= $DEFAULT_READ_FMT;
Condition0%0/3
$self->{"ReadFmt"} //= $DEFAULT_READ_FMT
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ReadFmt"} //= $DEFAULT_READ_FMT
$self->{"ReadFmt"} $DEFAULT_READ_FMT
Truth table0%0/3
A //= B
A= $self->{"ReadFmt"}B= $DEFAULT_READ_FMT
ABresult
1X1
011
000
2170 0 ▶ $self->{ PostFmt } //= $DEFAULT_POST_FMT;
Condition0%0/3
$self->{"PostFmt"} //= $DEFAULT_POST_FMT
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"PostFmt"} //= $DEFAULT_POST_FMT
$self->{"PostFmt"} $DEFAULT_POST_FMT
Truth table0%0/3
A //= B
A= $self->{"PostFmt"}B= $DEFAULT_POST_FMT
ABresult
1X1
011
000
2171 0 ▶ $self->{ FeedsFmt } //= $DEFAULT_FEED_FMT;
Condition0%0/3
$self->{"FeedsFmt"} //= $DEFAULT_FEED_FMT
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"FeedsFmt"} //= $DEFAULT_FEED_FMT
$self->{"FeedsFmt"} $DEFAULT_FEED_FMT
Truth table0%0/3
A //= B
A= $self->{"FeedsFmt"}B= $DEFAULT_FEED_FMT
ABresult
1X1
011
000
2172  
2173 0 ▶ unless ($self->{ LineWidth } > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"LineWidth"} > 0) 0 0 0
2174 0 die "width must be greater than 0\n";
2175 }
2176  
2177 0 ▶ if (defined $self->{ Status } and $self->{ Status } !~ /^(un)?read$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Status"} and not $self->{"Status"} =~ /^(un)?read$/u) 0 0 0
Condition0%0/3
defined $self->{"Status"} and not $self->{"Status"} =~ /^(un)?read$/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"Status"} and not $self->{"Status"} =~ /^(un)?read$/u
defined $self->{"Status"} not $self->{"Status"} =~ /^(un)?read$/u
Truth table0%0/3
A and not(B)
A= defined $self->{"Status"}B= not $self->{"Status"} =~ /^(un)?read$/u
ABresult
0X0
100
111
2178 0 die "status must either be 'read' or 'unread'\n";
2179 }
2180  
2181 0 ▶ $self->{ Sort } //= 'date';
Condition0%0/2
$self->{"Sort"} //= "date"
l!l
00
MC/DC0%0/1
$self->{"Sort"} //= "date"
$self->{"Sort"}
Truth table0%0/2
A
A= $self->{"Sort"}
Aresult
11
00
2182  
2183 0 ▶ unless (exists $VALID_SORTS{ $self->{ Sort } }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $VALID_SORTS{$self->{"Sort"}}) 0 0 0
2184 0 die sprintf
2185 "--sort must be one of the following: %s\n",
2186 join(', ', sort keys %VALID_SORTS);
2187 }
2188  
2189 0 ▶ if (defined $self->{ RateLimit } and $self->{ RateLimit } !~ $RATE_RX) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"RateLimit"} and not $self->{"RateLimit"} =~ /$RATE_RX/u) 0 0 0
Condition0%0/3
defined $self->{"RateLimit"} and not $self->{"RateLimit"} =~ /$RATE_RX/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"RateLimit"} and not $self->{"RateLimit"} =~ /$RATE_RX/u
defined $self->{"RateLimit"} not $self->{"RateLimit"} =~ /$RATE_RX/u
Truth table0%0/3
A and not(B)
A= defined $self->{"RateLimit"}B= not $self->{"RateLimit"} =~ /$RATE_RX/u
ABresult
0X0
100
111
2190 0 die "Invalid argument to --limit-rate\n";
2191 }
2192  
2193 0 ▶ unless ($DOESNT_NEED_FEED{ $self->{ Cmd } }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($DOESNT_NEED_FEED{$self->{"Cmd"}}) 0 0 0
2194 $self->{ DB } = WWW::Noss::DB->new(
2195 0 File::Spec->catfile($self->{ DataDir }, 'database.sqlite3')
2196 );
2197 }
2198  
2199 0 ▶ if (defined $self->{ TimeFmt }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"TimeFmt"}) 0 0 0
2200 0 _set_z_fmt($self->{ TimeFmt });
2201 }
2202  
2203 0 ▶ if (not defined $self->{ UseColor }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"UseColor"}) 0 0 0
2204 0 ▶ if (-t STDOUT) {
Branch: 1 branch
BranchTrueFalseTotal
if (-t STDOUT) { } 0 0 0
2205 0 $self->{ UseColor } = 1;
2206 } else {
2207 0 $self->{ UseColor } = 0;
2208 }
2209 }
2210  
2211 # Windows terminals do not support ANSI color codes.
2212 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 0 0
2213 0 $self->{ UseColor } = 0;
2214 }
2215  
2216 0 ▶ if (not defined $self->{ Timeout }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"Timeout"}) 0 0 0
2217 0 $self->{ Timeout } = 45;
2218 }
2219  
2220 0 return $self;
2221  
2222 }
2223  
2224 0 ▶sub run {
Subroutine run: not called CC=7 SCAR=40.3
Pod documented
2225  
2226 0 my ($self) = @_;
2227  
2228 0 $COMMANDS{ $self->{ Cmd } }->($self);
2229  
2230 0 ▶ if ($self->{ AutoClean } and not $DOESNT_NEED_FEED{ $self->{ Cmd } }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"AutoClean"} and not $DOESNT_NEED_FEED{$self->{"Cmd"}}) 0 0 0
Condition0%0/3
$self->{"AutoClean"} and not $DOESNT_NEED_FEED{$self->{"Cmd"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"AutoClean"} and not $DOESNT_NEED_FEED{$self->{"Cmd"}}
$self->{"AutoClean"} not $DOESNT_NEED_FEED{$self->{"Cmd"}}
Truth table0%0/3
A and not(B)
A= $self->{"AutoClean"}B= not $DOESNT_NEED_FEED{$self->{"Cmd"}}
ABresult
0X0
100
111
2231 0 $self->clean;
2232 }
2233  
2234 # Delete outdated retry caches
2235 0 my $now = time;
2236 0 for my $f (values %{ $self->{ Feeds } }) {
2237 0 my $retry = $f->retry;
2238 0 ▶ next if not defined $retry;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $retry 0 0 0
2239 0 ▶ if ($now >= $retry) {
Branch: 1 branch
BranchTrueFalseTotal
if ($now >= $retry) 0 0 0
2240 0 ▶ unlink $f->retry_cache
Branch: 1 branch
BranchTrueFalseTotal
unlink $f->retry_cache or warn sprintf("Failed to unlink %s: %s\n", $f->retry_cache, $!) 0 0 0
2241 or warn sprintf "Failed to unlink %s: %s\n", $f->retry_cache, $!;
2242 }
2243 }
2244  
2245 0 return 1;
2246  
2247 }
2248  
2249 1 1;
2250  
2251 =head1 NAME
2252  
2253 WWW::Noss - RSS/Atom feed reader and aggregator
2254  
2255 =head1 USAGE
2256  
2257 use WWW::Noss;
2258  
2259 my $noss = WWW::Noss->init(@ARGV);
2260 $noss->run;
2261  
2262 =head1 DESCRIPTION
2263  
2264 B<WWW::Noss> is the backend module providing L<noss>'s functionality. This is
2265 a private module, please consult the L<noss> manual for user documentation.
2266  
2267 =head1 METHODS
2268  
2269 =over 4
2270  
2271 =item $noss = WWW::Noss->init(@argv)
2272  
2273 Reads command-line arguments from C<@argv> and returns a blessed B<WWW::Noss>
2274 object. You would usually pass C<@ARGV> to it.
2275  
2276 Consult the L<noss> manual for documentation on what options/arguments are
2277 available.
2278  
2279 =item $noss->run()
2280  
2281 Runs L<noss> based on the parameters processed during C<init()>.
2282  
2283 =item $noss->update()
2284  
2285 Method implementing the C<update> command.
2286  
2287 =item $noss->reload()
2288  
2289 Method implementing the C<reload> command.
2290  
2291 =item $noss->read_post()
2292  
2293 Method implementing the C<read> command.
2294  
2295 =item $noss->open_post()
2296  
2297 Method implementing the C<open> command.
2298  
2299 =item $noss->cat()
2300  
2301 Method implementing the C<cat> command.
2302  
2303 =item $noss->look()
2304  
2305 Method implementing the C<list> command.
2306  
2307 =item $noss->unread()
2308  
2309 Method implementing the C<unread> command.
2310  
2311 =item $noss->mark()
2312  
2313 Method implementing the C<mark> command.
2314  
2315 =item $noss->post()
2316  
2317 Method implementing the C<post> command.
2318  
2319 =item $noss->feeds()
2320  
2321 Method implementing the C<feeds> command.
2322  
2323 =item $noss->groups()
2324  
2325 Method implementing the C<groups> command.
2326  
2327 =item $noss->clean()
2328  
2329 Method implementing the C<clean> command.
2330  
2331 =item $noss->discover()
2332  
2333 Method implementing the C<discover> command.
2334  
2335 =item $noss->export_opml()
2336  
2337 Method implementing the C<export> command.
2338  
2339 =item $noss->import_opml()
2340  
2341 Method implementing the C<import> command.
2342  
2343 =item $noss->help()
2344  
2345 Method implementing the C<help> command.
2346  
2347 =back
2348  
2349 =head1 AUTHOR
2350  
2351 Written by Samuel Young, E<lt>samyoung@posteo.comE<gt>.
2352  
2353 This project's source can be found on its
2354 L<Codeberg page|https://codeberg.org/1-1sam/noss.git>. Comments and pull
2355 requests are welcome!
2356  
2357 =head1 COPYRIGHT
2358  
2359 Copyright (C) 2025-2026 Samuel Young
2360  
2361 This program is free software: you can redistribute it and/or modify
2362 it under the terms of the GNU General Public License as published by
2363 the Free Software Foundation, either version 3 of the License, or
2364 (at your option) any later version.
2365  
2366 =head1 SEE ALSO
2367  
2368 L<noss>
2369  
2370 =cut
2371  
2372 # vim: expandtab shiftwidth=4
↑ Summary Noss/Curl.pm »