| 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 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 34 | $VERSION = '3.009'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 34 | ▶ | use base 'Mail::Reporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 34 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 34 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 34 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 34 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 34 | ▶ | use Devel::GlobalDestruction 'in_global_destruction'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 34 | 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 | 8 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 8 | ▶ | return $class->SUPER::new(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | unless $class eq __PACKAGE__; | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # Try to figure out which locking method we really want (bootstrap) | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 8 | my %args = @_; | |||||||||||||||||||||||||||
| 45 | my $method = !defined $args{method} ? 'DOTLOCK' | ||||||||||||||||||||||||||||
| 46 | : ref $args{method} eq 'ARRAY' ? 'MULTI' | ||||||||||||||||||||||||||||
| 47 | 8 | ▶ | : uc $args{method}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 8 | ▶ | my $create = $lockers{$method} || $args{$method}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$lockers{$method} || $args{$method}
MC/DC0%0/2
$lockers{$method} || $args{$method}
$lockers{$method}
$args{$method}
Truth table33%1/3
A || B
A= $lockers{$method}B= $args{$method}
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 8 | local $" = ' or '; | |||||||||||||||||||||||||||
| 52 | 8 | ▶ | confess "No locking method $method defined: use @{[ keys %lockers ]}" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | unless $create; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # compile the locking module (if needed) | ||||||||||||||||||||||||||||
| 56 | 8 | eval "require $create"; | |||||||||||||||||||||||||||
| 57 | 8 | ▶ | confess $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 7 | ▶ | $args{use} = $args{method} if ref $args{method} eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 7 | $create->SUPER::new(%args); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub init($) | ||||||||||||||||||||||||||||
| 65 | 7 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 7 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 7 | ▶ | $self->{MBL_expires} = $args->{expires} || 3600; # one hour | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'expires'} || 3600
MC/DC0%0/1
$args->{'expires'} || 3600
$args->{'expires'}
Truth table50%1/2
A
A= $args->{'expires'}
| |||||||||||||||||||||||||||||
| 70 | 7 | ▶ | $self->{MBL_timeout} = $args->{timeout} || 10; # ten secs | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'timeout'} || 10
MC/DC0%0/1
$args->{'timeout'} || 10
$args->{'timeout'}
Truth table50%1/2
A
A= $args->{'timeout'}
| |||||||||||||||||||||||||||||
| 71 | 7 | ▶ | $self->{MBL_filename} = $args->{file} || $args->{folder}->name; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'file'} || $args->{'folder'}->name
MC/DC0%0/2
$args->{'file'} || $args->{'folder'}->name
$args->{'file'}
$args->{'folder'}->name
Truth table33%1/3
A || B
A= $args->{'file'}B= $args->{'folder'}->name
| |||||||||||||||||||||||||||||
| 72 | 7 | $self->{MBL_has_lock} = 0; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 7 | $self->folder($args->{folder}); | |||||||||||||||||||||||||||
| 75 | 7 | $self; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub timeout(;$) | ||||||||||||||||||||||||||||
| 82 | 4 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
timeout: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 4 | ▶ | @_ ? $self->{MBL_timeout} = shift : $self->{MBL_timeout}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub expires(;$) | ||||||||||||||||||||||||||||
| 87 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
expires: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 2 | ▶ | @_ ? $self->{MBL_expires} = shift : $self->{MBL_expires}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub name {shift->notImplemented} | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | sub lockMethod($$$$) | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | { confess "Method removed: use inheritance to implement own method." | ||||||||||||||||||||||||||
|
Subroutine
lockMethod: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | sub folder(;$) | ||||||||||||||||||||||||||||
| 102 | 13 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
folder: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 13 | ▶ | @_ && $_[0] or return $self->{MBL_folder}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and $_[0]
MC/DC50%1/2
@_ and $_[0]
@_
$_[0]
Truth table66%2/3
A and B
A= @_B= $_[0]
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 7 | $self->{MBL_folder} = shift; | |||||||||||||||||||||||||||
| 106 | 7 | weaken $self->{MBL_folder}; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub filename(;$) | ||||||||||||||||||||||||||||
| 111 | 7 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
filename: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 7 | ▶ | $self->{MBL_filename} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 7 | $self->{MBL_filename}; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 4 | ▶ | sub lock($) { shift->{MBL_has_lock} = 1 } | ||||||||||||||||||||||||||
|
Subroutine
lock: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub isLocked($) {0} | ||||||||||||||||||||||||||
|
Subroutine
isLocked: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 15 | ▶ | sub hasLock() {shift->{MBL_has_lock}} | ||||||||||||||||||||||||||
|
Subroutine
hasLock: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub unlock() { shift->{MBL_has_lock} = 0 } | ||||||||||||||||||||||||||
|
Subroutine
unlock: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | #------------------------------------------- | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | sub DESTROY() | ||||||||||||||||||||||||||||
| 138 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 139 | 3 | ▶ | return $self if in_global_destruction; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 3 | ▶ | $self->unlock if $self->hasLock; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 3 | $self->SUPER::DESTROY; | |||||||||||||||||||||||||||
| 143 | 3 | $self; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 34 | 1; | |||||||||||||||||||||||||||