Lambda/Flock.pm

filter: Statementstmt 100% 34 / 34 Branchbran 66.6% 8 / 12 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 8 / 8 Podpod 50.0% 1 / 2 totaltotal 88.1% 52 / 59 CC 7 SCAR 10.7
CC
7
Cov
90%
poll_flock
5.1
flock
3.1
BEGIN
1.0
CRAP 2.9
« Lambda/Mutex.pm ↑ Summary Lambda/HTTP/Authen/Negotiate.pm »
1 # $Id: Flock.pm,v 1.8 2009/04/21 14:42:46 dk Exp $
2 package IO::Lambda::Flock;
3 2 ▶use vars qw($DEBUG @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 @ISA = qw(Exporter);
5 2 @EXPORT_OK = qw(flock);
6 2 %EXPORT_TAGS = ( all => \@EXPORT_OK);
7 2 ▶$DEBUG = $IO::Lambda::DEBUG{flock} || 0;
Condition50%1/2
$IO::Lambda::DEBUG{'flock'} || 0
l!l
02
MC/DC0%0/1
$IO::Lambda::DEBUG{'flock'} || 0
$IO::Lambda::DEBUG{'flock'}
Truth table50%1/2
A
A= $IO::Lambda::DEBUG{'flock'}
Aresult
11
00
8
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Fcntl ':flock';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use IO::Lambda qw(:all :dev);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use IO::Lambda::Poll qw(poll_event);
Subroutine BEGIN: called CC=1 SCAR=0.0
14
15 sub poll_flock
16 {
17 7 ▶ my ( $expired, $fh, $shared) = @_;
Subroutine poll_flock: called CC=5 SCAR=16.2
Pod undocumented
18 7 ▶ if ( CORE::flock( $fh, LOCK_NB | ($shared ? LOCK_SH : LOCK_EX) )) {
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::flock $fh, 4 | ($shared ? 1 : 2)) 1 6 7
$shared ? : 0 7 7
19 1 ▶ warn "flock $fh obtained\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $IO::Lambda::Flock::DEBUG 0 1 1
20 1 return 1, 1;
21 }
22 6 ▶ return 1, 0 if $expired;
Branch: 1 branch
BranchTrueFalseTotal
if $expired 1 5 6
23 5 return 0;
24 }
25
26 sub flock(&)
27 {
28 return this-> override_handler('flock', \&flock, shift)
29 2 ▶ if this-> {override}->{flock};
Subroutine flock: called CC=3 SCAR=11.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if this()->{"override"}{"flock"} 0 2 2
30
31 2 my $cb = _subname flock => shift;
32 2 my ($fh, %opt) = context;
33 2 ▶ my $deadline = exists($opt{timeout}) ? $opt{timeout} : $opt{deadline};
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{'timeout'} ? : 2 0 2
34
35 poll_event(
36 $cb, \&flock, \&poll_flock,
37 $deadline, $opt{frequency},
38 $fh, $opt{shared}
39 2 );
40 }
41
42
43 # The same code can be written way more elegant:
44 #
45 # sub flock(&)
46 # {
47 # poller {
48 # my %opt = @_;
49 # CORE::flock(
50 # $opt{fh},
51 # LOCK_NB | ($opt{shared} ? LOCK_SH : LOCK_EX
52 # );
53 # }
54 # -> call(context)
55 # -> condition(shift, \&flock, 'flock')
56 # }
57 #
58 # but will require another calling style:
59 #
60 # context fh => $fh, deadline => 5;
61 # flock { ok }
62
63 2 1;
64
65 __DATA__
« Lambda/Mutex.pm ↑ Summary Lambda/HTTP/Authen/Negotiate.pm »