blib/lib/Mail/Log/Trace.pm

filter: Statementstmt 97.4% 229 / 235 Branchbran 86.3% 38 / 44 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 51 / 51 Podpod 100% 8 / 8 totaltotal 96.4% 326 / 338 SCAR 35.9
CC
36
Cov
96%
new
11.1
_parse_args
9.0
__ANON__
5.0
CRAP 36.1
« blib/lib/Mail/Log/Trace/Postfix.pm ↑ Summary Build »
1 #!/usr/bin/perl
2  
3  
4 package Mail::Log::Trace;
5 {
6 =head1 NAME
7  
8 Mail::Log::Trace - Trace an email through the mailsystem logs.
9  
10 =head1 SYNOPSIS
11  
12 use Mail::Log::Trace;
13
14 my $tracer = Mail::Log::Trace::SUBCLASS->new({log_file => 'path/to/log'});
15 $tracer->set_message_id('message_id');
16 $tracer->find_message();
17 my $from_address = $tracer->get_from_address();
18
19 etc.
20  
21 =head1 DESCRIPTION
22  
23 This is the root-level class for a mail tracer: It allows you to search for
24 and find messages in maillogs. Accessors are provided for info common to
25 most maillogs: Specific subclasses may have further accessors depending on their
26 situation.
27  
28 Probably the two methods most commonly used (and sort of the point of this
29 module) are C<find_message> and C<find_message_info>. Both are simply stubs
30 for subclasses to implement: The first is defined to find the first (or first
31 from current location...) mention of the specified message in the log.
32 Depending on the log format that may or may not be the only mention, and there
33 may be information missing/incomplete at that point.
34  
35 C<find_message_info> should find I<all> information about a specific message
36 in the log. (Well, all information about a specific instance of the message:
37 If there are multiple messages that would match the info provided it must
38 find info on the first found.) That may mean searching through the log for
39 other information.
40  
41 If you just need to find if the message exists, use C<find_message>: it will
42 be faster (or at the least, the same speed. It should never be slower.)
43  
44 =head1 USAGE
45  
46 This is a an object-orientend module, with specific methods documented below.
47  
48 The string coersion is overloaded to return the class name, and the file
49 we are working with. Boolean currently checks to see if we were able to
50 open the file. (Which is kinda silly, as we'd throw an error if we couldn't.)
51  
52 All times are expected to be in Unix epoc-time format.
53  
54 =cut
55  
56 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 4 ▶use Scalar::Util qw(refaddr blessed reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
59 4 ▶use Mail::Log::Exceptions 1.0100;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 4 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 BEGIN {
63 4 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
64 4 ▶ use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
65 4 ▶ $VERSION = '1.0100_1';
Subroutine BEGIN: called CC=1 SCAR=0.0
66 #Give a hoot don't pollute, do not export more than needed by default
67 4 @EXPORT = qw();
68 4 @EXPORT_OK = qw();
69 4 %EXPORT_TAGS = ();
70 }
71  
72 #
73 # Define class variables. Note that they are hashes...
74 #
75  
76 4 my %message_info;
77 my %log_info;
78 4 my %message_raw_info;
79  
80 # Accessors.
81 4 my %public = ( from_address => undef,
82 message_id => undef,
83 recieved_time => undef,
84 sent_time => undef,
85 relay => undef,
86 subject => undef,
87 );
88 4 my %public_set_only = ();
89 4 my %public_get_only = ( connect_time => undef, disconnect_time => undef, delay => undef );
90 4 my %array_accessors = ( to_address => undef );
91 4 my @valid_parameters;
92 4 my @checked_parameters = qw(from_address message_id recieved_time sent_time relay
93 subject to_address);
94 4 my %all_setters;
95 my %all_getters;
96  
97 4 my @cleared_parameters = qw(from_address message_id recieved_time sent_time
98 relay to_address subject connect_time disconnect_time
99 delay);
100  
101 #
102 # DESTROY class variables.
103 #
104 ### IF NOT DONE THERE IS A MEMORY LEAK. ###
105  
106 sub DESTROY {
107 37 ▶ my ($self) = @_;
Subroutine DESTROY: called CC=1 SCAR=0.0
108
109 37 delete $message_info{$$self};
110 37 delete $log_info{$$self};
111 37 delete $message_raw_info{$$self};
112 37 delete $all_setters{$$self};
113 37 delete $all_getters{$$self};
114
115 37 return;
116 }
117  
118 #
119 # Set the coercions to something useful.
120 #
121  
122 use overload (
123 # Strings overload to the path and line number.
124 2 ▶ qw{""} => sub { my ($self) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
125 return blessed($self)
126 .' File: '
127 2 .$log_info{$$self}{'filename'};
128 },
129
130 # Boolean overloads to if we are usable. (Have a filehandle.)
131 2 ▶ qw{bool} => sub { my ($self) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
132 2 return defined($log_info{$$self}{'log_parser'});
133 },
134
135 # Numeric context just doesn't mean anything. Throw an error.
136 2 ▶ q{0+} => sub { Mail::Log::Exceptions->throw(q{Can't get a numeric value of a Mail::Log::Trace.} );
Subroutine __ANON__: called CC=1 SCAR=0.0
137 },
138
139 # Perl standard for everything else.
140 4 fallback => 1,
141 4 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
142  
143  
144 =head2 new (constructor)
145  
146 The base constructor for the Mail::Log::Trace classes. It takes inital values
147 for the following in a hash: C<from_address>, C<to_address>, C<message_id>,
148 C<log_file>. The only required value is the path to the logfile.
149  
150 use Mail::Log::Trace;
151 my $object = Mail::Log::Trace->new({ from_address => 'from@example.com',
152 to_address => 'to@example.com',
153 message_id => 'messg.id.string',
154 log_file => 'path/to/log',
155 });
156  
157 =cut
158  
159 sub new
160 {
161 37 ▶ my ($class, $parameters_ref) = @_;
Subroutine new: called CC=11 SCAR=24.1
Pod documented
162  
163 37 my $self = bless \do{my $anon}, $class;
164 37 $$self = refaddr $self;
165  
166 # Build accessors
167
168 # Get stuff from the any base classes.
169 37 my @public = $self->_requested_public_accessors();
170 37 my %public_special = $self->_requested_special_accessors();
171 37 my @public_set_only = $self->_requested_public_set_only();
172 37 my @public_get_only = $self->_requested_public_get_only();
173 37 my @array = $self->_requested_array_accessors();
174
175 37 @checked_parameters = ($self->_set_as_message_info(), @checked_parameters);
176 37 ▶ my %checked_parameters = map { $_ => undef if $_ ne ''; } @checked_parameters;
Branch: 1 branch
BranchTrueFalseTotal
if $_ ne "" 391 0 391
177 37 @checked_parameters = keys %checked_parameters;
178  
179 37 foreach my $item ( @public ) {
180 72 $public{$item} = undef;
181 }
182 37 foreach my $item ( @public_set_only ) {
183 0 $public_set_only{$item} = undef;
184 }
185 37 foreach my $item ( @public_get_only ) {
186 0 $public_get_only{$item} = undef;
187 }
188 37 foreach my $item ( @array ) {
189 0 $array_accessors{$item} = undef;
190 }
191
192 # Setters first.
193 37 my %merged_hash = (%public, %public_set_only, %public_special);
194 37 ▶ while ( my ($accessor, $action) = each %merged_hash ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %merged_hash) 318 37 355
195 318 $all_setters{$$self}{$accessor} = $self->_build_setter($accessor, 0, $action);
196 318 push @valid_parameters, $accessor;
197 }
198
199 # Now getters.
200 37 foreach my $accessor ( keys %public, keys %public_get_only, keys %public_special ) {
201 429 $all_getters{$$self}{$accessor} = $self->_build_getter($accessor);
202 }
203  
204 # Now build the private.
205 37 $all_setters{$$self}{$_} = $self->_build_setter($_, 1) foreach ( keys %public_get_only );
206 37 $all_getters{$$self}{$_} = $self->_build_getter($_, 1) foreach ( keys %public_set_only );
207  
208 # And the complex...
209 37 $self->_build_array_accessors($_) foreach ( keys %array_accessors );
210 37 push @valid_parameters, keys %array_accessors;
211  
212 # Get the list of parameters to clear when 'clear' is called.
213 37 my @requested_cleared = $self->_requested_cleared_parameters();
214 37 @requested_cleared = grep { defined($_) } @requested_cleared;
215 37 push @cleared_parameters, @requested_cleared;
216  
217 # Set up any/all passed parameters.
218 # (Only does message info. Note this can only be called after the above!)
219 37 $self->_parse_args($parameters_ref, 0);
220  
221 # Log info.
222 36 $self->set_log($parameters_ref->{'log_file'}); # Better to keep validation together.
223  
224 31 return $self;
225 }
226  
227 #
228 # The method factories.
229 #
230  
231 sub _build_setter {
232 429 ▶ my ($self, $attribute, $private, $action) = @_;
Subroutine _build_setter: called CC=3 SCAR=11.0
233
234 # Build the correct name.
235 429 my $sub_name = "set_$attribute";
236 429 ▶ $sub_name = "_$sub_name" if $private;
Branch: 1 branch
BranchTrueFalseTotal
if $private 111 318 429
237
238 # The typeglob below sets off all kinds of warnings.
239 # (The 'redefine' is because this happens for _every_object_.)
240 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
241 4 ▶ no warnings qw(redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
242
243 # Build the actual subroutine.
244 429 ▶ if ( defined($action) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $action) { } 24 405 429
245 # If we do processing or validation, give it a chance to happen.
246 return *$sub_name = sub {
247 4 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
248 9 ▶ my ($self, $new_id) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.2
249
250 # True if they accept the value, false otherwise.
251 # (To make validation easier.)
252 9 $new_id = $action->($self, $new_id);
253 9 ▶ if ( $new_id ne '____INVALID__VALUE____' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_id ne '____INVALID__VALUE____') { } 9 0 9
254 9 $message_info{$$self}{$attribute} = $new_id;
255 }
256 else {
257 # If they don't accept the value, tell the user.
258 0 Mail::Log::Exceptions::InvalidParameter->throw("'$new_id' is not a valid value for $attribute.\n");
259 }
260 9 return;
261 }
262 24 }
263 else {
264 # For basic setters, use a speed-optimized version.
265 return *$sub_name = sub {
266 757 ▶ $message_info{${$_[0]}}{$attribute} = $_[1];
Subroutine __ANON__: called CC=1 SCAR=0.0
267 757 return;
268 }
269 405 }
270 }
271  
272 sub _build_getter {
273 429 ▶ my ($self, $attribute, $private) = @_;
Subroutine _build_getter: called CC=2 SCAR=6.9
274  
275 # Build the correct name.
276 429 my $sub_name = "get_$attribute";
277 429 ▶ $sub_name = "_$sub_name" if $private;
Branch: 1 branch
BranchTrueFalseTotal
if $private 0 429 429
278  
279 # The typeglob below sets off all kinds of warnings.
280 # (The 'redefine' is because this happens for _every_object_.)
281 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
282 4 ▶ no warnings qw(redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
283  
284 # Build the actual subroutine. (As fast as we can make it.)
285 return *$sub_name = sub {
286 1626 ▶ return $message_info{${$_[0]}}{$attribute};
Subroutine __ANON__: called CC=1 SCAR=0.0
287 }
288 429 }
289  
290 sub _build_array_accessors {
291 37 ▶ my ($self, $attribute, $private) = @_;
Subroutine _build_array_accessors: called CC=3 SCAR=11.0
292  
293 37 my $get_name = "get_$attribute";
294 37 my $set_name = "set_$attribute";
295 37 my $add_name = "add_$attribute";
296 37 my $remove_name = "remove_$attribute";
297  
298 37 ▶ if ( $private ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($private) 0 37 37
299 0 foreach my $name ( ($get_name, $set_name, $add_name, $remove_name) ) {
300 0 $name = "_$name";
301 }
302 }
303  
304 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
305 4 ▶ no warnings qw(redefine);
Subroutine BEGIN: called CC=1 SCAR=0.0
306  
307 *$get_name = sub {
308 123 ▶ return $message_info{${$_[0]}}{$attribute};
Subroutine __ANON__: called CC=1 SCAR=0.0
309 37 };
310 37 $all_getters{$$self}{$attribute} = *$get_name;
311  
312 # Note that strict refs still aren't in effect.
313 # Needed for the call to $add_name below.
314 *$set_name = sub {
315 104 ▶ my ($self, $new_id) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
316 104 ▶ if (defined($new_id) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new_id) { } 101 3 104
317 101 @{$message_info{$$self}{$attribute}} = ();
318 101 $add_name->($self, $new_id);
319 }
320 else {
321 3 $message_info{$$self}->{$attribute} = undef;
322 }
323 104 return;
324 37 };
325 37 $all_setters{$$self}{$attribute} = *$set_name;
326  
327 *$add_name = sub {
328 4 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
329 191 ▶ my ($self, $new_id) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.1
330
331 # If we are given a single element, and we haven't seen it before,
332 # add it to the array.
333 191 ▶ if ( !defined(reftype($new_id)) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined builtin::reftype($new_id)) { } 178 13 191
elsif (builtin::reftype($new_id) eq 'ARRAY') { } 12 1 13
334 178 ▶ unless ( grep { $_ eq $new_id } @{$message_info{$$self}{$attribute}} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $new_id;} @{$message_info{$$self}{$attribute};}) 170 8 178
335 170 push @{$message_info{$$self}{$attribute}}, ($new_id);
336 }
337 }
338 # If we are given an array of elements, merge it with our current array.
339 elsif ( reftype($new_id) eq 'ARRAY' ) {
340 12 my %temp_hash;
341 12 foreach my $element (@{$message_info{$$self}{$attribute}}, @{$new_id}) {
342 26 $temp_hash{$element} = undef;
343 }
344 12 @{$message_info{$$self}{$attribute}} = keys %temp_hash;
345 }
346 191 return;
347 37 };
348  
349 *$remove_name = sub {
350 1 ▶ my ($self, $id) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
351 1 @{$message_info{$$self}{$attribute}}
352 1 = grep { $_ ne $id } @{$message_info{$$self}{$attribute}};
353 1 return;
354 37 };
355 }
356  
357 #
358 # Setters.
359 #
360  
361 =head2 SETTERS
362  
363 =head3 set_from_address
364  
365 Sets the from address of the message we are looking for.
366  
367 =head3 set_message_id
368  
369 Sets the message_id of the message we are looking for.
370 (Check with the specific parser class for what that means in a particular
371 log format.)
372  
373 =head3 set_recieved_time
374  
375 Sets the recieved time of the message we are looking for.
376 (The time this machine got the message.)
377  
378 =head3 set_sent_time
379  
380 Sets the sent time of the message we are looking for.
381 (The time this machine sent the message.)
382  
383 =head3 set_relay_host
384  
385 Sets the relay host of the message we are looking for. Commonly either
386 the relay we recieved it from, or the relay we sent it to. (Depending
387 on the logfile.)
388  
389 =head3 set_subject
390  
391 Sets the subject of the message we are looking for.
392  
393 =head3 set_parser_class
394  
395 Sets the parser class to use when searching the log file. A subclass will
396 have a 'default' parser that it will normally use: This is to allow easy
397 site-specific logfile formats based on more common formats. To use you
398 would subclass the default parser for the log file format of the base program
399 to handle the site's specific changes.
400  
401 Takes the name of a class as a string, and will throw an exception
402 (C<Mail::Log::Exceptions::InvalidParameter>) if that class name doesn't start
403 with Mail::Log::Parse.
404  
405 =cut
406  
407 sub set_parser_class {
408 6 ▶ my ($self, $new_id) = @_;
Subroutine set_parser_class: called CC=2 SCAR=6.9
Pod documented
409 6 ▶ if ( $new_id =~ /Mail::Log::Parse::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_id =~ /Mail::Log::Parse::/) { } 5 1 6
410 5 $log_info{$$self}{parser_class} = $new_id;
411 }
412 else {
413 1 Mail::Log::Exceptions::InvalidParameter->throw('Parser class needs to be a Mail::Log::Parse:: subclass.');
414 }
415 5 return;
416 }
417  
418 =head3 set_log
419  
420 Sets the log file we are searching throuh. Takes a full or relative path.
421 If it doesn't exist, or can't be read by the current user, it will throw an
422 exception. (C<Mail::Log::Exceptions::LogFile>) Note that it does I<not>
423 try to open it immedeately. That will be done at first attempt to read from
424 the logfile.
425  
426 =cut
427  
428 sub set_log {
429 38 ▶ my ($self, $new_name) = @_;
Subroutine set_log: called CC=4 SCAR=13.9
Pod documented
430  
431 38 ▶ if ( ! defined($new_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_name) 1 37 38
432 1 Mail::Log::Exceptions::InvalidParameter->throw('No log file specified in call to '.blessed($self).'->new().');
433 }
434  
435 # Check to make sure the file exists,
436 # and then that we can read it, before accpeting the filename.
437 37 ▶ if ( -e $new_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $new_name) { } 35 2 37
438 35 ▶ if ( -r $new_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $new_name) { } 33 2 35
439 33 $log_info{refaddr $self}{'filename'} = $new_name;
440 }
441 else {
442 2 Mail::Log::Exceptions::LogFile->throw("Log file $new_name is not readable.");
443 }
444 }
445 else {
446 2 Mail::Log::Exceptions::LogFile->throw("Log file $new_name does not exist.");
447 }
448  
449 # Reset the parser.
450 33 $self->_set_log_parser(undef);
451  
452 33 return;
453 }
454  
455 =head3 set_to_address
456  
457 Sets the to address of the message we are looking for. Multiple addresses can
458 be specified, they will all be added, with duplicates skipped. This method
459 completely clears the array: there will be no addresses in the list except
460 those given to it. Duplicates will be consolidated: Only one of any particular
461 address will be in the final array.
462  
463 As a special case, passing C<undef> to this will set the array to undef.
464  
465 =head3 add_to_address
466  
467 Adds to the list of to addresses we are looking for. It does I<not> delete the
468 array first.
469  
470 Duplicates will be consolidated, so that the array will only have one of any
471 given address. (No matter the order they are given in.)
472  
473 =head3 remove_to_address
474  
475 Removes a single to address from the array.
476  
477 =cut
478  
479 #
480 # Getters.
481 #
482  
483 =head2 GETTERS
484  
485 =head3 get_from_address
486  
487 Gets the from address. (Either as set using the setter, or as found in the
488 log.)
489  
490 =head3 get_to_address
491  
492 Gets the to address array. (Either as set using the setters, or as found in the
493 log.)
494  
495 Will return a reference to an array, or 'undef' if the to address has not been
496 set/found.
497  
498 =head3 get_message_id
499  
500 Gets the message_id. (Either as set using the setter, or as found in the
501 log.)
502  
503 =head3 get_subject
504  
505 Gets the message subject. (Either as set using the setter, or as found in the
506 log.)
507  
508 =head3 get_recieved_time
509  
510 Gets the recieved time. (Either as set using the setter, or as found in the
511 log.)
512  
513 =head3 get_sent_time
514  
515 Gets the sent time. (Either as set using the setter, or as found in the
516 log.)
517  
518 =head3 get_relay_host
519  
520 Gets the relay host. (Either as set using the setter, or as found in the
521 log.)
522  
523 =head3 get_log
524  
525 Returns the path to the logfile we are reading.
526  
527 =cut
528  
529 sub get_log {
530 28 ▶ my ($self) = @_;
Subroutine get_log: called CC=1 SCAR=0.0
Pod documented
531 28 return $log_info{$$self}{'filename'};
532 }
533  
534 =head3 get_connect_time
535  
536 Returns the time the remote host connected to this host to send the message.
537  
538 =head3 get_disconnect_time
539  
540 Returns the time the remote host disconnected from this host after sending
541 the message.
542  
543 =head3 get_delay
544  
545 Returns the total delay in this stage in processing the message.
546  
547 =head3 get_all_info
548  
549 Returns message info as returned from the parser, for more direct/complete
550 access.
551  
552 (It's probably a good idea to avoid using this, but it is useful and arguably
553 needed under certain circumstances.)
554  
555 =cut
556  
557 sub get_all_info {
558 126 ▶ my ($self) = @_;
Subroutine get_all_info: called CC=1 SCAR=0.0
Pod documented
559 126 return $message_raw_info{$$self};
560 }
561  
562 #
563 # To be implemented by the sub-classes.
564 #
565  
566 =head2 Utility subroutines
567  
568 =head3 clear_message_info
569  
570 Clears I<all> known information on the current message, but not on the log.
571  
572 Use to start searching for a new message.
573  
574 =cut
575  
576 sub clear_message_info {
577 3 ▶ my ($self) = @_;
Subroutine clear_message_info: called CC=3 SCAR=11.1
Pod documented
578  
579 3 foreach my $parameter ( @cleared_parameters ) {
580 66 ▶ $all_setters{$$self}{$parameter}->($self, undef) if defined($all_setters{$$self}{$parameter});
Branch: 1 branch
BranchTrueFalseTotal
if defined $all_setters{$$self}{$parameter} 66 0 66
581 }
582  
583 3 $self->_set_message_raw_info(undef);
584  
585 3 return;
586 }
587  
588 =head3 find_message
589  
590 Finds the first/next occurance of a message in the log. Can be passed any
591 of the above information in a hash format.
592  
593 Default is to search I<forward> in the log: If you have already done a search,
594 this will start searching where the previous search ended. To start over
595 at the beginning of the logfile, set C<from_start> as true in the parameter
596 hash.
597  
598 This method needs to be overridden by the subclass: by default it will throw
599 an C<Mail::Log::Exceptions::Unimplemented> error.
600  
601 =cut
602  
603 sub find_message {
604 1 ▶ Mail::Log::Exceptions::Unimplemented->throw("Method 'find_message' needs to be implemented by subclass.\n");
Subroutine find_message: called CC=1 SCAR=0.0
Pod documented
605 # return 0; # Return false: The message couldn't be found. This will never be called.
606 }
607  
608 =head3 find_message_info
609  
610 Finds as much information as possible about a specific occurance of a message
611 in the logfile. Acts much the same as find_message, other than the fact that
612 once it finds a message it will do any searching necarry to find all information
613 on that message connection.
614  
615 (Also needs to be implemented by subclasses.)
616  
617 =cut
618  
619 sub find_message_info {
620 1 ▶ Mail::Log::Exceptions::Unimplemented->throw("Method 'find_message_info' needs to be implemented by subclass.\n");
Subroutine find_message_info: called CC=1 SCAR=0.0
Pod documented
621 # return 0; # Return false: The message couldn't be found. This will never be called.
622 }
623  
624 #
625 # Private functions/methods.
626 #
627  
628 sub _set_message_raw_info {
629 137 ▶ my ($self, $new_hash) = @_;
Subroutine _set_message_raw_info: called CC=1 SCAR=0.0
630 137 $message_raw_info{$$self} = $new_hash;
631 137 return;
632 }
633  
634 sub _set_log_parser {
635 51 ▶ my ($self, $log_parser) = @_;
Subroutine _set_log_parser: called CC=1 SCAR=0.0
636 51 $log_info{$$self}->{log_parser} = $log_parser;
637 51 return;
638 }
639  
640 sub _get_log_parser {
641 38 ▶ my ($self) = @_;
Subroutine _get_log_parser: called CC=1 SCAR=0.0
642 38 return $log_info{$$self}->{log_parser};
643 }
644  
645 sub _get_parser_class {
646 25 ▶ my ($self) = @_;
Subroutine _get_parser_class: called CC=1 SCAR=0.0
647 25 return $log_info{$$self}->{parser_class};
648 }
649  
650 #
651 # Private to be implemented by the sub-classes...
652 # (If needed.)
653 #
654  
655 13 ▶sub _requested_public_accessors { return (); };
Subroutine _requested_public_accessors: called CC=1 SCAR=0.0
656 37 ▶sub _requested_public_set_only { return (); };
Subroutine _requested_public_set_only: called CC=1 SCAR=0.0
657 37 ▶sub _requested_public_get_only { return (); };
Subroutine _requested_public_get_only: called CC=1 SCAR=0.0
658 37 ▶sub _requested_array_accessors { return (); };
Subroutine _requested_array_accessors: called CC=1 SCAR=0.0
659 13 ▶sub _requested_cleared_parameters { return (); };
Subroutine _requested_cleared_parameters: called CC=1 SCAR=0.0
660 13 ▶sub _requested_special_accessors { return (); };
Subroutine _requested_special_accessors: called CC=1 SCAR=0.0
661 13 ▶sub _set_as_message_info { return (); };
Subroutine _set_as_message_info: called CC=1 SCAR=0.0
662  
663 sub _parse_args {
664 70 ▶ my ($self, $argref, $throw_error) = @_;
Subroutine _parse_args: called CC=9 SCAR=22.0
665
666 # It is possible for them to pass the message info here.
667 70 my %args;
668 70 foreach my $parameter ( @valid_parameters ) {
669 4118 ▶ $all_setters{$$self}{$parameter}->($self, $argref->{$parameter}) if exists $argref->{$parameter};
Branch: 1 branch
BranchTrueFalseTotal
if exists $argref->{$parameter} 438 3680 4118
670 }
671
672 # Not all parameters are checked...
673 70 foreach my $parameter ( @checked_parameters ) {
674 652 ▶ $args{$parameter} = $all_getters{$$self}{$parameter}->($self) if defined($all_setters{$$self}{$parameter});
Branch: 1 branch
BranchTrueFalseTotal
if defined $all_setters{$$self}{$parameter} 652 0 652
675 }
676 70 ▶ $args{from_start} = $argref->{from_start} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$argref->{'from_start'} ? : 1 69 70
677
678 # And log info.
679 70 ▶ $self->set_parser_class($argref->{parser_class}) if exists $argref->{parser_class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $argref->{"parser_class"} 4 66 70
680
681 # Speed things up a bit, and make it easier to read.
682
683 69 ▶ if ($throw_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($throw_error) 30 39 69
684 # If none are defined...
685 30 ▶ if ( (grep { defined($args{$_}) } keys %args) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep({defined $args{$_};} keys %args) == 1) 1 29 30
686 1 Mail::Log::Exceptions::Message->throw("Warning: Trying to search for a message with no message-specific data.\n");
687 }
688 }
689  
690 68 return \%args;
691 }
692  
693 =head1 BUGS
694  
695 None known at the moment...
696  
697 =head1 REQUIRES
698  
699 L<Scalar::Util>, L<Mail::Log::Exceptions>.
700  
701 Some subclass, and probably a L<Mail::Log::Parse> class to be useful.
702  
703 =head1 HISTORY
704  
705 1.00.03 Dec 5, 2208 - Licence clarification.
706  
707 1.00.02 Dec 2, 2008 - I really mean it this time.
708  
709 1.00.01 Dec 1, 2008 - Requirements fix, no code changes.
710  
711 1.00.00 Nov 28, 2008
712 - original version.
713  
714 =head1 AUTHOR
715  
716 Daniel T. Staal
717 CPAN ID: DSTAAL
718 dstaal@usa.net
719  
720 =head1 COPYRIGHT
721  
722 This program is free software; you can redistribute
723 it and/or modify it under the same terms as Perl itself.
724  
725 This copyright will expire in 30 years, or five years after the author's death,
726 whichever occurs last, at which time the code be released to the public domain.
727  
728 =cut
729  
730 #################### main pod documentation end ###################
731  
732 }
733 4 1;
734 # The preceding line will help the module return a true value
735  
« blib/lib/Mail/Log/Trace/Postfix.pm ↑ Summary Build »