blib/lib/File/FcntlLock/Pure.pm

filter: Statementstmt 96.1% 25 / 26 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 33.3% 1 / 3 totaltotal 89.4% 34 / 38 CC 2 SCAR 2.3
CC
2
Cov
93%
lock
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« blib/lib/File/FcntlLock/Inline.pm ↑ Summary FcntlLock.xs »
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 for file locking with fcntl(2) in which the binary layout of
10 # the C flock struct has been determined via a C program on installation
11 # and appropriate Perl code been appended to the package.
12  
13 package File::FcntlLock::Pure;
14  
15 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use base qw( File::FcntlLock::Core );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 4 our $VERSION = File::FcntlLock::Core->VERSION;
22  
23 4 our @EXPORT = @File::FcntlLock::Core::EXPORT;
24  
25  
26 ###########################################################
27 # Function for doing the actual fcntl() call: assembles the binary
28 # structure that must be passed to fcntl() from the File::FcntlLock
29 # object we get passed, calls it and then modifies the File::FcntlLock
30 # with the data from the flock structure
31  
32 28 ▶sub lock {
Subroutine lock: called CC=2 SCAR=7.1
Pod documented
33 28 my ( $self, $fh, $action ) = @_;
34 28 my $buf = $self->pack_flock( );
35 28 my $ret = fcntl( $fh, $action, $buf );
36  
37 28 ▶ if ( $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) { } 28 0 28
38 28 $self->unpack_flock( $buf );
39 28 $self->{ errno } = $self->{ error } = undef;
40 } else {
41 0 $self->get_error( $self->{ errno } = $! + 0 );
42 }
43  
44 28 return $ret;
45 }
46  
47  
48 ###########################################################
49  
50 # Method created automatically while running 'perl Makefile.PL'
51 # (based on the the C 'struct flock' in <fcntl.h>) for packing
52 # the data from the 'flock_struct' into a binary blob to be
53 # passed to fcntl().
54  
55 28 ▶sub pack_flock {
Subroutine pack_flock: called CC=1 SCAR=0.0
Pod undocumented
56 28 my $self = shift;
57 return pack( 'ssx4qqlx4',
58 $self->{ l_type },
59 $self->{ l_whence },
60 $self->{ l_start },
61 $self->{ l_len },
62 28 $self->{ l_pid } );
63 }
64  
65  
66 ###########################################################
67  
68 # Method created automatically while running 'perl Makefile.PL'
69 # (based on the the C 'struct flock' in <fcntl.h>) for unpacking
70 # the binary blob received from a call of fcntl() into the
71 # 'flock_struct'.
72  
73 28 ▶sub unpack_flock {
Subroutine unpack_flock: called CC=1 SCAR=0.0
Pod undocumented
74 28 my ( $self, $data ) = @_;
75 ( $self->{ l_type },
76 $self->{ l_whence },
77 $self->{ l_start },
78 $self->{ l_len },
79 28 $self->{ l_pid } ) = unpack( 'ssx4qqlx4', $data );
80 }
81  
82  
83 4 1;
« blib/lib/File/FcntlLock/Inline.pm ↑ Summary FcntlLock.xs »