File Coverage

blib/lib/Mail/SPF/Exception.pm
Criterion Covered Total %
statement 18 34 52.9
branch 1 6 16.6
condition 0 3 0.0
subroutine 6 11 54.5
pod 2 3 66.6
total 27 57 47.3


line stmt bran cond sub pod time code
1             #
2             # Mail::SPF::Exception
3             # Mail::SPF exception classes.
4             #
5             # (C) 2006 Julian Mehnle
6             # $Id: Exception.pm 36 2006-12-09 19:01:46Z Julian Mehnle $
7             #
8             ##############################################################################
9              
10             package Mail::SPF::Exception;
11              
12             =head1 NAME
13              
14             Mail::SPF::Exception - SPF exception class
15              
16             =head1 VERSION
17              
18             version 3.20250505
19              
20             =cut
21              
22 7     7   48 use warnings;
  7         13  
  7         401  
23 7     7   43 use strict;
  7         10  
  7         205  
24              
25 7     7   33 use base 'Error', 'Mail::SPF::Base';
  7         15  
  7         1567  
26              
27 7     7   47 use constant TRUE => (0 == 0);
  7         19  
  7         748  
28 7     7   47 use constant FALSE => not TRUE;
  7         16  
  7         9172  
29              
30             sub new {
31 13     13 1 410 my ($self, $text) = @_;
32 13         29 local $Error::Depth = $Error::Depth + 1;
33 13 50       85 return $self->SUPER::new(
34             defined($text) ? (-text => $text) : ()
35             );
36             }
37              
38             sub stringify {
39 0     0 1   my ($self) = @_;
40 0           my $text = $self->SUPER::stringify;
41 0 0         $text .= sprintf(" (%s) at %s line %d.\n", $self->name, $self->file, $self->line)
42             if $text !~ /\n$/s;
43 0           return $text;
44             }
45              
46             sub name {
47 0     0 0   my ($self) = @_;
48 0   0       my $class = ref($self) || $self;
49 0 0         return $class =~ /^Mail::SPF::(\w+)$/ ? $1 : $class;
50             }
51              
52              
53             # Generic Exceptions
54             ##############################################################################
55              
56             # Tried to call a class method as an instance method:
57             package Mail::SPF::EClassMethod;
58             our @ISA = qw(Mail::SPF::Exception);
59              
60             sub new {
61 0     0     my ($self) = @_;
62 0           local $Error::Depth = $Error::Depth + 2;
63 0           return $self->SUPER::new(
64             sprintf('Pure class method %s called as an instance method', (caller($Error::Depth - 1))[3])
65             );
66             }
67              
68             # Tried to call an instance method as a class method:
69             package Mail::SPF::EInstanceMethod;
70             our @ISA = qw(Mail::SPF::Exception);
71              
72             sub new {
73 0     0     my ($self) = @_;
74 0           local $Error::Depth = $Error::Depth + 2;
75 0           return $self->SUPER::new(
76             sprintf('Pure instance method %s called as a class method', (caller($Error::Depth - 1))[3])
77             );
78             }
79              
80             # Abstract class cannot be instantiated:
81             package Mail::SPF::EAbstractClass;
82             our @ISA = qw(Mail::SPF::Exception);
83              
84             sub new {
85 0     0     my ($self) = @_;
86 0           local $Error::Depth = $Error::Depth + 2;
87 0           return $self->SUPER::new('Abstract class cannot be instantiated');
88             }
89              
90             # Missing required method option:
91             package Mail::SPF::EOptionRequired;
92             our @ISA = qw(Mail::SPF::Exception);
93              
94             # Invalid value for method option:
95             package Mail::SPF::EInvalidOptionValue;
96             our @ISA = qw(Mail::SPF::Exception);
97              
98             # Read-only value:
99             package Mail::SPF::EReadOnlyValue;
100             our @ISA = qw(Mail::SPF::Exception);
101              
102              
103             # Miscellaneous Errors
104             ##############################################################################
105              
106             # DNS error:
107             package Mail::SPF::EDNSError;
108             our @ISA = qw(Mail::SPF::Exception);
109              
110             # DNS timeout:
111             package Mail::SPF::EDNSTimeout;
112             our @ISA = qw(Mail::SPF::EDNSError);
113              
114             # Record selection error:
115             package Mail::SPF::ERecordSelectionError;
116             our @ISA = qw(Mail::SPF::Exception);
117              
118             # No acceptable record found:
119             package Mail::SPF::ENoAcceptableRecord;
120             our @ISA = qw(Mail::SPF::ERecordSelectionError);
121              
122             # Redundant acceptable records found:
123             package Mail::SPF::ERedundantAcceptableRecords;
124             our @ISA = qw(Mail::SPF::ERecordSelectionError);
125              
126             # No unparsed text available:
127             package Mail::SPF::ENoUnparsedText;
128             our @ISA = qw(Mail::SPF::Exception);
129              
130             # Unexpected term object encountered:
131             package Mail::SPF::EUnexpectedTermObject;
132             our @ISA = qw(Mail::SPF::Exception);
133              
134             # Processing limit exceeded:
135             package Mail::SPF::EProcessingLimitExceeded;
136             our @ISA = qw(Mail::SPF::Exception);
137              
138             # Missing required context for macro expansion:
139             package Mail::SPF::EMacroExpansionCtxRequired;
140             our @ISA = qw(Mail::SPF::EOptionRequired);
141              
142              
143             # Parser Errors
144             ##############################################################################
145              
146             # Nothing to parse:
147             package Mail::SPF::ENothingToParse;
148             our @ISA = qw(Mail::SPF::Exception);
149              
150             # Generic syntax error:
151             package Mail::SPF::ESyntaxError;
152             our @ISA = qw(Mail::SPF::Exception);
153              
154             # Invalid record version:
155             package Mail::SPF::EInvalidRecordVersion;
156             our @ISA = qw(Mail::SPF::ESyntaxError);
157              
158             # Invalid scope:
159             package Mail::SPF::EInvalidScope;
160             our @ISA = qw(Mail::SPF::ESyntaxError);
161              
162             # Junk encountered in record:
163             package Mail::SPF::EJunkInRecord;
164             our @ISA = qw(Mail::SPF::ESyntaxError);
165              
166             # Invalid term:
167             package Mail::SPF::EInvalidTerm;
168             our @ISA = qw(Mail::SPF::ESyntaxError);
169              
170             # Junk encountered in term:
171             package Mail::SPF::EJunkInTerm;
172             our @ISA = qw(Mail::SPF::ESyntaxError);
173              
174             # Invalid modifier:
175             package Mail::SPF::EInvalidMod;
176             our @ISA = qw(Mail::SPF::EInvalidTerm);
177              
178             # Duplicate global modifier:
179             package Mail::SPF::EDuplicateGlobalMod;
180             our @ISA = qw(Mail::SPF::EInvalidMod);
181              
182             # Invalid mechanism:
183             package Mail::SPF::EInvalidMech;
184             our @ISA = qw(Mail::SPF::EInvalidTerm);
185              
186             # Invalid mechanism qualifier:
187             package Mail::SPF::EInvalidMechQualifier;
188             our @ISA = qw(Mail::SPF::EInvalidMech);
189              
190             # Missing required in term:
191             package Mail::SPF::ETermDomainSpecExpected;
192             our @ISA = qw(Mail::SPF::ESyntaxError);
193              
194             # Missing required in term:
195             package Mail::SPF::ETermIPv4AddressExpected;
196             our @ISA = qw(Mail::SPF::ESyntaxError);
197              
198             # Missing required in term:
199             package Mail::SPF::ETermIPv4PrefixLengthExpected;
200             our @ISA = qw(Mail::SPF::ESyntaxError);
201              
202             # Missing required in term:
203             package Mail::SPF::ETermIPv6AddressExpected;
204             our @ISA = qw(Mail::SPF::ESyntaxError);
205              
206             # Missing required in term:
207             package Mail::SPF::ETermIPv6PrefixLengthExpected;
208             our @ISA = qw(Mail::SPF::ESyntaxError);
209              
210             # Invalid macro string:
211             package Mail::SPF::EInvalidMacroString;
212             our @ISA = qw(Mail::SPF::ESyntaxError);
213              
214             # Invalid macro:
215             package Mail::SPF::EInvalidMacro;
216             our @ISA = qw(Mail::SPF::EInvalidMacroString);
217              
218              
219             package Mail::SPF::Exception;
220              
221             TRUE;