Box/Locker/Mutt.pm

filter: Statementstmt 28.8% 17 / 59 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 45.4% 5 / 11 Podpod 66.6% 4 / 6 totaltotal 23.8% 26 / 109 CC 14 SCAR 38.9
CC
14
Cov
20%
lock
110.0
unlock
12.0
init
6.0
CRAP 48.7
« Box/Thread/Node.pm ↑ Summary Box/Message.pm »
1 # Copyrights 2001-2020 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution Mail-Box. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Box::Locker::Mutt;
10 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 $VERSION = '3.009';
12  
13 2 ▶use base 'Mail::Box::Locker';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use POSIX qw/sys_wait_h/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 sub init($)
22 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
23 0 $self->SUPER::init($args);
24  
25 0 ▶ $self->{MBLM_exe} = $args->{exe} || 'mutt_dotlock';
Condition0%0/2
$args->{'exe'} || 'mutt_dotlock'
l!l
00
MC/DC0%0/1
$args->{'exe'} || 'mutt_dotlock'
$args->{'exe'}
Truth table0%0/2
A
A= $args->{'exe'}
Aresult
11
00
26 0 $self;
27 }
28  
29 sub name() {'MUTT'}
30 0 ▶sub lockfile() { shift->filename . '.lock' }
Subroutine lockfile: not called CC=1 SCAR=6.9
Pod undocumented
31  
32  
33  
34 0 ▶sub exe() {shift->{MBLM_exe}}
Subroutine exe: not called CC=1 SCAR=6.9
Pod documented
35  
36  
37  
38 sub unlock()
39 0 ▶{ my $self = shift;
Subroutine unlock: not called CC=3 SCAR=24.8
Pod documented
40 0 ▶ $self->hasLock
Branch: 1 branch
BranchTrueFalseTotal
$self->hasLock or return $self 0 0 0
41 or return $self;
42  
43 0 ▶ unless(system($self->exe, '-u', $self->filename))
Branch: 1 branch
BranchTrueFalseTotal
unless (system $self->exe, "-u", $self->filename) 0 0 0
44 0 { my $folder = $self->folder;
45 0 $self->log(WARNING => "Couldn't remove mutt-unlock $folder: $!");
46 }
47  
48 0 $self->SUPER::unlock;
49 0 $self;
50 }
51  
52  
53  
54 sub lock()
55 0 ▶{ my $self = shift;
Subroutine lock: not called CC=10 SCAR=47.0
Pod documented
56 0 my $folder = $self->folder;
57 0 ▶ if($self->hasLock)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hasLock) 0 0 0
58 0 { $self->log(WARNING => "Folder $folder already mutt-locked");
59 0 return 1;
60 }
61  
62 0 my $filename = $self->filename;
63 0 my $lockfn = $self->lockfile;
64  
65 0 my $timeout = $self->timeout;
66 0 ▶ my $end = $timeout eq 'NOTIMEOUT' ? -1 : $timeout;
Branch: 1 branch
BranchTrueFalseTotal
$timeout eq 'NOTIMEOUT' ? : 0 0 0
67 0 my $expire = $self->expires / 86400; # in days for -A
68 0 my $exe = $self->exe;
69  
70 0 while(1)
71 {
72 0 ▶ if(system($exe, '-p', '-r', 1, $filename))
Branch: 1 branch
BranchTrueFalseTotal
if (system $exe, '-p', '-r', 1, $filename) { } 0 0 0
73 0 ▶ { unless(WIFEXITED($?) && WEXITSTATUS($?)==3)
Branch: 1 branch
BranchTrueFalseTotal
unless (WIFEXITED($?) and WEXITSTATUS($?) == 3) 0 0 0
Condition0%0/3
WIFEXITED($?) and WEXITSTATUS($?) == 3
!ll&&!rl&&r
000
MC/DC0%0/2
WIFEXITED($?) and WEXITSTATUS($?) == 3
WIFEXITED($?) WEXITSTATUS($?) == 3
Truth table0%0/3
A and B
A= WIFEXITED($?)B= WEXITSTATUS($?) == 3
ABresult
0X0
100
111
74 0 { $self->log(ERROR => "Will never get a mutt-lock: $!");
75 0 return 0;
76 }
77 }
78 else
79 0 { return $self->SUPER::lock;
80 }
81  
82 0 ▶ if(-e $lockfn && -A $lockfn > $expire)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $lockfn and -A $lockfn > $expire) 0 0 0
Condition0%0/3
-e $lockfn and -A $lockfn > $expire
!ll&&!rl&&r
000
MC/DC0%0/2
-e $lockfn and -A $lockfn > $expire
-e $lockfn -A $lockfn > $expire
Truth table0%0/3
A and B
A= -e $lockfnB= -A $lockfn > $expire
ABresult
0X0
100
111
83 {
84 0 ▶ if(system($exe, '-f', '-u', $filename))
Branch: 1 branch
BranchTrueFalseTotal
if (system $exe, '-f', '-u', $filename) { } 0 0 0
85 0 { $self->log(ERROR =>
86 "Failed to remove expired mutt-lock $lockfn: $!");
87 0 last;
88 }
89 else
90 0 { $self->log(WARNING => "Removed expired mutt-lock $lockfn");
91 0 redo;
92 }
93 }
94  
95 0 ▶ last unless --$end;
Branch: 1 branch
BranchTrueFalseTotal
unless --$end 0 0 0
96 0 sleep 1;
97 }
98  
99 0 return 0;
100 }
101  
102  
103 sub isLocked()
104 0 ▶{ my $self = shift;
Subroutine isLocked: not called CC=2 SCAR=17.9
Pod documented
105 0 system($self->exe, '-t', $self->filename);
106 0 ▶ WIFEXITED($?) && WEXITSTATUS($?)==3;
Branch: 1 branch
BranchTrueFalseTotal
WIFEXITED($?) and WEXITSTATUS($?) == 3 0 0 0
107 }
108  
109 2 1;
110  
« Box/Thread/Node.pm ↑ Summary Box/Message.pm »