File Coverage

blib/lib/WWW/Noss/BaseConfig.pm
Criterion Covered Total %
statement 129 142 90.8
branch 38 52 73.0
condition 22 23 95.6
subroutine 37 37 100.0
pod 26 27 96.3
total 252 281 89.6


line stmt bran cond sub pod time code
1             package WWW::Noss::BaseConfig;
2 6     6   190554 use 5.016;
  6         25  
3 6     6   35 use strict;
  6         10  
  6         190  
4 6     6   26 use warnings;
  6         11  
  6         477  
5             our $VERSION = '2.02';
6              
7 6     6   35 use List::Util qw(any all);
  6         20  
  6         13557  
8              
9             sub new {
10              
11 1     1 1 1914 my ($class, %param) = @_;
12              
13 1         3 my $self = bless {}, $class;
14              
15 1         24 $self->initialize(%param);
16              
17 1         7 return $self;
18              
19             }
20              
21             sub initialize {
22              
23 23     23 0 72 my ($self, %param) = @_;
24              
25 23         113 $self->set_limit($param{ limit });
26 23   100     160 $self->set_respect_skip($param{ respect_skip } // 1);
27 23   100     145 $self->set_include_title($param{ include_title } // []);
28 23   100     125 $self->set_exclude_title($param{ exclude_title } // []);
29 23   100     152 $self->set_include_content($param{ include_content } // []);
30 23   100     128 $self->set_exclude_content($param{ exclude_content } // []);
31 23   100     122 $self->set_include_tags($param{ include_tags } // []);
32 23   100     125 $self->set_exclude_tags($param{ exclude_tags } // []);
33 23   100     138 $self->set_autoread($param{ autoread } // 0);
34 23   100     131 $self->set_default_update($param{ default_update } // 1);
35 23   100     113 $self->set_hidden($param{ hidden } // 0);
36              
37 23         67 return 1;
38              
39             }
40              
41             sub limit {
42              
43 25     25 1 2025 my ($self) = @_;
44              
45 25         125 return $self->{ Limit };
46              
47             }
48              
49             sub set_limit {
50              
51 27     27 1 86 my ($self, $new) = @_;
52              
53 27 50 66     149 if (defined $new and $new <= 0) {
54 0         0 die "limit must be greater than 0";
55             }
56              
57 27         107 $self->{ Limit } = $new;
58              
59             }
60              
61             sub respect_skip {
62              
63 5     5 1 15 my ($self) = @_;
64              
65 5         52 return $self->{ RespectSkip };
66              
67             }
68              
69             sub set_respect_skip {
70              
71 25     25 1 57 my ($self, $new) = @_;
72              
73 25         55 $self->{ RespectSkip } = !! $new;
74              
75             }
76              
77             sub include_title {
78              
79 101     101 1 174 my ($self) = @_;
80              
81 101         277 return $self->{ IncludeTitle };
82              
83             }
84              
85             sub set_include_title {
86              
87 24     24 1 117 my ($self, $new) = @_;
88              
89 24 50       101 if (ref $new ne 'ARRAY') {
90 0         0 die "include_title must be an array ref";
91             }
92              
93 24         54 $self->{ IncludeTitle } = $new;
94              
95             }
96              
97             sub exclude_title {
98              
99 95     95 1 138 my ($self) = @_;
100              
101 95         228 return $self->{ ExcludeTitle };
102              
103             }
104              
105             sub set_exclude_title {
106              
107 24     24 1 66 my ($self, $new) = @_;
108              
109 24 50       63 if (ref $new ne 'ARRAY') {
110 0         0 die "exclude_title must be an array ref";
111             }
112              
113 24         53 $self->{ ExcludeTitle } = $new;
114              
115             }
116              
117             sub title_ok {
118              
119 76     76 1 132 my ($self, $title) = @_;
120              
121 76 100       94 if (@{ $self->include_title }) {
  76         179  
122 14 50       29 unless (defined $title) {
123 0         0 return 0;
124             }
125 14 100   42   79 unless (all { $title =~ $_ } @{ $self->include_title }) {
  42         276  
  14         25  
126 4         10 return 0;
127             }
128             }
129              
130 72 100       107 if (@{ $self->exclude_title }) {
  72         147  
131 12 50       24 unless (defined $title) {
132 0         0 return 1;
133             }
134 12 100   25   31 if (any { $title =~ $_ } @{ $self->exclude_title }) {
  25         124  
  12         18  
135 7         26 return 0;
136             }
137             }
138              
139 65         147 return 1;
140              
141             }
142              
143             sub include_content {
144              
145 92     92 1 135 my ($self) = @_;
146              
147 92         226 return $self->{ IncludeContent };
148              
149             }
150              
151             sub set_include_content {
152              
153 24     24 1 46 my ($self, $new) = @_;
154              
155 24 50       61 if (ref $new ne 'ARRAY') {
156 0         0 die "include_content must be an array ref";
157             }
158              
159 24         57 $self->{ IncludeContent } = $new;
160              
161             }
162              
163             sub exclude_content {
164              
165 87     87 1 128 my ($self) = @_;
166              
167 87         205 return $self->{ ExcludeContent };
168              
169             }
170              
171             sub set_exclude_content {
172              
173 24     24 1 50 my ($self, $new) = @_;
174              
175 24 50       62 if (ref $new ne 'ARRAY') {
176 0         0 die "exclude_content must be an array ref";
177             }
178              
179 24         53 $self->{ ExcludeContent } = $new;
180              
181             }
182              
183             sub content_ok {
184              
185 67     67 1 115 my ($self, $content) = @_;
186              
187 67 100       76 if (@{ $self->include_content }) {
  67         166  
188 14 50       28 unless (defined $content) {
189 0         0 return 0;
190             }
191 14 100   37   40 if (not all { $content =~ $_ } @{ $self->include_content }) {
  37         256  
  14         39  
192 4         11 return 0;
193             }
194             }
195              
196 63 100       127 if (@{ $self->exclude_content }) {
  63         162  
197 13 50       26 unless (defined $content) {
198 0         0 return 1;
199             }
200 13 100   22   34 if (any { $content =~ $_ } @{ $self->exclude_content }) {
  22         142  
  13         23  
201 8         29 return 0;
202             }
203             }
204              
205 55         162 return 1;
206              
207             }
208              
209             sub include_tags {
210              
211 82     82 1 136 my ($self) = @_;
212              
213 82         225 return $self->{ IncludeTags };
214              
215             }
216              
217             sub set_include_tags {
218              
219 24     24 1 45 my ($self, $new) = @_;
220              
221 24 50       62 if (ref $new ne 'ARRAY') {
222 0         0 die "include_tags must be an array ref";
223             }
224              
225 24         107 $self->{ IncludeTags } = $new;
226              
227             }
228              
229             sub exclude_tags {
230              
231 70     70 1 144 my ($self) = @_;
232              
233 70         166 return $self->{ ExcludeTags };
234              
235             }
236              
237             sub set_exclude_tags {
238              
239 24     24 1 46 my ($self, $new) = @_;
240              
241 24 50       78 if (ref $new ne 'ARRAY') {
242 0         0 die "exclude_tags must be an array ref";
243             }
244              
245 24         45 $self->{ ExcludeTags } = $new;
246              
247             }
248              
249             sub tags_ok {
250              
251 57     57 1 99 my ($self, $tags) = @_;
252              
253 57 50       143 my %tagmap = defined $tags ? (map { fc $_ => 1 } @$tags) : ();
  195         534  
254              
255 57 100       102 if (@{ $self->include_tags }) {
  57         122  
256 14 50       33 unless (defined $tags) {
257 0         0 return 0;
258             }
259 14 100   37   57 if (any { not exists $tagmap{ fc $_ } } @{ $self->include_tags }) {
  37         94  
  14         53  
260 8         31 return 0;
261             }
262             }
263              
264 49 100       78 if (@{ $self->exclude_tags }) {
  49         117  
265 10 50       22 unless (defined $tags) {
266 0         0 return 1;
267             }
268 10 100   18   40 if (any { exists $tagmap{ fc $_ } } @{ $self->exclude_tags }) {
  18         39  
  10         22  
269 4         18 return 0;
270             }
271             }
272              
273 45         174 return 1;
274              
275             }
276              
277             sub autoread {
278              
279 13     13 1 46 my ($self) = @_;
280              
281 13         678 return $self->{ Autoread };
282              
283             }
284              
285             sub set_autoread {
286              
287 26     26 1 69 my ($self, $read) = @_;
288              
289 26         71 $self->{ Autoread } = !! $read;
290              
291             }
292              
293             sub default_update {
294              
295 6     6 1 14 my ($self) = @_;
296              
297 6         25 return $self->{ DefaultUpdate };
298              
299             }
300              
301             sub set_default_update {
302              
303 26     26 1 51 my ($self, $new) = @_;
304              
305 26         58 $self->{ DefaultUpdate } = !! $new;
306              
307             }
308              
309             sub hidden {
310              
311 5     5 1 15 my ($self) = @_;
312              
313 5         24 return $self->{ Hidden };
314              
315             }
316              
317             sub set_hidden {
318              
319 26     26 1 55 my ($self, $new) = @_;
320              
321 26         89 $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 is a class that implements the base functionality for
336             the L and L modules. This is a
337             private module, please consult the L 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. 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 for no
355             limit.
356              
357             =item respect_skip
358              
359             Boolean determining whether the B and B 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 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 attribute.
412              
413             =item $respect = $conf->respect_skip()
414              
415             =item $conf->set_respect_skip($respect)
416              
417             Getter/setter for the C 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 and C 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 and C 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 and C attributes.
448              
449             =item $autoread = $conf->autoread()
450              
451             =item $conf->set_autoread($autoread)
452              
453             Getter/setter for the C attribute.
454              
455             =item $default = $conf->default_update()
456              
457             =item $conf->set_default_update($default)
458              
459             Getter/setter for the C attribute.
460              
461             =item $hidden = $conf->hidden()
462              
463             =item $conf->set_hidden($hidden)
464              
465             Getter/setter for the C 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, Esamyoung12788@gmail.comE.
481              
482             This project's source can be found on its
483             L. 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, L, L
498              
499             =cut
500              
501             1;
502              
503             # vim: expandtab shiftwidth=4