| 1 | # -*- cperl -*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Copyright (C) 2002-2014 Jens Thoms Toerring <jt@toerring.de> | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # Base class for the three modules for file locking using fcntl(2) | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | package File::FcntlLock::Core; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use base qw( File::FcntlLock::Errors Exporter ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | our $VERSION = '0.22'; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # Items to export into callers namespace by default. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | our @EXPORT = qw( F_GETLK F_SETLK F_SETLKW | |||||||||||||||||||||||||||||||||||||||||
| 27 | F_RDLCK F_WRLCK F_UNLCK | ||||||||||||||||||||||||||||||||||||||||||
| 28 | SEEK_SET SEEK_CUR SEEK_END ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # Make our exports exportable by child classes | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | sub import | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 12 | File::FcntlLock::Core->export_to_level( 1, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # Method for creating the object | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 35 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 35 | my $inv = shift; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 35 | ▶ | my $pkg = ref( $inv ) || $inv; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $inv || $inv
MC/DC0%0/2
ref $inv || $inv
ref $inv
$inv
Truth table33%1/3
A || B
A= ref $invB= $inv
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 35 | my $self = { l_type => F_RDLCK, | |||||||||||||||||||||||||||||||||||||||||
| 49 | l_whence => SEEK_SET, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | l_start => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | l_len => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | l_pid => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | errno => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | error_message => undef }; | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 35 | ▶ | if ( @_ % 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | carp "Missing value in key-value initializer list " . | |||||||||||||||||||||||||||||||||||||||||
| 58 | "in call of new method"; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 52 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 52 | ▶ | unless ( defined &$key ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | carp "Flock structure has no '$key' member " . | |||||||||||||||||||||||||||||||||||||||||
| 67 | "in call of new method"; | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 52 | &$key( $self, shift ); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 4 | ▶ | use strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 35 | bless $self, $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # Method for setting or querying the 'l_type' property | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 144 | ▶ | sub l_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
l_type: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 144 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 144 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 72 | my $l_type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 72 | ▶ | unless ( $l_type == F_RDLCK | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$l_type == 0 or $l_type == 1 or $l_type == 2
$l_type == 0 or $l_type == 1
MC/DC0%0/3
$l_type == 0 or $l_type == 1 or $l_type == 2
$l_type == 0
$l_type == 1
$l_type == 2
Truth table75%3/4
A or B or C
A= $l_type == 0B= $l_type == 1C= $l_type == 2
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | or $l_type == F_WRLCK | ||||||||||||||||||||||||||||||||||||||||||
| 88 | or $l_type == F_UNLCK ) { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | carp "Invalid argument in call of l_type method"; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 72 | $self->{ l_type } = $l_type; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 144 | return $self->{ l_type }; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # Method for setting or querying the 'l_whence' property | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 42 | ▶ | sub l_whence { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
l_whence: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 42 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 30 | my $l_whence = shift; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 30 | ▶ | unless ( $l_whence == SEEK_SET | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$l_whence == 0 or $l_whence == 1 or $l_whence == 2
$l_whence == 0 or $l_whence == 1
MC/DC0%0/3
$l_whence == 0 or $l_whence == 1 or $l_whence == 2
$l_whence == 0
$l_whence == 1
$l_whence == 2
Truth table75%3/4
A or B or C
A= $l_whence == 0B= $l_whence == 1C= $l_whence == 2
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | or $l_whence == SEEK_CUR | ||||||||||||||||||||||||||||||||||||||||||
| 108 | or $l_whence == SEEK_END ) { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | carp "Invalid argument in call of l_whence method"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 30 | $self->{ l_whence } = $l_whence; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 42 | return $self->{ l_whence }; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # Method to set or query of the 'l_start' property | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 34 | ▶ | sub l_start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
l_start: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 34 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 34 | ▶ | $self->{ l_start } = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 34 | return $self->{ l_start }; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # Method to set or query the 'l_len' property | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 34 | ▶ | sub l_len { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
l_len: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 34 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 34 | ▶ | $self->{ l_len } = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 34 | return $self->{ l_len }; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 141 | # Method to query the 'l_pid' property | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 24 | ▶ | sub l_pid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
l_pid: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 24 | return shift->{ l_pid }; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | # Local variables: | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # tab-width: 4 | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # indent-tabs-mode: nil | ||||||||||||||||||||||||||||||||||||||||||
| 154 | # End: | ||||||||||||||||||||||||||||||||||||||||||