| 1 | package IO::File::Lockable; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use base qw(IO::File); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | $VERSION = '0.34'; | |||||||||||||||||||||||||||
| 7 | ##### override open method , add argument lock mode. | ||||||||||||||||||||||||||||
| 8 | 2 | ▶ | sub class :method {ref($_[0]) || $_[0] || __PACKAGE__} | ||||||||||||||||||||||||||
|
Subroutine
class: called CC=3 SCAR=14.2
Pod
undocumented
Branch: 1 branch
Condition33%1/3
ref $_[0] or $_[0]
MC/DC0%0/2
ref $_[0] or $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A or B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | sub new :method {(shift()->class->SUPER::new())->init(@_)} | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | sub init :method {shift()->open(@_) if(@_ > 1);} | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | sub open :method { | ||||||||||||||||||||||||||
|
Subroutine
open: called CC=6 SCAR=20.3
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 2 | my $fh = shift; | |||||||||||||||||||||||||||
| 13 | 2 | ▶ | my $file = shift || return; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 14 | 2 | my $mode = shift; | |||||||||||||||||||||||||||
| 15 | 2 | ▶ | $file = IO::Handle::_open_mode_string($mode) . $file if($mode); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | $fh->SUPER::open($file) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | my $lock = (defined $_[0]) ? $_[0] | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 18 | : ($file =~ /^(\+?>|\+<)/) ? 'lock_ex' : 'lock_sh'; | ||||||||||||||||||||||||||||
| 19 | 2 | return $fh->$lock($_[1]); | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub lock_ex :method {carp('please override lock_ex method.');$_[0]} | ||||||||||||||||||||||||||
|
Subroutine
lock_ex: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub lock_sh :method {carp('please override lock_sh method.');$_[0]} | ||||||||||||||||||||||||||
|
Subroutine
lock_sh: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub lock_un :method {carp('please override lock_un method.');$_[0]} | ||||||||||||||||||||||||||
|
Subroutine
lock_un: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | ###################################################################### | ||||||||||||||||||||||||||||
| 25 | 8 | ▶ | sub set_timeout :method { | ||||||||||||||||||||||||||
|
Subroutine
set_timeout: called CC=3 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 27 | 8 | my $timeout = shift; | |||||||||||||||||||||||||||
| 28 | 8 | my $sub = shift; | |||||||||||||||||||||||||||
| 29 | my $result = $timeout | ||||||||||||||||||||||||||||
| 30 | ? eval { | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | local $SIG{ALRM} = sub {die('TIMEOUT')}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 0 | my $old = alarm($timeout); | |||||||||||||||||||||||||||
| 33 | 0 | my $r = $sub->(); | |||||||||||||||||||||||||||
| 34 | 0 | alarm($old); | |||||||||||||||||||||||||||
| 35 | 0 | return $r; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 8 | ▶ | : eval {return $sub->()}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if($@){carp($@);return;} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 8 | return $result; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | ###################################################################### | ||||||||||||||||||||||||||||
| 42 | __END__ | ||||||||||||||||||||||||||||