blib/lib/IPC/ScoreBoard.pm

filter: Statementstmt 91.7% 67 / 73 Branchbran 50.0% 10 / 20 Conditioncond 22.2% 4 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 69.7% 97 / 139 CC 18 SCAR 15.7
CC
18
Cov
73%
named
7.2
open
6.9
anon
6.2
CRAP 4.8
↑ Summary ScoreBoard.xs »
1 package IPC::ScoreBoard;
2  
3 8 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use File::Map qw/:map/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 our $VERSION = '0.05';
10  
11 8 require XSLoader;
12 8 XSLoader::load('IPC::ScoreBoard', $VERSION);
13  
14 8 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 IVLEN=>length(pack "J", 0),
16 MAGIC=>'PCSB',
17 8 };
18  
19 # a slot is always a set of IVs.
20 # hence, $slotsize is given in units of IVLEN bytes.
21  
22 8 ▶sub anon {
Subroutine anon: called CC=5 SCAR=18.2
Pod documented
23 8 my ($class, $how_many, $slotsize, $score_extra);
24 8 ▶ if( @_>3 or $_[0]!~/^\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 3 or not $_[0] =~ /^\d/) { } 0 8 8
Condition33%1/3
@_ > 3 or not $_[0] =~ /^\d/
l!l&&r!l&&!r
008
MC/DC0%0/2
@_ > 3 or not $_[0] =~ /^\d/
@_ > 3 not $_[0] =~ /^\d/
Truth table33%1/3
A or not(B)
A= @_ > 3B= not $_[0] =~ /^\d/
ABresult
1X1
011
000
25 0 ($class, $how_many, $slotsize, $score_extra)=@_;
26 0 ▶ $class=ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
27 } else {
28 8 ($how_many, $slotsize, $score_extra)=@_;
29 8 $class=__PACKAGE__;
30 }
31  
32 8 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 8 ▶ $score_extra=0 unless defined $score_extra;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $score_extra 8 0 8
34  
35 8 my $slsz=$slotsize*IVLEN;
36 8 map_anonymous my $scoreboard, (4+$how_many*$slotsize+$score_extra)*IVLEN;
37 8 substr $scoreboard, 0, length(MAGIC), MAGIC;
38 8 substr $scoreboard, IVLEN, 3*IVLEN,
39 pack "J3", $how_many, $slotsize, $score_extra;
40  
41 8 return bless \$scoreboard, $class;
42 }
43  
44 8 ▶sub named {
Subroutine named: called CC=6 SCAR=19.7
Pod documented
45 8 my ($class, $filename, $how_many, $slotsize, $score_extra);
46 8 ▶ if( @_>4 or $_[1]!~/^\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 4 or not $_[1] =~ /^\d/) { } 8 0 8
Condition33%1/3
@_ > 4 or not $_[1] =~ /^\d/
l!l&&r!l&&!r
800
MC/DC0%0/2
@_ > 4 or not $_[1] =~ /^\d/
@_ > 4 not $_[1] =~ /^\d/
Truth table33%1/3
A or not(B)
A= @_ > 4B= not $_[1] =~ /^\d/
ABresult
1X1
011
000
47 8 ($class, $filename, $how_many, $slotsize, $score_extra)=@_;
48 8 ▶ $class=ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
080
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
49 } else {
50 0 ($filename, $how_many, $slotsize, $score_extra)=@_;
51 0 $class=__PACKAGE__;
52 }
53  
54 8 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 8 ▶ $score_extra=0 unless defined $score_extra;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $score_extra 0 8 8
56  
57 8 ▶ open my $fh, '+>', $filename or croak "Cannot open $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
CORE::open my $fh, "+>", $filename or croak("Cannot open ${filename}: $!") 8 0 8
58  
59 8 syswrite $fh, "\0" x((4+$how_many*$slotsize+$score_extra)*IVLEN);
60 8 map_handle my $scoreboard, $fh, '+<';
61 8 substr $scoreboard, 0, length(MAGIC), MAGIC;
62 8 substr $scoreboard, IVLEN, 3*IVLEN,
63 pack "J3", $how_many, $slotsize, $score_extra;
64  
65 8 return bless \$scoreboard, $class;
66 }
67  
68 2 ▶sub open {
Subroutine open: called CC=5 SCAR=19.3
Pod documented
69 2 my ($class, $filename);
70 2 ▶ if( @_>1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) { } 0 2 2
71 0 ($class, $filename)=@_;
72 0 ▶ $class=ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
73 } else {
74 2 ($filename)=@_;
75 2 $class=__PACKAGE__;
76 }
77  
78 2 ▶ open my $fh, '+<', $filename or croak "Cannot open $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
CORE::open my $fh, "+<", $filename or croak("Cannot open ${filename}: $!") 2 0 2
79 2 map_handle my $scoreboard, $fh, '+<';
80  
81 2 ▶ croak "Invalid magic number in $filename"
Branch: 1 branch
BranchTrueFalseTotal
unless substr($scoreboard, 0, 4) eq "PCSB" 0 2 2
82 unless substr($scoreboard, 0, length(MAGIC)) eq MAGIC;
83  
84 2 return bless(\$scoreboard, $class), unpack 'x'.IVLEN.'J3', $scoreboard;
85 }
86  
87 8 my $import_done;
88 8 ▶sub import {
Subroutine import: called CC=5 SCAR=16.7
89 8 ▶ return if @_>=2 and $_[1] eq ':noshortcuts';
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 2 and $_[1] eq ":noshortcuts" 0 8 8
Condition33%1/3
@_ >= 2 and $_[1] eq ":noshortcuts"
!ll&&!rl&&r
800
MC/DC0%0/2
@_ >= 2 and $_[1] eq ":noshortcuts"
@_ >= 2 $_[1] eq ":noshortcuts"
Truth table33%1/3
A and B
A= @_ >= 2B= $_[1] eq ":noshortcuts"
ABresult
0X0
100
111
90 # create shortcuts
91 8 ▶ return if $import_done;
Branch: 1 branch
BranchTrueFalseTotal
if $import_done 0 8 8
92 8 $import_done=1;
93 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
94 8 for my $n (qw/anon named open get set incr decr sum get_all sum_all
95 get_extra set_extra incr_extra decr_extra get_all_extra
96 nslots slotsize nextra have_atomics offset_of/) {
97 160 *{'SB::'.$n}=\&{$n};
98 }
99 }
100  
101 8 1;
102 __END__
↑ Summary ScoreBoard.xs »