File Coverage

blib/lib/App/SpamcupNG/Error.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition 5 5 100.0
subroutine 5 5 100.0
pod 3 3 100.0
total 36 36 100.0


line stmt bran cond sub pod time code
1             package App::SpamcupNG::Error;
2 13     13   109581 use strict;
  13         43  
  13         421  
3 13     13   71 use warnings;
  13         31  
  13         3609  
4              
5             our $VERSION = '0.016'; # VERSION
6              
7             =head1 NAME
8              
9             App::SpamcupNG::Error - base class for Spamcop website errors
10              
11             =head1 SYNOPSIS
12              
13             use parent 'App::SpamcupNG::Error';
14              
15             =head1 DESCRIPTION
16              
17             This is a base class to represent error messages after parsing Spamcop HTML.
18              
19             =head1 METHODS
20              
21             =head2 new
22              
23             Creates a new instance. Instances of C<App::Spamcup::Error> shouldn't be
24             created directly, use one of the subclasses of it.
25              
26             Expect as parameters:
27              
28             - an array reference containing all the strings from the original message. - a
29             scalar with 0 or 1 to indicate that the message should be considered fatal or
30             not.
31              
32             A message parsed from Spamcop website HTML that should stop the SPAM processing
33             should be considered as fatal.
34              
35             =cut
36              
37             sub new {
38 13     13 1 1556 my ( $class, $message_ref, $is_fatal ) = @_;
39 13   100     49 $is_fatal //= 0;
40              
41             die 'message must be an non empty array reference'
42             unless ( ( ref($message_ref) eq 'ARRAY' )
43 13 100 100     62 and ( scalar( @{$message_ref} ) > 0 ) );
  11         45  
44              
45 10         25 for ( my $i = 0 ; $i < scalar( @{$message_ref} ) ; $i++ ) {
  26         56  
46 16         47 $message_ref->[$i] =~ s/^\s+//;
47 16         78 $message_ref->[$i] =~ s/\s+$//;
48             }
49              
50 10         31 my $self = {
51             message => $message_ref,
52             is_fatal => $is_fatal
53             };
54              
55 10         21 bless( $self, $class );
56 10         39 return $self;
57             }
58              
59             =head2 message
60              
61             Returns the message associated with the error.
62              
63             =cut
64              
65             sub message {
66 4     4 1 1159 my $self = shift;
67 4         19 return $self->{message}->[0];
68             }
69              
70             =head2 is_fatal
71              
72             Returns 0 if the error is not fatal, 1 otherwise.
73              
74             =cut
75              
76             sub is_fatal {
77 10     10 1 4219 my $self = shift;
78 10         61 return $self->{is_fatal};
79             }
80              
81             =head1 AUTHOR
82              
83             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>
84              
85             =head1 COPYRIGHT AND LICENSE
86              
87             This software is copyright (c) 2018 of Alceu Rodrigues de Freitas Junior,
88             E<lt>arfreitas@cpan.orgE<gt>
89              
90             This file is part of App-SpamcupNG distribution.
91              
92             App-SpamcupNG is free software: you can redistribute it and/or modify it under
93             the terms of the GNU General Public License as published by the Free Software
94             Foundation, either version 3 of the License, or (at your option) any later
95             version.
96              
97             App-SpamcupNG is distributed in the hope that it will be useful, but WITHOUT
98             ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
99             FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
100              
101             You should have received a copy of the GNU General Public License along with
102             App-SpamcupNG. If not, see <http://www.gnu.org/licenses/>.
103              
104             =cut
105              
106             1;