Mail/Abuse/Processor/Explain.pm

filter: Statementstmt 39.2% 22 / 56 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 75.0% 6 / 8 Podpod 100% 1 / 1 totaltotal 34.5% 29 / 84 CC 12 SCAR 34.7
CC
12
Cov
31%
process
56.9
_dump
30.0
BEGIN
1.0
CRAP 32.2
« Mail/Abuse/Filter/Time.pm ↑ Summary Mail/Abuse/Filter/IP.pm »
1 package Mail::Abuse::Processor::Explain;
2  
3 2 require 5.005_62;
4  
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use base 'Mail::Abuse::Processor';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # The code below should be in a single line
14  
15 2 our $VERSION = do { my @r = (q$Revision: 1.2 $ =~ /\d+/g); sprintf " %d."."%03d" x $#r, @r };
16  
17 =pod
18  
19 =head1 NAME
20  
21 Mail::Abuse::Processor::Explain - Explain a Mail::Abuse::Report
22  
23 =head1 SYNOPSIS
24  
25 use Mail::Abuse::Processor::Explain;
26  
27 use Mail::Abuse::Report;
28 my $p = new Mail::Abuse::Processor::Explain;
29 my $report = new Mail::Abuse::Report (processors => [ $p ]);
30  
31 # ... other pieces of code that configure the report ...
32  
33 =head1 DESCRIPTION
34  
35 This class outputs an abuse report and information about the incidents
36 that were extracted, to STDOUT. It is useful when using this framework
37 as part of a filter that preprocesses messages before handing them to
38 other systems.
39  
40 The following functions are implemented.
41  
42 =over
43  
44 =item C<process($report)>
45  
46 Takes a C<Mail::Abuse::Report> object as an argument and performs the
47 processing action required.
48  
49 =cut
50  
51 sub _dump($$$$$);
52  
53 sub _dump($$$$$)
54 0 ▶{
Subroutine _dump: not called CC=5 SCAR=34.0
55 0 my $fh = shift; # File handle to write output to
56 0 my $r = shift; # Handle to the incident
57 0 my $indent = shift; # Current indent level
58 0 my $parent = shift; # The name of what is being printed
59 0 my $r_data = shift; # The datum returned by the handler
60  
61 0 ▶ if (ref $r_data eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $r_data eq 'ARRAY') { } 0 0 0
elsif (ref $r_data eq 'HASH') { } 0 0 0
62 {
63 0 print $fh '| ' x ($indent - 1), "+-$parent\n";
64 0 for my $k (0 .. $#{$r_data})
65 {
66 0 _dump($fh, $r, $indent + 1, $parent . '.[' . $k .']',
67 $r_data->[$k]);
68 }
69 }
70 elsif (ref $r_data eq 'HASH')
71 {
72 0 print $fh '| ' x ($indent - 1), "+-$parent\n";
73 0 for my $k (sort keys %$r_data)
74 {
75 _dump($fh, $r, $indent + 1, $parent . '.{' . $k .'}',
76 0 $r_data->{$k});
77 }
78 }
79 else
80 {
81 0 print $fh '| ' x ($indent - 1), "+-$parent=$r_data\n";
82 }
83 }
84  
85 sub process
86 0 ▶{
Subroutine process: not called CC=8 SCAR=40.4
Pod documented
87 0 my $self = shift;
88 0 my $rep = shift;
89  
90 # If no work is required, simply leave quickly
91 0 ▶ return if @{$rep->incidents} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if @{$rep->incidents;} == 0 0 0 0
92  
93 # Where to send the explanations...
94 0 my $fh = \*STDOUT;
95  
96 # Print a nice header
97 0 my $PACKAGE = __PACKAGE__;
98 0 print $fh qq{
99 #================================================================
100 #Incident explanation by $PACKAGE
101 }
102 ;
103 0 print $fh q{#$Id: Explain.pm,v 1.2 2004/11/21 02:44:14 lem Exp $
104 #================================================================
105  
106 }
107 ;
108  
109 # Iterate through all the incidents
110 0 ▶ for my $r (sort { $a->ip <=> $b->ip
Condition0%0/6
$a->ip <=> $b->ip || $a->time <=> $b->time || $a->type cmp $b->type
l!l&&r!l&&!r
000
$a->ip <=> $b->ip or $a->time <=> $b->time
l!l&&r!l&&!r
000
MC/DC0%0/3
$a->ip <=> $b->ip || $a->time <=> $b->time || $a->type cmp $b->type
$a->ip <=> $b->ip $a->time <=> $b->time $a->type cmp $b->type
Truth table0%0/4
A or B || C
A= $a->ip <=> $b->ipB= $a->time <=> $b->timeC= $a->type cmp $b->type
ABCresult
1XX1
01X1
0011
0000
111 or $a->time <=> $b->time
112 or $a->type cmp $b->type }
113 0 @{$rep->incidents})
114 {
115 0 print $fh "# ", $r->ip, " ", strftime("%B %d, %H:%M:%S %Y (%z)",
116 localtime($r->time)), "\n";
117 0 for my $method (sort $r->items)
118 {
119 0 ▶ next if grep { $method eq $_ } qw/ip time data/;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$method eq $_;} "ip", "time", "data" 0 0 0
120 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
121 0 _dump($fh, $r, 1, $method, $r->$method);
122 }
123 }
124  
125 # Output a trailer and introduce the report text
126 0 print $fh q{
127  
128 #================================================================
129 #No more incidents to explain. The recovered report body follows.
130 #================================================================
131  
132 };
133  
134 0 ▶ print $fh $rep->normalized ? ${$rep->body} : ${$rep->text};
Branch: 1 branch
BranchTrueFalseTotal
$rep->normalized ? : 0 0 0
135 }
136  
137 __END__
« Mail/Abuse/Filter/Time.pm ↑ Summary Mail/Abuse/Filter/IP.pm »