Lockable.pm

filter: Statementstmt 68.1% 30 / 44 Branchbran 43.7% 7 / 16 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 69.2% 9 / 13 Podpod 62.5% 5 / 8 totaltotal 59.5% 53 / 89 CC 11 SCAR 13.4
CC
11
Cov
60%
open
7.6
set_timeout
4.3
class
4.1
CRAP 3.8
↑ Summary fcntl.pm »
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
BranchTrueFalseTotal
ref $_[0] or $_[0] or __PACKAGE__ 2 0 2
Condition33%1/3
ref $_[0] or $_[0]
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $_[0] or $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A or B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if @_ > 1 2 0 2
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)
l!l
20
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
14 2 my $mode = shift;
15 2 ▶ $file = IO::Handle::_open_mode_string($mode) . $file if($mode);
Branch: 1 branch
BranchTrueFalseTotal
if $mode 2 0 2
16 2 ▶ $fh->SUPER::open($file) or return;
Branch: 1 branch
BranchTrueFalseTotal
$fh->SUPER::open($file) or return 2 0 2
17 2 ▶ my $lock = (defined $_[0]) ? $_[0]
Branch: 2 branches
BranchTrueFalseTotal
defined $_[0] ? : 2 0 2
$file =~ /^(\+?>|\+<)/ ? : 0 0 0
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
BranchTrueFalseTotal
$timeout ? : 0 8 8
38 0 ▶ if($@){carp($@);return;}
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 8 8
39 8 return $result;
40 }
41 ######################################################################
42 __END__
↑ Summary fcntl.pm »