line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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; |
10
|
34
|
|
|
34
|
|
265
|
use vars '$VERSION'; |
|
34
|
|
|
|
|
76
|
|
|
34
|
|
|
|
|
1844
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.009'; |
12
|
|
|
|
|
|
|
|
13
|
34
|
|
|
34
|
|
204
|
use base 'Mail::Reporter'; |
|
34
|
|
|
|
|
67
|
|
|
34
|
|
|
|
|
3731
|
|
14
|
|
|
|
|
|
|
|
15
|
34
|
|
|
34
|
|
251
|
use strict; |
|
34
|
|
|
|
|
88
|
|
|
34
|
|
|
|
|
789
|
|
16
|
34
|
|
|
34
|
|
197
|
use warnings; |
|
34
|
|
|
|
|
82
|
|
|
34
|
|
|
|
|
1139
|
|
17
|
|
|
|
|
|
|
|
18
|
34
|
|
|
34
|
|
232
|
use Carp; |
|
34
|
|
|
|
|
65
|
|
|
34
|
|
|
|
|
2296
|
|
19
|
34
|
|
|
34
|
|
239
|
use Scalar::Util 'weaken'; |
|
34
|
|
|
|
|
78
|
|
|
34
|
|
|
|
|
1735
|
|
20
|
34
|
|
|
34
|
|
16567
|
use Devel::GlobalDestruction 'in_global_destruction'; |
|
34
|
|
|
|
|
70586
|
|
|
34
|
|
|
|
|
202
|
|
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
|
2841
|
{ my $class = shift; |
38
|
|
|
|
|
|
|
|
39
|
92
|
50
|
|
|
|
340
|
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
|
|
|
|
|
787
|
my %args = @_; |
45
|
|
|
|
|
|
|
my $method = !defined $args{method} ? 'DOTLOCK' |
46
|
|
|
|
|
|
|
: ref $args{method} eq 'ARRAY' ? 'MULTI' |
47
|
92
|
50
|
|
|
|
608
|
: uc $args{method}; |
|
|
50
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
92
|
|
33
|
|
|
452
|
my $create = $lockers{$method} || $args{$method}; |
50
|
|
|
|
|
|
|
|
51
|
92
|
|
|
|
|
249
|
local $" = ' or '; |
52
|
92
|
50
|
|
|
|
284
|
confess "No locking method $method defined: use @{[ keys %lockers ]}" |
|
0
|
|
|
|
|
0
|
|
53
|
|
|
|
|
|
|
unless $create; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# compile the locking module (if needed) |
56
|
92
|
|
|
|
|
7349
|
eval "require $create"; |
57
|
92
|
100
|
|
|
|
719
|
confess $@ if $@; |
58
|
|
|
|
|
|
|
|
59
|
91
|
50
|
|
|
|
373
|
$args{use} = $args{method} if ref $args{method} eq 'ARRAY'; |
60
|
|
|
|
|
|
|
|
61
|
91
|
|
|
|
|
735
|
$create->SUPER::new(%args); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub init($) |
65
|
91
|
|
|
91
|
0
|
1074
|
{ my ($self, $args) = @_; |
66
|
|
|
|
|
|
|
|
67
|
91
|
|
|
|
|
400
|
$self->SUPER::init($args); |
68
|
|
|
|
|
|
|
|
69
|
91
|
|
50
|
|
|
1330
|
$self->{MBL_expires} = $args->{expires} || 3600; # one hour |
70
|
91
|
|
100
|
|
|
449
|
$self->{MBL_timeout} = $args->{timeout} || 10; # ten secs |
71
|
91
|
|
66
|
|
|
433
|
$self->{MBL_filename} = $args->{file} || $args->{folder}->name; |
72
|
91
|
|
|
|
|
221
|
$self->{MBL_has_lock} = 0; |
73
|
|
|
|
|
|
|
|
74
|
91
|
|
|
|
|
395
|
$self->folder($args->{folder}); |
75
|
91
|
|
|
|
|
676
|
$self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#------------------------------------------- |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub timeout(;$) |
82
|
7
|
|
|
7
|
1
|
18
|
{ my $self = shift; |
83
|
7
|
50
|
|
|
|
33
|
@_ ? $self->{MBL_timeout} = shift : $self->{MBL_timeout}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub expires(;$) |
87
|
3
|
|
|
3
|
1
|
6
|
{ my $self = shift; |
88
|
3
|
50
|
|
|
|
17
|
@_ ? $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
|
242
|
{ my $self = shift; |
103
|
99
|
100
|
66
|
|
|
703
|
@_ && $_[0] or return $self->{MBL_folder}; |
104
|
|
|
|
|
|
|
|
105
|
91
|
|
|
|
|
304
|
$self->{MBL_folder} = shift; |
106
|
91
|
|
|
|
|
442
|
weaken $self->{MBL_folder}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub filename(;$) |
111
|
144
|
|
|
144
|
1
|
299
|
{ my $self = shift; |
112
|
144
|
100
|
|
|
|
505
|
$self->{MBL_filename} = shift if @_; |
113
|
144
|
|
|
|
|
444
|
$self->{MBL_filename}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
#------------------------------------------- |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
84
|
|
|
84
|
1
|
418
|
sub lock($) { shift->{MBL_has_lock} = 1 } |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
0
|
1
|
0
|
sub isLocked($) {0} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
119
|
|
|
119
|
1
|
473
|
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
|
482
|
sub unlock() { shift->{MBL_has_lock} = 0 } |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
#------------------------------------------- |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub DESTROY() |
138
|
90
|
|
|
90
|
|
16528
|
{ my $self = shift; |
139
|
90
|
50
|
|
|
|
2397
|
return $self if in_global_destruction; |
140
|
|
|
|
|
|
|
|
141
|
90
|
50
|
|
|
|
803
|
$self->unlock if $self->hasLock; |
142
|
90
|
|
|
|
|
485
|
$self->SUPER::DESTROY; |
143
|
90
|
|
|
|
|
2381
|
$self; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |