Noss/BaseConfig.pm

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