| 1 | #!perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package File::Lock::Multi::Base::Iterative; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings (FATAL => 'all'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use File::Lock::Multi::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use base q(File::Lock::Multi::Base); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Time::HiRes qw(sleep); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | __PACKAGE__->mk_accessors(qw(iteration_delay)); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | return 1; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub _lock { | ||||||||||||||||||||||||||||
| 17 | 59 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_lock: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | return $self->_iterate(sub { | ||||||||||||||||||||||||||||
| 19 | 142 | ▶ | my($me, $now) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 142 | return $me->lock_non_block_for($now); | |||||||||||||||||||||||||||
| 21 | 59 | }); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub lockers { | ||||||||||||||||||||||||||||
| 25 | 23 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
lockers: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 23 | my @lockers = (); | |||||||||||||||||||||||||||
| 27 | $self->_iterate(sub { | ||||||||||||||||||||||||||||
| 28 | 87 | ▶ | my($me, $now) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 29 | 87 | ▶ | push(@lockers, $now) if($me->lock_held_for($now)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 87 | return; | |||||||||||||||||||||||||||
| 31 | 23 | }); | |||||||||||||||||||||||||||
| 32 | 23 | return @lockers; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub lock_held_for { | ||||||||||||||||||||||||||||
| 36 | 87 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
lock_held_for: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 87 | return !$self->obtain_lock_for(@_); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub _iterate { | ||||||||||||||||||||||||||||
| 41 | 82 | ▶ | my($self, $code) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_iterate: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||
| 42 | 82 | my $max = $self->max; | |||||||||||||||||||||||||||
| 43 | 82 | my $now = 1; | |||||||||||||||||||||||||||
| 44 | 82 | my $delay = $self->iteration_delay; | |||||||||||||||||||||||||||
| 45 | 82 | my $rv; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 82 | ▶ | while($now <= $max) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 229 | ▶ | if(my $rv = $code->($self, $now)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 18 | return $rv; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 211 | $now++; | |||||||||||||||||||||||||||
| 52 | 211 | ▶ | sleep($delay) if $delay && $now <= $max; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$delay and $now <= $max
MC/DC0%0/2
$delay and $now <= $max
$delay
$now <= $max
Truth table33%1/3
A and B
A= $delayB= $now <= $max
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 64 | return; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||