blib/lib/Log/Accounting/Sendmail.pm

filter: Statementstmt 87.8% 94 / 107 Branchbran 53.8% 14 / 26 Conditioncond 44.4% 8 / 18 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 8 totaltotal 70.3% 126 / 179 CC 27 SCAR 29.0
CC
27
Cov
77%
addfile
30.0
calc
23.5
new
2.0
CRAP 18.3
↑ Summary
1 package Log::Accounting::Sendmail;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 require Exporter;
7 1 require AutoLoader;
8  
9 1 @ISA = qw(Exporter AutoLoader);
10 # Items to export into callers namespace by default. Note: do not export
11 # names by default without a very good reason. Use EXPORT_OK instead.
12 # Do not simply export all your public functions/methods/constants.
13 1 @EXPORT = qw(
14
15 );
16 1 $VERSION = '0.2';
17  
18 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
19 1 my $that = shift;
20 1 ▶ my $class = ref($that) || $that;
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
21 1 my $self = {};
22 1 bless $self, $class;
23 1 $self->reset();
24 1 $self
25 }
26  
27 2 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod undocumented
28 2 my $self = shift;
29 2 delete $self->{_data};
30 2 delete $self->{filter};
31 2 delete $self->{group};
32 2 $self
33 }
34  
35 2 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod undocumented
36 2 my $self = shift;
37 2 $self->{_data} .= $_[0];
38 2 $self
39 }
40  
41 0 ▶sub addfile {
Subroutine addfile: not called CC=5 SCAR=34.0
Pod undocumented
42 0 my ($self,$fh) = @_;
43 0 ▶ if (!ref($fh) && ref(\$fh) ne "GLOB") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $fh and ref \$fh ne "GLOB") 0 0 0
Condition0%0/3
not ref $fh and ref \$fh ne "GLOB"
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $fh and ref \$fh ne "GLOB"
not ref $fh ref \$fh ne "GLOB"
Truth table0%0/3
not(A) and B
A= not ref $fhB= ref \$fh ne "GLOB"
ABresult
0X0
100
111
44 0 require Symbol;
45 0 $fh = Symbol::qualify($fh, scalar caller);
46 }
47 # $self->{_data} .= do{local$/;<$fh>};
48 0 my $read = 0;
49 0 my $buffer = '';
50 0 ▶ $self->add($buffer) while $read = read $fh, $buffer, 8192;
Branch: 1 branch
BranchTrueFalseTotal
$read = read($fh, $buffer, 8192) and do { $self->add($buffer) } 0 0 0
51 0 ▶ die __PACKAGE__, " read failed: $!" unless defined $read;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $read 0 0 0
52 }
53  
54 1 ▶sub group {
Subroutine group: called CC=1 SCAR=0.0
Pod undocumented
55 1 my $self = shift;
56 1 push @{$self->{group}}, @_;
57 1 $self
58 }
59  
60 1 ▶sub filter {
Subroutine filter: called CC=1 SCAR=0.0
Pod undocumented
61 1 my $self = shift;
62 1 push @{$self->{filter}}, @_;
63 1 $self
64 }
65  
66 1 ▶sub map {
Subroutine map: called CC=2 SCAR=6.9
Pod undocumented
67 1 my $self = shift;
68 1 my %params = @_;
69 1 foreach my $k (keys %params) {
70 1 push @{$self->{map}->{$k}}, @{$params{$k}}
71 }
72 $self
73 1 }
74  
75 2 ▶sub calc {
Subroutine calc: called CC=21 SCAR=31.6
Pod undocumented
76 2 my $self = shift;
77 2 my (%MSGFROM, %MSGTO, %MSGREC, %MSGREC2, %MSGSIZE);
78 # parse
79 2 foreach(split /\n/, $self->{_data}) {
80 7 ▶ if (/sm-mta\[\d+\]\: (.+)\: from=(.+), size=(\d+), class=-?\d+, (?:pri=\d+, )?nrcpts=(\d+), msgid/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/sm-mta\[\d+\]\: (.+)\: from=(.+), size=(\d+), class=-?\d+, (?:pri=\d+, )?nrcpts=(\d+), msgid/) { } 2 5 7
elsif (/sm-mta\[\d+\]\: (.+)\: to=(.+?), /) { } 3 2 5
81 2 my $id=$1;
82 2 my $from=lc $2;
83 2 my $size=$3;
84 2 my $nr=$4;
85 2 $from=~s/[<>]//g;
86  
87 2 ▶ if ($from ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($from ne "") 2 0 2
88 #print STDERR "id=$id, from=$from, rcp=$nr, size=$size\n";
89 2 $MSGFROM{$id}=$from;
90 2 $MSGREC{$id}=$nr;
91 2 $MSGREC2{$id}=$nr;
92 2 $MSGSIZE{$id}=$size;
93 }
94 } elsif (/sm-mta\[\d+\]\: (.+)\: to=(.+?), /) {
95 3 my $id=$1;
96 3 my $to=lc $2;
97 3 $to =~ s/[<>]//g;
98  
99 3 my @tos = split(/,/,$to);
100 3 foreach my $to (@tos) {
101 3 ▶ if (defined($MSGFROM{$id})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $MSGFROM{$id}) 3 0 3
102 #print STDERR "id=$id, to=$to\n";
103 3 $MSGTO{$id." ".$MSGREC{$id}}=$to;
104 3 $MSGREC{$id}--;
105 }
106 }
107 }
108 }
109  
110 2 my %revmap;
111 2 foreach my $k (keys %{$self->{map}}) {
112 1 map {$revmap{$_}=$k} @{$self->{map}->{$k}}
113 }
114  
115 # calc
116 2 my %out;
117 2 foreach my $id (keys %MSGTO) {
118 3 $id =~ /(\w+) \d+/;
119 3 my $sid=$1;
120 #print STDERR "sid=$sid, id=$id\n";
121  
122 #print STDERR "MSGFROM{$sid}=$MSGFROM{$sid}, MSGTO{$id}=$MSGTO{$id}\n";
123 next if (ref($self->{filter}) eq 'ARRAY' &&
124 2 !grep($MSGFROM{$sid} =~ /^$_$/i, @{$self->{filter}}) &&
125 0 ▶ !grep($MSGTO{$id} =~ /^$_$/i, @{$self->{filter}}));
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"filter"} eq "ARRAY" and not grep(($MSGFROM{$sid} =~ /^$_$/i), @{$$self{"filter"};}) and not grep(($MSGTO{$id} =~ /^$_$/i), @{$$self{"filter"};}) 0 3 3
Condition50%3/6
ref $self->{"filter"} eq "ARRAY" and not grep(($MSGFROM{$sid} =~ /^$_$/i), @{$$self{"filter"};}) and not grep(($MSGTO{$id} =~ /^$_$/i), @{$$self{"filter"};})
!ll&&!rl&&r
300
ref $self->{"filter"} eq "ARRAY" and not grep(($MSGFROM{$sid} =~ /^$_$/i), @{$$self{"filter"};})
!ll&&!rl&&r
120
MC/DC0%0/3
ref $self->{"filter"} eq "ARRAY" and not grep(($MSGFROM{$sid} =~ /^$_$/i), @{$$self{"filter"};}) and not grep(($MSGTO{$id} =~ /^$_$/i), @{$$self{"filter"};})
ref $self->{"filter"} eq "ARRAY" not grep(($MSGFROM{$sid} =~ /^$_$/i), @{$$self{"filter"};}) not grep(($MSGTO{$id} =~ /^$_$/i), @{$$self{"filter"};})
Truth table50%2/4
A and not(B) and not(C)
A= ref $self->{"filter"} eq "ARRAY"B= not grep(($MSGFROM{$sid} =~ /^$_$/i), @{$$self{"filter"};})C= not grep(($MSGTO{$id} =~ /^$_$/i), @{$$self{"filter"};})
ABCresult
0XX0
10X0
1100
1111
126  
127 3 my $tokey = $MSGTO{$id};
128 3 ▶ if (grep($MSGTO{$id} =~ /^$_$/i, keys %revmap)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep(($MSGTO{$id} =~ /^$_$/i), keys %revmap)) 0 3 3
129 0 $tokey = $revmap{(grep($MSGTO{$id} =~ /^$_$/i, keys %revmap))[0]};
130 }
131 3 my $fromkey = $MSGFROM{$sid};
132 3 ▶ if (grep($MSGFROM{$sid} =~ /^$_$/i, keys %revmap)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep(($MSGFROM{$sid} =~ /^$_$/i), keys %revmap)) 2 1 3
133 2 $fromkey = $revmap{(grep($MSGFROM{$sid} =~ /^$_$/i, keys %revmap))[0]};
134 }
135  
136 3 ▶ if (ref($self->{group}) eq 'ARRAY' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'group'} eq 'ARRAY' and grep(($fromkey =~ /^$_$/i), @{$$self{'group'};}) or grep(($tokey =~ /^$_$/i), @{$$self{'group'};})) { } 2 1 3
Condition66%4/6
ref $self->{"group"} eq "ARRAY" and grep(($fromkey =~ /^$_$/i), @{$$self{"group"};}) or grep(($tokey =~ /^$_$/i), @{$$self{"group"};})
l!l&&r!l&&!r
201
ref $self->{"group"} eq "ARRAY" and grep(($fromkey =~ /^$_$/i), @{$$self{"group"};})
!ll&&!rl&&r
102
MC/DC33%1/3
ref $self->{"group"} eq "ARRAY" and grep(($fromkey =~ /^$_$/i), @{$$self{"group"};}) or grep(($tokey =~ /^$_$/i), @{$$self{"group"};})
ref $self->{"group"} eq "ARRAY" grep(($fromkey =~ /^$_$/i), @{$$self{"group"};}) grep(($tokey =~ /^$_$/i), @{$$self{"group"};})
Truth table40%2/5
A and B or C
A= ref $self->{"group"} eq "ARRAY"B= grep(($fromkey =~ /^$_$/i), @{$$self{"group"};})C= grep(($tokey =~ /^$_$/i), @{$$self{"group"};})
ABCresult
11X1
0X11
1011
0X00
1000
137 2 grep($fromkey =~ /^$_$/i, @{$self->{group}}) ||
138 1 grep($tokey =~ /^$_$/i, @{$self->{group}})) {
139 2 my @key;
140 2 ▶ if (@key=grep($tokey =~ /^$_$/i, @{$self->{group}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (@key = grep(($tokey =~ /^$_$/i), @{$$self{"group"};})) 0 2 2
141 0 foreach my $key (@key) {
142 0 $out{$key}->[0]++;
143 0 $out{$key}->[1] += $MSGSIZE{$sid};
144 }
145 }
146 2 ▶ if (@key=grep($fromkey =~ /^$_$/, @{$self->{group}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (@key = grep(($fromkey =~ /^$_$/), @{$$self{"group"};})) 2 0 2
147 2 foreach my $key (@key) {
148 2 $out{$key}->[0]++;
149 2 $out{$key}->[1] += $MSGSIZE{$sid};
150 }
151 }
152 } else {
153 1 push @{$out{$fromkey}}, [$MSGTO{$id}, $MSGSIZE{$sid}];
154 }
155 }
156  
157 2 %out;
158 }
159  
160  
161 1 1;
162 __END__
↑ Summary