blib/lib/Mail/QmailQueue.pm

filter: Statementstmt 23.7% 19 / 80 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 41.6% 5 / 12 Podpod 71.4% 5 / 7 totaltotal 23.7% 29 / 122 CC 15 SCAR 33.3
CC
15
Cov
19%
send
72.0
data
20.0
recipient
12.0
CRAP 27.9
↑ Summary
1 package Mail::QmailQueue;
2 # $Id: QmailQueue.pm,v 1.2 2002/04/05 13:07:58 ikechin Exp $
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use IO::Pipe;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 $VERSION = '0.03';
10  
11 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
12 0 my $class = shift;
13 0 ▶ my $bin = shift || "/var/qmail/bin/qmail-queue";
Condition0%0/2
shift() || '/var/qmail/bin/qmail-queue'
l!l
00
MC/DC0%0/1
shift() || '/var/qmail/bin/qmail-queue'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
14 0 my $self = {
15 bin => $bin
16 };
17 0 bless $self,$class;
18 }
19
20 0 ▶sub mail {
Subroutine mail: not called CC=2 SCAR=17.9
Pod documented
21 0 my $self = shift;
22 0 ▶ if ($_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 0 0 0
23 0 $self->{mail} = shift;
24 }
25 0 $self->{mail};
26 }
27  
28 1 *sender = \&mail;
29  
30 0 ▶sub recipient {
Subroutine recipient: not called CC=3 SCAR=24.8
Pod documented
31 0 my $self = shift;
32 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
33 0 ▶ if ($self->{recipient}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'recipient'}) { } 0 0 0
34 0 push(@{$self->{recipient}},@_);
35 } else {
36 0 $self->{recipient} = [ @_ ];
37 }
38 }
39 0 $self->{recipient};
40 }
41  
42 1 *to = \&recipient;
43  
44 0 ▶sub data {
Subroutine data: not called CC=4 SCAR=30.0
Pod documented
45 0 my $self = shift;
46 0 ▶ if ($_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) 0 0 0
47 0 my $data = $_[0];
48 0 ▶ if (ref($data) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq 'ARRAY') { } 0 0 0
49 0 for my $d(@{$data}) {
50 0 $d =~ s/\r\n/\n/g;
51 0 $self->{data} .= $d;
52 }
53 }
54 else {
55 0 $data =~ s/\r\n/\n/g;
56 0 $self->{data} .= $data;
57 }
58 }
59 0 $self->{data};
60 }
61  
62 0 ▶sub datasend {
Subroutine datasend: not called CC=1 SCAR=6.9
Pod undocumented
63 0 my $self = shift;
64 0 $self->data(shift);
65 0 $self->send;
66 }
67  
68 0 ▶sub send {
Subroutine send: not called CC=8 SCAR=42.8
Pod documented
69 0 my $self = shift;
70 0 my $data = IO::Pipe->new;
71 0 my $addr = IO::Pipe->new;
72
73 0 foreach my $key (qw(recipient mail data)) {
74 0 ▶ if (!$self->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$key}) 0 0 0
75 0 carp "please specify $key";
76 }
77 }
78 0 ▶ $self->{data} .= "\n" unless $self->{data} =~ m/\n$/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"} =~ /\n$/s 0 0 0
79 0 ▶ if (my $pid = fork) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $pid = fork) { } 0 0 0
elsif (defined $pid) { } 0 0 0
80 0 $data->writer;
81 0 $addr->writer;
82
83 0 $data->print($self->data);
84 0 $data->close;
85
86 0 $addr->print("F" . $self->mail . "\0");
87 0 foreach my $rcpt (@{$self->recipient}) {
88 0 $addr->print("T" . $rcpt . "\0");
89 }
90 0 $addr->print("\0");
91 0 $addr->close;
92
93 0 delete $self->{mail};
94 0 delete $self->{recipient};
95 0 delete $self->{data};
96
97 0 wait;
98 } elsif (defined $pid) {
99 0 my $fd0 = IO::Handle->new->fdopen(0,"w");
100 0 my $fd1 = IO::Handle->new->fdopen(1,"w");
101 0 $data->reader();
102 0 $addr->reader();
103 0 $fd0->fdopen(fileno($data),"r");
104 0 $fd1->fdopen(fileno($addr),"r");
105 0 ▶ exec($self->{bin}) || carp $!;
Branch: 1 branch
BranchTrueFalseTotal
exec $self->{"bin"} or carp($!) 0 0 0
106 0 exit;
107 } else {
108 0 carp "Cannot fork!!";
109 }
110 }
111  
112  
113 0 ▶sub quit {
Subroutine quit: not called CC=1 SCAR=6.9
Pod undocumented
114 # do nothing
115 0 1;
116 }
117  
118 1 1;
119 __END__
↑ Summary