blib/lib/File/FcntlLock.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 40.0% 4 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 80.0% 48 / 60 CC 7 SCAR 17.4
CC
7
Cov
79%
lock
11.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.7
« blib/lib/File/FcntlLock/Errors.pm ↑ Summary blib/lib/File/FcntlLock/Core.pm »
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 package File::FcntlLock;
10  
11 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Errno;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use base qw( File::FcntlLock::Core DynaLoader );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 4 our $VERSION = '0.22';
21  
22  
23 4 bootstrap File::FcntlLock $VERSION;
24  
25 4 our @EXPORT = @File::FcntlLock::Core::EXPORT;
26  
27  
28 ###########################################################
29 #
30 # Make our exports exportable by child classes
31  
32 sub import
33 4 ▶{
Subroutine import: called CC=1 SCAR=0.0
34 4 File::FcntlLock->export_to_level( 1, @_ );
35 }
36  
37  
38 ###########################################################
39 #
40 # Function for locking or unlocking a file or determining which
41 # process holds a lock.
42  
43 39 ▶sub lock {
Subroutine lock: called CC=7 SCAR=24.0
Pod documented
44 39 my ( $self, $fh, $action ) = @_;
45 39 my ( $ret, $err );
46  
47 # Figure out the file descriptor - we might get a file handle, a
48 # typeglob or already a file descriptor) and set it to a value which
49 # will make fcntl(2) fail with EBADF if the argument is undefined or
50 # is a file handle that's invalid.
51  
52 39 ▶ my $fd = ( ref( $fh ) or $fh =~ /^\*/ ) ? fileno( $fh ) : $fh;
Branch: 1 branch
BranchTrueFalseTotal
ref $fh || $fh =~ /^\*/ ? : 39 0 39
Condition33%1/3
ref $fh or $fh =~ /^\*/
l!l&&r!l&&!r
3900
MC/DC0%0/2
ref $fh or $fh =~ /^\*/
ref $fh $fh =~ /^\*/
Truth table33%1/3
A or B
A= ref $fhB= $fh =~ /^\*/
ABresult
1X1
011
000
53 39 ▶ $fd = -1 unless defined $fd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fd 0 39 39
54  
55 # Set the action argument to something invalid if it's not defined
56 # which then fcntl(2) fails and errno gets set accordingly
57  
58 39 ▶ $action = -1 unless defined $action;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $action 0 39 39
59  
60 39 ▶ if ( $ret = C_fcntl_lock( $fd, $action, $self, $err ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ret = &C_fcntl_lock($fd, $action, $self, $err)) { } 39 0 39
elsif ($err) { } 0 0 0
61 39 $self->{ errno } = $self->{ error } = undef;
62 } elsif ( $err ) {
63 0 die "Internal error in File::FcntlLock module detected";
64 } else {
65 0 $self->get_error( $self->{ errno } = $! + 0 );
66 }
67  
68 39 return $ret;
69 }
70  
71  
72 4 1;
73  
74  
75 # Local variables:
76 # tab-width: 4
77 # indent-tabs-mode: nil
78 # End:
« blib/lib/File/FcntlLock/Errors.pm ↑ Summary blib/lib/File/FcntlLock/Core.pm »