line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2019 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; |
10
|
34
|
|
|
34
|
|
267
|
use vars '$VERSION'; |
|
34
|
|
|
|
|
69
|
|
|
34
|
|
|
|
|
1558
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.008'; |
12
|
|
|
|
|
|
|
|
13
|
34
|
|
|
34
|
|
170
|
use base 'Mail::Reporter'; |
|
34
|
|
|
|
|
58
|
|
|
34
|
|
|
|
|
3131
|
|
14
|
|
|
|
|
|
|
|
15
|
34
|
|
|
34
|
|
191
|
use strict; |
|
34
|
|
|
|
|
61
|
|
|
34
|
|
|
|
|
675
|
|
16
|
34
|
|
|
34
|
|
158
|
use warnings; |
|
34
|
|
|
|
|
73
|
|
|
34
|
|
|
|
|
1438
|
|
17
|
|
|
|
|
|
|
|
18
|
34
|
|
|
34
|
|
187
|
use Carp; |
|
34
|
|
|
|
|
54
|
|
|
34
|
|
|
|
|
1917
|
|
19
|
34
|
|
|
34
|
|
194
|
use Scalar::Util 'weaken'; |
|
34
|
|
|
|
|
72
|
|
|
34
|
|
|
|
|
1492
|
|
20
|
34
|
|
|
34
|
|
13443
|
use Devel::GlobalDestruction 'in_global_destruction'; |
|
34
|
|
|
|
|
55974
|
|
|
34
|
|
|
|
|
158
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#------------------------------------------- |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %lockers = |
26
|
|
|
|
|
|
|
( DOTLOCK => __PACKAGE__ .'::DotLock' |
27
|
|
|
|
|
|
|
, FCNTLLOCK => __PACKAGE__ .'::FcntlLock' |
28
|
|
|
|
|
|
|
, FLOCK => __PACKAGE__ .'::Flock' |
29
|
|
|
|
|
|
|
, MULTI => __PACKAGE__ .'::Multi' |
30
|
|
|
|
|
|
|
, MUTT => __PACKAGE__ .'::Mutt' |
31
|
|
|
|
|
|
|
, NFS => __PACKAGE__ .'::NFS' |
32
|
|
|
|
|
|
|
, NONE => __PACKAGE__ |
33
|
|
|
|
|
|
|
, POSIX => __PACKAGE__ .'::POSIX' |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new(@) |
37
|
92
|
|
|
92
|
1
|
16874
|
{ my $class = shift; |
38
|
|
|
|
|
|
|
|
39
|
92
|
50
|
|
|
|
282
|
return $class->SUPER::new(@_) |
40
|
|
|
|
|
|
|
unless $class eq __PACKAGE__; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Try to figure out which locking method we really want (bootstrap) |
43
|
|
|
|
|
|
|
|
44
|
92
|
|
|
|
|
599
|
my %args = @_; |
45
|
|
|
|
|
|
|
my $method = !defined $args{method} ? 'DOTLOCK' |
46
|
|
|
|
|
|
|
: ref $args{method} eq 'ARRAY' ? 'MULTI' |
47
|
92
|
50
|
|
|
|
526
|
: uc $args{method}; |
|
|
50
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
92
|
|
33
|
|
|
334
|
my $create = $lockers{$method} || $args{$method}; |
50
|
|
|
|
|
|
|
|
51
|
92
|
|
|
|
|
191
|
local $" = ' or '; |
52
|
92
|
50
|
|
|
|
240
|
confess "No locking method $method defined: use @{[ keys %lockers ]}" |
|
0
|
|
|
|
|
0
|
|
53
|
|
|
|
|
|
|
unless $create; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# compile the locking module (if needed) |
56
|
92
|
|
|
|
|
5580
|
eval "require $create"; |
57
|
92
|
100
|
|
|
|
651
|
confess $@ if $@; |
58
|
|
|
|
|
|
|
|
59
|
91
|
50
|
|
|
|
329
|
$args{use} = $args{method} if ref $args{method} eq 'ARRAY'; |
60
|
|
|
|
|
|
|
|
61
|
91
|
|
|
|
|
783
|
$create->SUPER::new(%args); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub init($) |
65
|
91
|
|
|
91
|
0
|
868
|
{ my ($self, $args) = @_; |
66
|
|
|
|
|
|
|
|
67
|
91
|
|
|
|
|
317
|
$self->SUPER::init($args); |
68
|
|
|
|
|
|
|
|
69
|
91
|
|
50
|
|
|
1061
|
$self->{MBL_expires} = $args->{expires} || 3600; # one hour |
70
|
91
|
|
100
|
|
|
392
|
$self->{MBL_timeout} = $args->{timeout} || 10; # ten secs |
71
|
91
|
|
66
|
|
|
333
|
$self->{MBL_filename} = $args->{file} || $args->{folder}->name; |
72
|
91
|
|
|
|
|
190
|
$self->{MBL_has_lock} = 0; |
73
|
|
|
|
|
|
|
|
74
|
91
|
|
|
|
|
309
|
$self->folder($args->{folder}); |
75
|
91
|
|
|
|
|
551
|
$self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#------------------------------------------- |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub timeout(;$) |
82
|
7
|
|
|
7
|
1
|
14
|
{ my $self = shift; |
83
|
7
|
50
|
|
|
|
29
|
@_ ? $self->{MBL_timeout} = shift : $self->{MBL_timeout}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub expires(;$) |
87
|
3
|
|
|
3
|
1
|
7
|
{ my $self = shift; |
88
|
3
|
50
|
|
|
|
15
|
@_ ? $self->{MBL_expires} = shift : $self->{MBL_expires}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#------------------------------------------- |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
0
|
1
|
0
|
sub name {shift->notImplemented} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub lockMethod($$$$) |
97
|
0
|
|
|
0
|
0
|
0
|
{ confess "Method removed: use inheritance to implement own method." |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub folder(;$) |
102
|
99
|
|
|
99
|
1
|
223
|
{ my $self = shift; |
103
|
99
|
100
|
66
|
|
|
590
|
@_ && $_[0] or return $self->{MBL_folder}; |
104
|
|
|
|
|
|
|
|
105
|
91
|
|
|
|
|
244
|
$self->{MBL_folder} = shift; |
106
|
91
|
|
|
|
|
343
|
weaken $self->{MBL_folder}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub filename(;$) |
111
|
144
|
|
|
144
|
1
|
265
|
{ my $self = shift; |
112
|
144
|
100
|
|
|
|
390
|
$self->{MBL_filename} = shift if @_; |
113
|
144
|
|
|
|
|
367
|
$self->{MBL_filename}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
#------------------------------------------- |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
84
|
|
|
84
|
1
|
320
|
sub lock($) { shift->{MBL_has_lock} = 1 } |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
0
|
1
|
0
|
sub isLocked($) {0} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
119
|
|
|
119
|
1
|
357
|
sub hasLock() {shift->{MBL_has_lock}} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# implementation hazard: the unlock must be self-reliant, without |
129
|
|
|
|
|
|
|
# help by the folder, because it may be called at global destruction |
130
|
|
|
|
|
|
|
# after the folder has been removed. |
131
|
|
|
|
|
|
|
|
132
|
119
|
|
|
119
|
1
|
285
|
sub unlock() { shift->{MBL_has_lock} = 0 } |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
#------------------------------------------- |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub DESTROY() |
138
|
90
|
|
|
90
|
|
2993
|
{ my $self = shift; |
139
|
90
|
50
|
|
|
|
1803
|
return $self if in_global_destruction; |
140
|
|
|
|
|
|
|
|
141
|
90
|
50
|
|
|
|
574
|
$self->unlock if $self->hasLock; |
142
|
90
|
|
|
|
|
370
|
$self->SUPER::DESTROY; |
143
|
90
|
|
|
|
|
2276
|
$self; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |