Noss/BaseConfig.pm

filter: Statementstmt 90.9% 131 / 144 Branchbran 73.0% 38 / 52 Conditioncond 95.6% 22 / 23 MC/DCmcdc 83.3% 10 / 12 Subroutinesub 100% 37 / 37 Podpod 96.3% 26 / 27 totaltotal 89.4% 264 / 295 CC 38 SCAR 15.5
CC
38
Cov
87%
initialize
11.0
tags_ok
8.2
title_ok
7.1
CRAP 4.7
« Noss/Timestamp.pm ↑ Summary Noss/Util.pm »
1 package WWW::Noss::BaseConfig;
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.03';
6  
7 6 ▶use List::Util qw(any all);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new {
10  
11 1 ▶ my ($class, %param) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12  
13 1 my $self = bless {}, $class;
14  
15 1 $self->initialize(%param);
16  
17 1 return $self;
18  
19 }
20  
21 sub initialize {
22  
23 23 ▶ my ($self, %param) = @_;
Subroutine initialize: called CC=11 SCAR=24.0
Pod undocumented
24  
25 23 $self->set_limit($param{ limit });
26 23 ▶ $self->set_respect_skip($param{ respect_skip } // 1);
Condition100%2/2
$param{"respect_skip"} // 1
l!l
617
MC/DC100%1/1
$param{"respect_skip"} // 1
$param{"respect_skip"}
Truth table100%2/2
A
A= $param{"respect_skip"}
Aresult
11
00
27 23 ▶ $self->set_include_title($param{ include_title } // []);
Condition100%2/2
$param{"include_title"} // []
l!l
617
MC/DC100%1/1
$param{"include_title"} // []
$param{"include_title"}
Truth table100%2/2
A
A= $param{"include_title"}
Aresult
11
00
28 23 ▶ $self->set_exclude_title($param{ exclude_title } // []);
Condition100%2/2
$param{"exclude_title"} // []
l!l
617
MC/DC100%1/1
$param{"exclude_title"} // []
$param{"exclude_title"}
Truth table100%2/2
A
A= $param{"exclude_title"}
Aresult
11
00
29 23 ▶ $self->set_include_content($param{ include_content } // []);
Condition100%2/2
$param{"include_content"} // []
l!l
617
MC/DC100%1/1
$param{"include_content"} // []
$param{"include_content"}
Truth table100%2/2
A
A= $param{"include_content"}
Aresult
11
00
30 23 ▶ $self->set_exclude_content($param{ exclude_content } // []);
Condition100%2/2
$param{"exclude_content"} // []
l!l
617
MC/DC100%1/1
$param{"exclude_content"} // []
$param{"exclude_content"}
Truth table100%2/2
A
A= $param{"exclude_content"}
Aresult
11
00
31 23 ▶ $self->set_include_tags($param{ include_tags } // []);
Condition100%2/2
$param{"include_tags"} // []
l!l
617
MC/DC100%1/1
$param{"include_tags"} // []
$param{"include_tags"}
Truth table100%2/2
A
A= $param{"include_tags"}
Aresult
11
00
32 23 ▶ $self->set_exclude_tags($param{ exclude_tags } // []);
Condition100%2/2
$param{"exclude_tags"} // []
l!l
617
MC/DC100%1/1
$param{"exclude_tags"} // []
$param{"exclude_tags"}
Truth table100%2/2
A
A= $param{"exclude_tags"}
Aresult
11
00
33 23 ▶ $self->set_autoread($param{ autoread } // 0);
Condition100%2/2
$param{"autoread"} // 0
l!l
617
MC/DC100%1/1
$param{"autoread"} // 0
$param{"autoread"}
Truth table100%2/2
A
A= $param{"autoread"}
Aresult
11
00
34 23 ▶ $self->set_default_update($param{ default_update } // 1);
Condition100%2/2
$param{"default_update"} // 1
l!l
617
MC/DC100%1/1
$param{"default_update"} // 1
$param{"default_update"}
Truth table100%2/2
A
A= $param{"default_update"}
Aresult
11
00
35 23 ▶ $self->set_hidden($param{ hidden } // 0);
Condition100%2/2
$param{"hidden"} // 0
l!l
617
MC/DC100%1/1
$param{"hidden"} // 0
$param{"hidden"}
Truth table100%2/2
A
A= $param{"hidden"}
Aresult
11
00
36  
37 23 return 1;
38  
39 }
40  
41 sub limit {
42  
43 25 ▶ my ($self) = @_;
Subroutine limit: called CC=1 SCAR=0.0
Pod documented
44  
45 25 return $self->{ Limit };
46  
47 }
48  
49 sub set_limit {
50  
51 27 ▶ my ($self, $new) = @_;
Subroutine set_limit: called CC=3 SCAR=12.0
Pod documented
52  
53 27 ▶ if (defined $new and $new <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new and $new <= 0) 0 27 27
Condition66%2/3
defined $new and $new <= 0
!ll&&!rl&&r
17100
MC/DC0%0/2
defined $new and $new <= 0
defined $new $new <= 0
Truth table66%2/3
A and B
A= defined $newB= $new <= 0
ABresult
0X0
100
111
54 0 die "limit must be greater than 0";
55 }
56  
57 27 $self->{ Limit } = $new;
58  
59 }
60  
61 sub respect_skip {
62  
63 5 ▶ my ($self) = @_;
Subroutine respect_skip: called CC=1 SCAR=0.0
Pod documented
64  
65 5 return $self->{ RespectSkip };
66  
67 }
68  
69 sub set_respect_skip {
70  
71 25 ▶ my ($self, $new) = @_;
Subroutine set_respect_skip: called CC=1 SCAR=0.0
Pod documented
72  
73 25 $self->{ RespectSkip } = !! $new;
74  
75 }
76  
77 sub include_title {
78  
79 101 ▶ my ($self) = @_;
Subroutine include_title: called CC=1 SCAR=0.0
Pod documented
80  
81 101 return $self->{ IncludeTitle };
82  
83 }
84  
85 sub set_include_title {
86  
87 24 ▶ my ($self, $new) = @_;
Subroutine set_include_title: called CC=2 SCAR=7.6
Pod documented
88  
89 24 ▶ if (ref $new ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new ne "ARRAY") 0 24 24
90 0 die "include_title must be an array ref";
91 }
92  
93 24 $self->{ IncludeTitle } = $new;
94  
95 }
96  
97 sub exclude_title {
98  
99 95 ▶ my ($self) = @_;
Subroutine exclude_title: called CC=1 SCAR=0.0
Pod documented
100  
101 95 return $self->{ ExcludeTitle };
102  
103 }
104  
105 sub set_exclude_title {
106  
107 24 ▶ my ($self, $new) = @_;
Subroutine set_exclude_title: called CC=2 SCAR=7.6
Pod documented
108  
109 24 ▶ if (ref $new ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new ne "ARRAY") 0 24 24
110 0 die "exclude_title must be an array ref";
111 }
112  
113 24 $self->{ ExcludeTitle } = $new;
114  
115 }
116  
117 sub title_ok {
118  
119 76 ▶ my ($self, $title) = @_;
Subroutine title_ok: called CC=7 SCAR=19.6
Pod documented
120  
121 76 ▶ if (@{ $self->include_title }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->include_title;}) 14 62 76
122 14 ▶ unless (defined $title) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $title) 0 14 14
123 0 return 0;
124 }
125 14 ▶ unless (all { $title =~ $_ } @{ $self->include_title }) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless (&all(sub { $title =~ /$_/u; } , @{$self->include_title;})) 4 10 14
126 4 return 0;
127 }
128 }
129  
130 72 ▶ if (@{ $self->exclude_title }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->exclude_title;}) 12 60 72
131 12 ▶ unless (defined $title) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $title) 0 12 12
132 0 return 1;
133 }
134 12 ▶ if (any { $title =~ $_ } @{ $self->exclude_title }) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $title =~ /$_/u; } , @{$self->exclude_title;})) 7 5 12
135 7 return 0;
136 }
137 }
138  
139 65 return 1;
140  
141 }
142  
143 sub include_content {
144  
145 92 ▶ my ($self) = @_;
Subroutine include_content: called CC=1 SCAR=0.0
Pod documented
146  
147 92 return $self->{ IncludeContent };
148  
149 }
150  
151 sub set_include_content {
152  
153 24 ▶ my ($self, $new) = @_;
Subroutine set_include_content: called CC=2 SCAR=7.6
Pod documented
154  
155 24 ▶ if (ref $new ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new ne "ARRAY") 0 24 24
156 0 die "include_content must be an array ref";
157 }
158  
159 24 $self->{ IncludeContent } = $new;
160  
161 }
162  
163 sub exclude_content {
164  
165 87 ▶ my ($self) = @_;
Subroutine exclude_content: called CC=1 SCAR=0.0
Pod documented
166  
167 87 return $self->{ ExcludeContent };
168  
169 }
170  
171 sub set_exclude_content {
172  
173 24 ▶ my ($self, $new) = @_;
Subroutine set_exclude_content: called CC=2 SCAR=7.6
Pod documented
174  
175 24 ▶ if (ref $new ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new ne "ARRAY") 0 24 24
176 0 die "exclude_content must be an array ref";
177 }
178  
179 24 $self->{ ExcludeContent } = $new;
180  
181 }
182  
183 sub content_ok {
184  
185 67 ▶ my ($self, $content) = @_;
Subroutine content_ok: called CC=7 SCAR=19.6
Pod documented
186  
187 67 ▶ if (@{ $self->include_content }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->include_content;}) 14 53 67
188 14 ▶ unless (defined $content) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content) 0 14 14
189 0 return 0;
190 }
191 14 ▶ if (not all { $content =~ $_ } @{ $self->include_content }) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless (&all(sub { $content =~ /$_/u; } , @{$self->include_content;})) 4 10 14
192 4 return 0;
193 }
194 }
195  
196 63 ▶ if (@{ $self->exclude_content }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->exclude_content;}) 13 50 63
197 13 ▶ unless (defined $content) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content) 0 13 13
198 0 return 1;
199 }
200 13 ▶ if (any { $content =~ $_ } @{ $self->exclude_content }) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $content =~ /$_/u; } , @{$self->exclude_content;})) 8 5 13
201 8 return 0;
202 }
203 }
204  
205 55 return 1;
206  
207 }
208  
209 sub include_tags {
210  
211 82 ▶ my ($self) = @_;
Subroutine include_tags: called CC=1 SCAR=0.0
Pod documented
212  
213 82 return $self->{ IncludeTags };
214  
215 }
216  
217 sub set_include_tags {
218  
219 24 ▶ my ($self, $new) = @_;
Subroutine set_include_tags: called CC=2 SCAR=7.6
Pod documented
220  
221 24 ▶ if (ref $new ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new ne "ARRAY") 0 24 24
222 0 die "include_tags must be an array ref";
223 }
224  
225 24 $self->{ IncludeTags } = $new;
226  
227 }
228  
229 sub exclude_tags {
230  
231 70 ▶ my ($self) = @_;
Subroutine exclude_tags: called CC=1 SCAR=0.0
Pod documented
232  
233 70 return $self->{ ExcludeTags };
234  
235 }
236  
237 sub set_exclude_tags {
238  
239 24 ▶ my ($self, $new) = @_;
Subroutine set_exclude_tags: called CC=2 SCAR=7.6
Pod documented
240  
241 24 ▶ if (ref $new ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new ne "ARRAY") 0 24 24
242 0 die "exclude_tags must be an array ref";
243 }
244  
245 24 $self->{ ExcludeTags } = $new;
246  
247 }
248  
249 sub tags_ok {
250  
251 57 ▶ my ($self, $tags) = @_;
Subroutine tags_ok: called CC=8 SCAR=21.0
Pod documented
252  
253 57 ▶ my %tagmap = defined $tags ? (map { fc $_ => 1 } @$tags) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $tags ? : 57 0 57
254  
255 57 ▶ if (@{ $self->include_tags }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->include_tags;}) 14 43 57
256 14 ▶ unless (defined $tags) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tags) 0 14 14
257 0 return 0;
258 }
259 14 ▶ if (any { not exists $tagmap{ fc $_ } } @{ $self->include_tags }) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { not exists $tagmap{fc $_}; } , @{$self->include_tags;})) 8 6 14
260 8 return 0;
261 }
262 }
263  
264 49 ▶ if (@{ $self->exclude_tags }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->exclude_tags;}) 10 39 49
265 10 ▶ unless (defined $tags) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tags) 0 10 10
266 0 return 1;
267 }
268 10 ▶ if (any { exists $tagmap{ fc $_ } } @{ $self->exclude_tags }) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { exists $tagmap{fc $_}; } , @{$self->exclude_tags;})) 4 6 10
269 4 return 0;
270 }
271 }
272  
273 45 return 1;
274  
275 }
276  
277 sub autoread {
278  
279 13 ▶ my ($self) = @_;
Subroutine autoread: called CC=1 SCAR=0.0
Pod documented
280  
281 13 return $self->{ Autoread };
282  
283 }
284  
285 sub set_autoread {
286  
287 26 ▶ my ($self, $read) = @_;
Subroutine set_autoread: called CC=1 SCAR=0.0
Pod documented
288  
289 26 $self->{ Autoread } = !! $read;
290  
291 }
292  
293 sub default_update {
294  
295 6 ▶ my ($self) = @_;
Subroutine default_update: called CC=1 SCAR=0.0
Pod documented
296  
297 6 return $self->{ DefaultUpdate };
298  
299 }
300  
301 sub set_default_update {
302  
303 26 ▶ my ($self, $new) = @_;
Subroutine set_default_update: called CC=1 SCAR=0.0
Pod documented
304  
305 26 $self->{ DefaultUpdate } = !! $new;
306  
307 }
308  
309 sub hidden {
310  
311 5 ▶ my ($self) = @_;
Subroutine hidden: called CC=1 SCAR=0.0
Pod documented
312  
313 5 return $self->{ Hidden };
314  
315 }
316  
317 sub set_hidden {
318  
319 26 ▶ my ($self, $new) = @_;
Subroutine set_hidden: called CC=1 SCAR=0.0
Pod documented
320  
321 26 $self->{ Hidden } = !! $new;
322  
323 }
324  
325 =head1 NAME
326  
327 WWW::Noss::BaseConfig - Base class for feed configuration classes
328  
329 =head1 USAGE
330  
331 use parent 'WWW::Noss::BaseConfig';
332  
333 =head1 DESCRIPTION
334  
335 B<WWW::Noss::BaseConfig> is a class that implements the base functionality for
336 the L<WWW::Noss::FeedConfig> and L<WWW::Noss::GroupConfig> modules. This is a
337 private module, please consult the L<noss> manual for user documentation.
338  
339 =head1 METHODS
340  
341 =over 4
342  
343 =item $conf = WWW::Noss::BaseConfig->new(%param)
344  
345 Default constructor for B<WWW::Noss::BaseConfig>. Parameters are supplied via
346 the C<%param> hash.
347  
348 The following are valid fields for C<%param>:
349  
350 =over 4
351  
352 =item limit
353  
354 Post limit. Should be an integar that is greater than C<0>, or C<undef> for no
355 limit.
356  
357 =item respect_skip
358  
359 Boolean determining whether the B<skipHours> and B<skipDays> fields in RSS
360 feeds should be respected.
361  
362 =item include_title
363  
364 Array ref of regexes that post titles must match in order to not be filtered
365 out.
366  
367 =item exclude_title
368  
369 Array ref of regexes that post titles must NOT match in order to not be
370 filtered out.
371  
372 =item include_content
373  
374 Array ref of regexes that a post's content must match in order to not be
375 filtered out.
376  
377 =item exclude_content
378  
379 Array ref of regexes that a post's content must NOT match in order to not be
380 filtered out.
381  
382 =item include_tags
383  
384 Array ref of tags that a post must have in order to not be filtered out.
385  
386 =item exclude_tags
387  
388 Array ref of tags that a post must NOT have in order to not be filtered out.
389  
390 =item autoread
391  
392 Boolean determining whether new posts will automatically be marked as read or
393 not.
394  
395 =item default_update
396  
397 Boolean determining whether a feed should be included in a default update or
398 not.
399  
400 =item hidden
401  
402 Boolean determining whether a feed should be omitted from the C<list> command's
403 default listing.
404  
405 =back
406  
407 =item $limit = $conf->limit()
408  
409 =item $conf->set_limit($limit)
410  
411 Getter/setter for the C<limit> attribute.
412  
413 =item $respect = $conf->respect_skip()
414  
415 =item $conf->set_respect_skip($respect)
416  
417 Getter/setter for the C<respect_skip> attribute.
418  
419 =item \@inc = $conf->include_title()
420  
421 =item $conf->set_include_title(\@inc)
422  
423 =item \@exc = $conf->exclude_title()
424  
425 =item $conf->set_exclude_title(\@exc)
426  
427 Getter/setters for the C<include_title> and C<exclude_title> attributes.
428  
429 =item \@inc = $conf->include_content()
430  
431 =item $conf->set_include_content(\@inc)
432  
433 =item \@exc = $conf->exclude_content()
434  
435 =item $conf->set_exclude_content(\@exc)
436  
437 Getter/setters for the C<include_content> and C<exclude_content> attributes.
438  
439 =item \@inc = $conf->include_tags()
440  
441 =item $conf->set_include_tags(\@inc)
442  
443 =item \@exc = $conf->exclude_tags()
444  
445 =item $conf->set_exclude_tags(\@exc)
446  
447 Getter/setters for the C<include_tags> and C<exclude_tags> attributes.
448  
449 =item $autoread = $conf->autoread()
450  
451 =item $conf->set_autoread($autoread)
452  
453 Getter/setter for the C<autoread> attribute.
454  
455 =item $default = $conf->default_update()
456  
457 =item $conf->set_default_update($default)
458  
459 Getter/setter for the C<default_update> attribute.
460  
461 =item $hidden = $conf->hidden()
462  
463 =item $conf->set_hidden($hidden)
464  
465 Getter/setter for the C<hidden> attribute.
466  
467 =item $ok = $conf->title_ok($title)
468  
469 =item $ok = $conf->content_ok($content)
470  
471 =item $ok = $conf->tags_ok(\@tags)
472  
473 Methods returning a boolean of whether the given title/content/tags are
474 acceptable according to their respective include and exclude attributes.
475  
476 =back
477  
478 =head1 AUTHOR
479  
480 Written by Samuel Young, E<lt>samyoung12788@gmail.comE<gt>.
481  
482 This project's source can be found on its
483 L<Codeberg page|https://codeberg.org/1-1sam/noss.git>. Comments and pull
484 requests are welcome!
485  
486 =head1 COPYRIGHT
487  
488 Copyright (C) 2025-2026 Samuel Young
489  
490 This program is free software: you can redistribute it and/or modify
491 it under the terms of the GNU General Public License as published by
492 the Free Software Foundation, either version 3 of the License, or
493 (at your option) any later version.
494  
495 =head1 SEE ALSO
496  
497 L<WWW::Noss::FeedConfig>, L<WWW::Noss::GroupConfig>, L<noss>
498  
499 =cut
500  
501 6 1;
502  
503 # vim: expandtab shiftwidth=4
« Noss/Timestamp.pm ↑ Summary Noss/Util.pm »