Noss/FeedConfig.pm

filter: Statementstmt 93.3% 196 / 210 Branchbran 72.4% 42 / 58 Conditioncond 50.0% 10 / 20 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 96.4% 27 / 28 Podpod 94.4% 17 / 18 totaltotal 84.9% 293 / 345 CC 40 SCAR 23.4
CC
40
Cov
86%
initialize
24.1
retry
5.9
set_groups
4.6
CRAP 10.4
« Noss/OPML.pm ↑ Summary Noss/Timestamp.pm »
1 package WWW::Noss::FeedConfig;
2 6 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 our $VERSION = '2.04';
6  
7 6 ▶use parent 'WWW::Noss::BaseConfig';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use List::Util qw(any first min);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12  
13 17 my ($class, %param) = @_;
14  
15 17 my $self = bless {}, $class;
16  
17 17 $self->initialize(%param);
18  
19 17 return $self;
20  
21 }
22  
23 17 ▶sub initialize {
Subroutine initialize: called CC=24 SCAR=31.8
Pod undocumented
24  
25 17 my ($self, %param) = @_;
26  
27 17 $self->SUPER::initialize;
28 17 $self->set_name($param{ name });
29 17 $self->set_feed($param{ feed });
30 17 $self->set_path($param{ path });
31 17 $self->set_etag($param{ etag });
32 17 $self->set_retry_cache($param{ retry_cache });
33  
34 17 my $default = $param{ default };
35  
36 # Apply default parameters
37 17 ▶ if (defined $default) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default) 1 16 17
38 1 $self->set_limit($default->limit);
39 1 $self->set_respect_skip($default->respect_skip);
40 1 $self->set_include_title($default->include_title);
41 1 $self->set_exclude_title($default->exclude_title);
42 1 $self->set_include_content($default->include_content);
43 1 $self->set_exclude_content($default->exclude_content);
44 1 $self->set_include_tags($default->include_tags);
45 1 $self->set_exclude_tags($default->exclude_tags);
46 1 $self->set_autoread($default->autoread);
47 1 $self->set_default_update($default->default_update);
48 1 $self->set_hidden($default->hidden);
49 1 $self->set_open_cmd($default->open_cmd);
50 }
51  
52 17 ▶ $self->set_groups($param{ groups } // []);
Condition100%2/2
$param{"groups"} // []
l!l
116
MC/DC100%1/1
$param{"groups"} // []
$param{"groups"}
Truth table100%2/2
A
A= $param{"groups"}
Aresult
11
00
53  
54 17 ▶ if (@{ $self->groups }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->groups;}) 1 16 17
55  
56 # Set lowest limit defined by groups if present
57 1 my $limit = min grep { defined } map { $_->limit } @{ $self->groups };
58 1 ▶ $self->set_limit($limit) if defined $limit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $limit 1 0 1
59  
60 # If any group respects skip, we respect skip
61 1 ▶ my $rs = any { $_->respect_skip } @{ $self->groups };
Subroutine __ANON__: called CC=1 SCAR=0.0
62 1 $self->set_respect_skip($rs);
63  
64 # Overlay group filters
65 1 push @{ $self->include_title },
66 3 ▶ map { @{ $_->include_title // [] } }
Condition50%1/2
$_->include_title // []
l!l
30
MC/DC0%0/1
$_->include_title // []
$_->include_title
Truth table50%1/2
A
A= $_->include_title
Aresult
11
00
67 1 @{ $self->groups };
68 1 push @{ $self->exclude_title },
69 3 ▶ map { @{ $_->exclude_title // [] } }
Condition50%1/2
$_->exclude_title // []
l!l
30
MC/DC0%0/1
$_->exclude_title // []
$_->exclude_title
Truth table50%1/2
A
A= $_->exclude_title
Aresult
11
00
70 1 @{ $self->groups };
71 1 push @{ $self->include_content },
72 3 ▶ map { @{ $_->include_content // [] } }
Condition50%1/2
$_->include_content // []
l!l
30
MC/DC0%0/1
$_->include_content // []
$_->include_content
Truth table50%1/2
A
A= $_->include_content
Aresult
11
00
73 1 @{ $self->groups };
74 1 push @{ $self->exclude_content },
75 3 ▶ map { @{ $_->exclude_content // [] } }
Condition50%1/2
$_->exclude_content // []
l!l
30
MC/DC0%0/1
$_->exclude_content // []
$_->exclude_content
Truth table50%1/2
A
A= $_->exclude_content
Aresult
11
00
76 1 @{ $self->groups };
77 1 push @{ $self->include_tags },
78 3 ▶ map { @{ $_->include_tags // [] } }
Condition50%1/2
$_->include_tags // []
l!l
30
MC/DC0%0/1
$_->include_tags // []
$_->include_tags
Truth table50%1/2
A
A= $_->include_tags
Aresult
11
00
79 1 @{ $self->groups };
80 1 push @{ $self->exclude_tags },
81 3 ▶ map { @{ $_->exclude_tags // [] } }
Condition50%1/2
$_->exclude_tags // []
l!l
30
MC/DC0%0/1
$_->exclude_tags // []
$_->exclude_tags
Truth table50%1/2
A
A= $_->exclude_tags
Aresult
11
00
82 1 @{ $self->groups };
83  
84 # If any group wants autoread, we'll take autoread
85 1 ▶ my $ar = any { $_->autoread } @{ $self->groups };
Subroutine __ANON__: called CC=1 SCAR=0.0
86 1 $self->set_autoread($ar);
87  
88 # If any group does not want default_updates, we'll take no default
89 # updates
90 1 ▶ my $ndu = any { !$_->default_update } @{ $self->groups };
Subroutine __ANON__: called CC=1 SCAR=0.0
91 1 $self->set_default_update(!$ndu);
92  
93 # If any groups wants hidden, take hidden
94 1 ▶ my $hid = any { $_->hidden } @{ $self->groups };
Subroutine __ANON__: called CC=1 SCAR=0.0
95 1 $self->set_hidden($hid);
96  
97 1 ▶ my $cmd = first { defined }
Subroutine __ANON__: called CC=1 SCAR=0.0
98 3 map { $_->open_cmd }
99 3 sort { $a->name cmp $b->name }
100 1 @{ $self->groups };
101 1 ▶ if (defined $cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cmd) 1 0 1
102 1 $self->set_open_cmd($cmd);
103 }
104  
105 }
106  
107 17 ▶ if (defined $param{ limit }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"limit"}) 2 15 17
108 2 $self->set_limit($param{ limit });
109 }
110 17 ▶ if (defined $param{ respect_skip }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"respect_skip"}) 0 17 17
111 0 $self->set_respect_skip($param{ respect_skip });
112 }
113 17 ▶ if (defined $param{ include_title }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"include_title"}) 3 14 17
114 3 push @{ $self->include_title }, @{ $param{ include_title } };
115 }
116 17 ▶ if (defined $param{ exclude_title }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"exclude_title"}) 3 14 17
117 3 push @{ $self->exclude_title }, @{ $param{ exclude_title } };
118 }
119 17 ▶ if (defined $param{ include_content }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"include_content"}) 3 14 17
120 3 push @{ $self->include_content }, @{ $param{ include_content } };
121 }
122 17 ▶ if (defined $param{ exclude_content }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"exclude_content"}) 3 14 17
123 3 push @{ $self->exclude_content }, @{ $param{ exclude_content } };
124 }
125 17 ▶ if (defined $param{ include_tags }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"include_tags"}) 3 14 17
126 3 push @{ $self->include_tags }, @{ $param{ include_tags } };
127 }
128 17 ▶ if (defined $param{ exclude_tags }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"exclude_tags"}) 3 14 17
129 3 push @{ $self->exclude_tags }, @{ $param{ exclude_tags } };
130 }
131 17 ▶ if (defined $param{ autoread }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"autoread"}) 1 16 17
132 1 $self->set_autoread($param{ autoread });
133 }
134 17 ▶ if (defined $param{ default_update }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"default_update"}) 1 16 17
135 1 $self->set_default_update($param{ default_update });
136 }
137 17 ▶ if (defined $param{ hidden }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"hidden"}) 1 16 17
138 1 $self->set_hidden($param{ hidden });
139 }
140 17 ▶ if (defined $param{ open }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param{"open"}) 1 16 17
141 1 $self->set_open_cmd($param{ open });
142 }
143  
144 17 return 1;
145  
146 }
147  
148 19 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
149  
150 19 my ($self) = @_;
151  
152 19 return $self->{ Name };
153  
154 }
155  
156 17 ▶sub set_name {
Subroutine set_name: called CC=3 SCAR=12.7
Pod documented
157  
158 17 my ($self, $name) = @_;
159  
160 17 ▶ unless (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 0 17 17
161 0 die "name cannot be undefined";
162 }
163  
164 # ':' feeds are reserved for internal use
165 17 ▶ unless ($name =~ /^\:?\w+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ /^\:?\w+$/u) 0 17 17
166 0 die "name can only contain alphanumeric and underscore characters";
167 }
168  
169 17 $self->{ Name } = $name;
170  
171 }
172  
173 17 ▶sub feed {
Subroutine feed: called CC=1 SCAR=0.0
Pod documented
174  
175 17 my ($self) = @_;
176  
177 17 return $self->{ Feed };
178  
179 }
180  
181 17 ▶sub set_feed {
Subroutine set_feed: called CC=2 SCAR=7.6
Pod documented
182  
183 17 my ($self, $feed) = @_;
184  
185 17 ▶ unless (defined $feed) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $feed) 0 17 17
186 0 die "feed cannot be undefined";
187 }
188  
189 17 $self->{ Feed } = $feed;
190  
191 }
192  
193 33 ▶sub groups {
Subroutine groups: called CC=1 SCAR=0.0
Pod documented
194  
195 33 my ($self) = @_;
196  
197 33 return $self->{ Groups };
198  
199 }
200  
201 17 ▶sub set_groups {
Subroutine set_groups: called CC=4 SCAR=15.2
Pod documented
202  
203 17 my ($self, $new) = @_;
204  
205 17 ▶ unless (ref $new eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $new eq "ARRAY") 0 17 17
206 0 die "groups must be an array ref";
207 }
208  
209 17 for my $i (0 .. $#$new) {
210 3 ▶ unless (eval { $new->[$i]->isa('WWW::Noss::GroupConfig') }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $new->[$i]->isa("WWW::Noss::GroupConfig") } }) 0 3 3
211 0 die "group[$i] is not a WWW::Noss::GroupConfig object";
212 }
213 }
214  
215 17 $self->{ Groups } = $new;
216  
217 }
218  
219 3 ▶sub has_group {
Subroutine has_group: called CC=1 SCAR=0.0
Pod documented
220  
221 3 my ($self, $grp) = @_;
222  
223 3 return !! grep { $_->name eq $grp } @{ $self->groups };
224  
225 }
226  
227 17 ▶sub path {
Subroutine path: called CC=1 SCAR=0.0
Pod documented
228  
229 17 my ($self) = @_;
230  
231 17 return $self->{ Path };
232  
233 }
234  
235 17 ▶sub set_path {
Subroutine set_path: called CC=2 SCAR=7.6
Pod documented
236  
237 17 my ($self, $path) = @_;
238  
239 17 ▶ unless (defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 0 17 17
240 0 die "path cannot be undefined";
241 }
242  
243 17 $self->{ Path } = $path;
244  
245 }
246  
247 1 ▶sub etag {
Subroutine etag: called CC=1 SCAR=0.0
Pod documented
248  
249 1 my ($self) = @_;
250  
251 1 return $self->{ Etag };
252  
253 }
254  
255 17 ▶sub set_etag {
Subroutine set_etag: called CC=1 SCAR=0.0
Pod documented
256  
257 17 my ($self, $etag) = @_;
258  
259 17 $self->{ Etag } = $etag;
260  
261 }
262  
263 0 ▶sub retry_cache {
Subroutine retry_cache: not called CC=1 SCAR=6.9
Pod documented
264  
265 0 my ($self) = @_;
266  
267 0 return $self->{ RetryCache };
268  
269 }
270  
271 17 ▶sub set_retry_cache {
Subroutine set_retry_cache: called CC=1 SCAR=0.0
Pod documented
272  
273 17 my ($self, $cache) = @_;
274  
275 17 $self->{ RetryCache } = $cache;
276  
277 }
278  
279 2 ▶sub retry {
Subroutine retry: called CC=5 SCAR=17.8
Pod documented
280  
281 2 my ($self) = @_;
282  
283 2 ▶ if (not defined $self->{ RetryCache } or not -f $self->{ RetryCache }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"RetryCache"} and -f $self->{"RetryCache"}) 0 2 2
Condition33%1/3
defined $self->{"RetryCache"} and -f $self->{"RetryCache"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $self->{"RetryCache"} and -f $self->{"RetryCache"}
defined $self->{"RetryCache"} -f $self->{"RetryCache"}
Truth table33%1/3
A and B
A= defined $self->{"RetryCache"}B= -f $self->{"RetryCache"}
ABresult
0X0
100
111
284 0 return undef;
285 }
286  
287 open my $fh, '<', $self->{ RetryCache }
288 2 ▶ or die "Failed to open $self->{ RetryCache } for reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->{"RetryCache"} or die qq[Failed to open $self->{"RetryCache"} for reading: $!] 2 0 2
289 2 my $retry = do { local $/; (readline $fh)[0] };
290 2 close $fh;
291 2 chomp $retry;
292  
293 2 ▶ if ($retry !~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($retry =~ /^\d+$/u) 0 2 2
294 0 die "$self->{ RetryCache }: corrupted retry cache";
295 }
296  
297 2 return int $retry;
298  
299 }
300  
301 1 ▶sub set_retry {
Subroutine set_retry: called CC=4 SCAR=14.8
Pod documented
302  
303 1 my ($self, $retry) = @_;
304  
305 1 ▶ if ($retry !~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($retry =~ /^\d+$/u) 0 1 1
306 0 die 'retry time must be an integar';
307 }
308  
309 1 ▶ if (not defined $self->{ RetryCache }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"RetryCache"}) 0 1 1
310 0 die 'retry_cache must be set before setting retry';
311 }
312  
313 1 $retry = int $retry;
314  
315 open my $fh, '>', $self->{ RetryCache }
316 1 ▶ or die "Failed to open $self->{ RetryCache } for writing: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $self->{"RetryCache"} or die qq[Failed to open $self->{"RetryCache"} for writing: $!] 1 0 1
317 1 print { $fh } $retry, "\n";
318 1 close $fh;
319  
320 1 return $retry;
321  
322 }
323  
324 1 ▶sub can_we_retry {
Subroutine can_we_retry: called CC=3 SCAR=12.3
Pod documented
325  
326 1 my ($self, $time) = @_;
327 1 ▶ $time //= time;
Condition33%1/3
$time //= time
l!l&&r!l&&!r
010
MC/DC0%0/2
$time //= time
$time time
Truth table33%1/3
A //= B
A= $timeB= time
ABresult
1X1
011
000
328  
329 1 my $retry = $self->retry;
330 1 ▶ if (not defined $retry) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $retry) 0 1 1
331 0 return 1;
332 }
333  
334 1 return $time >= $retry;
335  
336 }
337  
338 6 1;
339  
340 =head1 NAME
341  
342 WWW::Noss::FeedConfig - Class for storing feed configurations
343  
344 =head1 USAGE
345  
346 use WWW::Noss::FeedConfig;
347  
348 my $feed = WWW::Noss::FeedConfig->new(
349 name => 'feed',
350 feed => 'https://feed.xml',
351 path => 'feed.xml',
352 );
353  
354 =head1 DESCRIPTION
355  
356 B<WWW::Noss::FeedConfig> is a module that provides a class for storing L<noss>
357 feed configurations. This is a private module, please consult the L<noss>
358 manual for user documentation.
359  
360 =head1 METHODS
361  
362 Not all methods are documented here, as this class is derived from the
363 L<WWW::Noss::BaseConfig> module. Consult its documentation for additional
364 methods.
365  
366 =over 4
367  
368 =item $feed = WWW::Noss::FeedConfig->new(%param)
369  
370 Returns a blessed B<WWW::Noss::FeedConfig> object based on the parameters
371 provided in the C<%param> hash.
372  
373 The following are valid fields for the C<%param> hash. The C<name>, C<feed>,
374 and C<path> fields are the only required fields.
375  
376 =over 4
377  
378 =item name
379  
380 The name of feed. Can only only contain alphanumeric and underscore
381 characters.
382  
383 =item feed
384  
385 The feed URL.
386  
387 =item path
388  
389 Path to the location to store the feed.
390  
391 =item etag
392  
393 Path to store the feed's etag.
394  
395 =item groups
396  
397 Array ref of L<WWW::Noss::GroupConfig> groups that the feed is a part of.
398  
399 =item default
400  
401 L<WWW::Noss::GroupConfig> object representing the default feed group.
402  
403 =back
404  
405 The following fields from L<WWW::Noss::BaseConfig> are also available:
406  
407 =over 4
408  
409 =item limit
410  
411 =item respect_skip
412  
413 =item include_title
414  
415 =item exclude_title
416  
417 =item include_content
418  
419 =item exclude_content
420  
421 =item include_tags
422  
423 =item exclude_tags
424  
425 =item autoread
426  
427 =item default_update
428  
429 =item hidden
430  
431 =item open
432  
433 =back
434  
435 =item $name = $feed->name()
436  
437 =item $feed->set_name($name)
438  
439 Getter/setter for the feed's name attribute.
440  
441 =item $url = $feed->feed()
442  
443 =item $feed->set_feed($url)
444  
445 Getter/setter for the feed's feed attribute.
446  
447 =item \@groups = $feed->groups()
448  
449 =item $feed->set_groups(\@groups)
450  
451 Getter/setter for the feed's groups attribute. Do note that modifying the
452 groups attribute does not affect the feed's configuration like it does during
453 initialization.
454  
455 =item $ok = $feed->has_group($group)
456  
457 Returns true if C<$feed> is a part of the group C<$group>.
458  
459 =item $path = $feed->path()
460  
461 =item $feed->set_path($path)
462  
463 Getter/setter for the feed's path attribute.
464  
465 =item $etag = $feed->etag()
466  
467 =item $feed->set_etag($etag)
468  
469 Getter/setter for the feed's etag attribute.
470  
471 =item $file = $feed->retry_cache()
472  
473 =item $feed->set_retry_cache($file)
474  
475 Getter/setter for the feed's retry cache file.
476  
477 =item $retry = $feed->retry()
478  
479 =item $feed->set_retry($retry)
480  
481 =item $ok = $feed->can_we_retry([ $time ])
482  
483 Getter/setter for the feed's retry time.
484  
485 =back
486  
487 =head1 AUTHOR
488  
489 Written by Samuel Young, E<lt>samyoung12788@gmail.comE<gt>.
490  
491 This project's source can be found on its
492 L<Codeberg page|https://codeberg.org/1-1sam/noss.git>. Comments and pull
493 requests are welcome!
494  
495 =head1 COPYRIGHT
496  
497 Copyright (C) 2025-2026 Samuel Young
498  
499 This program is free software: you can redistribute it and/or modify
500 it under the terms of the GNU General Public License as published by
501 the Free Software Foundation, either version 3 of the License, or
502 (at your option) any later version.
503  
504 =head1 SEE ALSO
505  
506 L<WWW::Noss::BaseConfig>, L<WWW::Noss::GroupConfig>, L<noss>
507  
508 =cut
509  
510 # vim: expandtab shiftwidth=4
« Noss/OPML.pm ↑ Summary Noss/Timestamp.pm »