Box/Locker.pm

filter: Statementstmt 94.9% 56 / 59 Branchbran 62.5% 15 / 24 Conditioncond 61.5% 8 / 13 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 84.2% 16 / 19 Podpod 83.3% 10 / 12 totaltotal 79.2% 107 / 135 CC 18 SCAR 13.6
CC
18
Cov
82%
new
9.8
init
4.0
DESTROY
3.1
CRAP 3.9
« Box/Identity.pm ↑ Summary Message/Head/Delayed.pm »
1 # This code is part of Perl distribution Mail-Box version 4.02.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2026 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Mail::Box::Locker;{
13 34 our $VERSION = '4.02';
14 }
15  
16 34 ▶use parent 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 34 ▶use Log::Report 'mail-box', import => [ qw/__x error panic/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 34 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 34 ▶use Devel::GlobalDestruction qw/in_global_destruction/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 #--------------------
27  
28 34 my %lockers = (
29 DOTLOCK => __PACKAGE__ .'::DotLock',
30 FCNTLLOCK => __PACKAGE__ .'::FcntlLock',
31 FLOCK => __PACKAGE__ .'::Flock',
32 MULTI => __PACKAGE__ .'::Multi',
33 MUTT => __PACKAGE__ .'::Mutt',
34 NFS => __PACKAGE__ .'::NFS',
35 NONE => __PACKAGE__,
36 POSIX => __PACKAGE__ .'::POSIX',
37 );
38  
39 sub new(@)
40 92 ▶{ my ($class, %args) = @_;
Subroutine new: called CC=8 SCAR=22.8
Pod documented
41 92 ▶ $class eq __PACKAGE__ or return $class->SUPER::new(%args);
Branch: 1 branch
BranchTrueFalseTotal
$class eq __PACKAGE__ or return $class->SUPER::new(%args) 92 0 92
42  
43 # Try to figure out which locking method we really want (bootstrap)
44  
45 my $method
46 = ! defined $args{method} ? 'DOTLOCK'
47 : ref $args{method} eq 'ARRAY' ? 'MULTI'
48 92 ▶ : uc $args{method};
Branch: 2 branches
BranchTrueFalseTotal
!defined($args{'method'}) ? : 0 92 92
ref $args{'method'} eq 'ARRAY' ? : 0 92 92
49  
50 92 ▶ my $create = $lockers{$method} || $args{$method}
Branch: 1 branch
BranchTrueFalseTotal
my $create = $lockers{$method} || $args{$method} or &error(&__x("no locking method {name} defined: use {avail}.", "name", $method, "avail", [keys %lockers])) 92 0 92
Condition33%1/3
$lockers{$method} || $args{$method}
l!l&&r!l&&!r
9200
MC/DC0%0/2
$lockers{$method} || $args{$method}
$lockers{$method} $args{$method}
Truth table33%1/3
A || B
A= $lockers{$method}B= $args{$method}
ABresult
1X1
011
000
51 or error __x"no locking method {name} defined: use {avail}.", name => $method, avail => [ keys %lockers ];
52  
53 # compile the locking module (if needed)
54 92 eval "require $create";
55 92 ▶ error __x"failed to use locking module {class}:\n{error}", class => $create, error => $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 91 92
56  
57 91 ▶ $args{use} = $args{method} if ref $args{method} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args{"method"} eq "ARRAY" 0 91 91
58 91 $create->SUPER::new(%args);
59 }
60  
61 sub init($)
62 91 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=14.0
Pod undocumented
63 91 $self->SUPER::init($args);
64  
65 91 ▶ $self->{MBL_expires} = $args->{expires} || 3600; # one hour
Condition50%1/2
$args->{'expires'} || 3600
l!l
091
MC/DC0%0/1
$args->{'expires'} || 3600
$args->{'expires'}
Truth table50%1/2
A
A= $args->{'expires'}
Aresult
11
00
66 91 ▶ $self->{MBL_timeout} = $args->{timeout} || 10; # ten secs
Condition100%2/2
$args->{'timeout'} || 10
l!l
784
MC/DC100%1/1
$args->{'timeout'} || 10
$args->{'timeout'}
Truth table100%2/2
A
A= $args->{'timeout'}
Aresult
11
00
67 91 ▶ $self->{MBL_filename} = $args->{file} || $args->{folder}->name;
Condition66%2/3
$args->{'file'} || $args->{'folder'}->name
l!l&&r!l&&!r
56350
MC/DC0%0/2
$args->{'file'} || $args->{'folder'}->name
$args->{'file'} $args->{'folder'}->name
Truth table66%2/3
A || B
A= $args->{'file'}B= $args->{'folder'}->name
ABresult
1X1
011
000
68 91 $self->{MBL_has_lock} = 0;
69  
70 91 $self->folder($args->{folder});
71 91 $self;
72 }
73  
74 #--------------------
75  
76 7 ▶sub timeout(;$) { my $self = shift; @_ ? $self->{MBL_timeout} = shift : $self->{MBL_timeout} }
Subroutine timeout: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 7 7
77 3 ▶sub expires(;$) { my $self = shift; @_ ? $self->{MBL_expires} = shift : $self->{MBL_expires} }
Subroutine expires: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 3 3
78  
79  
80 0 ▶sub name { $_[0]->notImplemented }
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
81  
82 0 ▶sub lockMethod($$$$) { panic "Method removed: use inheritance to implement own method." }
Subroutine lockMethod: not called CC=1 SCAR=6.9
Pod undocumented
83  
84  
85 sub folder(;$)
86 98 ▶{ my $self = shift;
Subroutine folder: called CC=3 SCAR=11.0
Pod documented
87 98 ▶ @_ && $_[0] or return $self->{MBL_folder};
Branch: 1 branch
BranchTrueFalseTotal
@_ and $_[0] or return $self->{"MBL_folder"} 91 7 98
Condition66%2/3
@_ and $_[0]
!ll&&!rl&&r
7091
MC/DC50%1/2
@_ and $_[0]
@_ $_[0]
Truth table66%2/3
A and B
A= @_B= $_[0]
ABresult
0X0
100
111
88  
89 91 $self->{MBL_folder} = shift;
90 91 weaken $self->{MBL_folder};
91 }
92  
93  
94 144 ▶sub filename(;$) { my $self = shift; @_ ? $self->{MBL_filename} = shift : $self->{MBL_filename} }
Subroutine filename: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 83 61 144
95  
96 #--------------------
97  
98 84 ▶sub lock($) { $_[0]->{MBL_has_lock} = 1 }
Subroutine lock: called CC=1 SCAR=0.0
Pod documented
99  
100  
101 0 ▶sub isLocked($) {0}
Subroutine isLocked: not called CC=1 SCAR=6.9
Pod documented
102  
103  
104 119 ▶sub hasLock() { $_[0]->{MBL_has_lock} }
Subroutine hasLock: called CC=1 SCAR=0.0
Pod documented
105  
106  
107 # implementation hazard: the unlock must be self-reliant, without
108 # help by the folder, because it may be called at global destruction
109 # after the folder has been removed.
110  
111 119 ▶sub unlock() { $_[0]->{MBL_has_lock} = 0 }
Subroutine unlock: called CC=1 SCAR=0.0
Pod documented
112  
113 #--------------------
114  
115 sub DESTROY()
116 90 ▶{ my $self = shift;
Subroutine DESTROY: called CC=3 SCAR=11.3
117 90 ▶ return $self if in_global_destruction;
Branch: 1 branch
BranchTrueFalseTotal
if &in_global_destruction() 0 90 90
118  
119 90 ▶ $self->unlock if $self->hasLock;
Branch: 1 branch
BranchTrueFalseTotal
if $self->hasLock 0 90 90
120 90 $self->SUPER::DESTROY;
121 90 $self;
122 }
123  
124 34 1;
« Box/Identity.pm ↑ Summary Message/Head/Delayed.pm »