line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2023 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.03. |
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
|
|
256
|
use vars '$VERSION'; |
|
34
|
|
|
|
|
75
|
|
|
34
|
|
|
|
|
1825
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.010'; |
12
|
|
|
|
|
|
|
|
13
|
34
|
|
|
34
|
|
202
|
use base 'Mail::Reporter'; |
|
34
|
|
|
|
|
93
|
|
|
34
|
|
|
|
|
3693
|
|
14
|
|
|
|
|
|
|
|
15
|
34
|
|
|
34
|
|
245
|
use strict; |
|
34
|
|
|
|
|
119
|
|
|
34
|
|
|
|
|
994
|
|
16
|
34
|
|
|
34
|
|
197
|
use warnings; |
|
34
|
|
|
|
|
77
|
|
|
34
|
|
|
|
|
1166
|
|
17
|
|
|
|
|
|
|
|
18
|
34
|
|
|
34
|
|
210
|
use Carp; |
|
34
|
|
|
|
|
107
|
|
|
34
|
|
|
|
|
2140
|
|
19
|
34
|
|
|
34
|
|
230
|
use Scalar::Util 'weaken'; |
|
34
|
|
|
|
|
98
|
|
|
34
|
|
|
|
|
1854
|
|
20
|
34
|
|
|
34
|
|
16612
|
use Devel::GlobalDestruction 'in_global_destruction'; |
|
34
|
|
|
|
|
71896
|
|
|
34
|
|
|
|
|
220
|
|
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
|
3441
|
{ my $class = shift; |
38
|
|
|
|
|
|
|
|
39
|
92
|
50
|
|
|
|
325
|
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
|
|
|
|
|
749
|
my %args = @_; |
45
|
|
|
|
|
|
|
my $method = !defined $args{method} ? 'DOTLOCK' |
46
|
|
|
|
|
|
|
: ref $args{method} eq 'ARRAY' ? 'MULTI' |
47
|
92
|
50
|
|
|
|
747
|
: uc $args{method}; |
|
|
50
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
92
|
|
33
|
|
|
400
|
my $create = $lockers{$method} || $args{$method}; |
50
|
|
|
|
|
|
|
|
51
|
92
|
|
|
|
|
232
|
local $" = ' or '; |
52
|
92
|
50
|
|
|
|
248
|
confess "No locking method $method defined: use @{[ keys %lockers ]}" |
|
0
|
|
|
|
|
0
|
|
53
|
|
|
|
|
|
|
unless $create; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# compile the locking module (if needed) |
56
|
92
|
|
|
|
|
7052
|
eval "require $create"; |
57
|
92
|
100
|
|
|
|
864
|
confess $@ if $@; |
58
|
|
|
|
|
|
|
|
59
|
91
|
50
|
|
|
|
382
|
$args{use} = $args{method} if ref $args{method} eq 'ARRAY'; |
60
|
|
|
|
|
|
|
|
61
|
91
|
|
|
|
|
811
|
$create->SUPER::new(%args); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub init($) |
65
|
91
|
|
|
91
|
0
|
1132
|
{ my ($self, $args) = @_; |
66
|
|
|
|
|
|
|
|
67
|
91
|
|
|
|
|
437
|
$self->SUPER::init($args); |
68
|
|
|
|
|
|
|
|
69
|
91
|
|
50
|
|
|
1466
|
$self->{MBL_expires} = $args->{expires} || 3600; # one hour |
70
|
91
|
|
100
|
|
|
428
|
$self->{MBL_timeout} = $args->{timeout} || 10; # ten secs |
71
|
91
|
|
66
|
|
|
453
|
$self->{MBL_filename} = $args->{file} || $args->{folder}->name; |
72
|
91
|
|
|
|
|
223
|
$self->{MBL_has_lock} = 0; |
73
|
|
|
|
|
|
|
|
74
|
91
|
|
|
|
|
391
|
$self->folder($args->{folder}); |
75
|
91
|
|
|
|
|
745
|
$self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#------------------------------------------- |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub timeout(;$) |
82
|
7
|
|
|
7
|
1
|
20
|
{ my $self = shift; |
83
|
7
|
50
|
|
|
|
34
|
@_ ? $self->{MBL_timeout} = shift : $self->{MBL_timeout}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub expires(;$) |
87
|
3
|
|
|
3
|
1
|
6
|
{ my $self = shift; |
88
|
3
|
50
|
|
|
|
37
|
@_ ? $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
|
235
|
{ my $self = shift; |
103
|
99
|
100
|
66
|
|
|
758
|
@_ && $_[0] or return $self->{MBL_folder}; |
104
|
|
|
|
|
|
|
|
105
|
91
|
|
|
|
|
371
|
$self->{MBL_folder} = shift; |
106
|
91
|
|
|
|
|
444
|
weaken $self->{MBL_folder}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub filename(;$) |
111
|
144
|
|
|
144
|
1
|
346
|
{ my $self = shift; |
112
|
144
|
100
|
|
|
|
477
|
$self->{MBL_filename} = shift if @_; |
113
|
144
|
|
|
|
|
468
|
$self->{MBL_filename}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
#------------------------------------------- |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
84
|
|
|
84
|
1
|
414
|
sub lock($) { shift->{MBL_has_lock} = 1 } |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
0
|
1
|
0
|
sub isLocked($) {0} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
119
|
|
|
119
|
1
|
457
|
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
|
455
|
sub unlock() { shift->{MBL_has_lock} = 0 } |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
#------------------------------------------- |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub DESTROY() |
138
|
90
|
|
|
90
|
|
9620
|
{ my $self = shift; |
139
|
90
|
50
|
|
|
|
2248
|
return $self if in_global_destruction; |
140
|
|
|
|
|
|
|
|
141
|
90
|
50
|
|
|
|
924
|
$self->unlock if $self->hasLock; |
142
|
90
|
|
|
|
|
471
|
$self->SUPER::DESTROY; |
143
|
90
|
|
|
|
|
2669
|
$self; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |