POPRelay/Daemon.pm

filter: Statementstmt 36.7% 18 / 49 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 45.4% 5 / 11 Podpod 0.0% 0 / 1 totaltotal 28.4% 23 / 81 CC 11 SCAR 32.7
CC
11
Cov
26%
__mainLoop
56.0
init
30.0
__setupSignals
2.0
CRAP 26.4
« POPRelay.pm ↑ Summary Object.pm »
1 package Mail::POPRelay::Daemon;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mail::POPRelay;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Tail;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use vars qw[@ISA $VERSION ];
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use POSIX qw[setsid ];
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 @ISA = qw[Mail::POPRelay ];
10 1 $VERSION = '0.1.1';
11  
12  
13 # trap signals
14 # ---------
15 0 ▶sub __setupSignals {
Subroutine __setupSignals: not called CC=1 SCAR=6.9
16 0 my $self = shift;
17  
18 0 ▶ $SIG{'TERM'} = sub { $self->wipeRelayDirectory(); $self->generateRelayFile(); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 0 ▶ $SIG{'KILL'} = sub { $self->wipeRelayDirectory(); $self->generateRelayFile(); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 0 ▶ $SIG{'HUP'} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 $self->initWithConfigFile($self->{'configFile'});
22 0 $self->cleanRelayDirectory();
23 0 $self->generateRelayFile();
24 0 };
25 }
26  
27  
28 # daemonize
29 # ---------
30 0 ▶sub init {
Subroutine init: not called CC=5 SCAR=34.0
Pod undocumented
31 0 my $self = Mail::POPRelay::initWithConfigFile(@_);
32  
33 0 ▶ defined(my $pid = fork()) or die "Unable to fork: $!";
Branch: 1 branch
BranchTrueFalseTotal
defined(my $pid = fork) or die "Unable to fork: $!" 0 0 0
34 0 ▶ if ($pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) { } 0 0 0
35 # parent
36 0 return $pid;
37 } else {
38 # sibling
39 #chdir('/') or die "Can't chdir to /: $!";
40 0 ▶ setsid() or die "Can't start new session: $!";
Branch: 1 branch
BranchTrueFalseTotal
setsid() or die "Can't start new session: $!" 0 0 0
41 0 ▶ open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&STDOUT" or die "Can't dup stdout: $!" 0 0 0
42  
43 0 $self->__setupSignals();
44 0 $self->__mainLoop();
45  
46 0 return $self;
47 }
48 }
49  
50  
51 # ---------
52 0 ▶sub __mainLoop {
Subroutine __mainLoop: not called CC=7 SCAR=40.3
53 0 my $self = shift;
54  
55 my $fileTail = File::Tail->new (
56 0 ▶ name => $self->{'mailLogFile'},
Branch: 1 branch
BranchTrueFalseTotal
my $fileTail = "File::Tail"->new("name", $self->{"mailLogFile"}, "interval", 2, "maxinterval", 3, "adjustafter", 3) or die qq[Unable to tail $self->{"mailLogFile"}: $!] 0 0 0
57 interval => 2,
58 maxinterval => 3,
59 adjustafter => 3,
60 ) or die "Unable to tail $self->{'mailLogFile'}: $!";
61  
62 0 my($line, $flag);
63 0 ▶ while (defined($line = $fileTail->read())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $fileTail->read)) 0 0 0
64 0 ▶ if ($line =~ m|$self->{'mailLogRegExp'}|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$self->{"mailLogRegExp"}/) 0 0 0
65 # save processing cycles and exit early if possible
66 0 $flag = 0;
67 0 ▶ $flag = 1 if $self->addRelayAddress($1, $2);
Branch: 1 branch
BranchTrueFalseTotal
if $self->addRelayAddress($1, $2) 0 0 0
68 0 ▶ $flag = 1 if $self->cleanRelayDirectory();
Branch: 1 branch
BranchTrueFalseTotal
if $self->cleanRelayDirectory 0 0 0
69 0 ▶ $self->generateRelayFile() if $flag;
Branch: 1 branch
BranchTrueFalseTotal
if $flag 0 0 0
70  
71 }
72 }
73 0 $self->wipeRelayDirectory();
74 0 $self->generateRelayFile();
75 }
76  
77  
78 1 1337;
79  
80 __END__
« POPRelay.pm ↑ Summary Object.pm »