DBus/Pack.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 96.4% 54 / 56 CC 5 SCAR 5.7
CC
5
Cov
100%
BEGIN
3.0
align
2.0
align_str
2.0
CRAP 1.8
« DBus/X/SurpriseShutdown.pm ↑ Summary DBus/Authn/Mechanism.pm »
1 package Protocol::DBus::Pack;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use constant CAN_64 => eval { !!pack 'q' };
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use constant NUMERIC => {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 y => 'C', # uint8
10 b => 'L', # boolean (uint32)
11 n => 's', # int16
12 q => 'S', # uint16
13 i => 'l', # int32
14 u => 'L', # uint32
15 x => 'q', # int64
16 t => 'Q', # uint64
17 d => 'd', # double float (?)
18 h => 'L', # unix fd, uint32
19 8 };
20  
21 8 ▶use constant STRING => {
Subroutine BEGIN: called CC=1 SCAR=0.0
22 s => 'L/a x',
23 o => 'L/a x',
24 g => 'C/a x',
25 8 };
26  
27 8 ▶use constant WIDTH => {
Subroutine BEGIN: called CC=3 SCAR=11.0
28  
29 # Accommodate 32-bit Perls:
30 80 ▶ (map { $_ => ($_ eq 'x' || $_ eq 't') ? 8 : length pack NUMERIC()->{$_} } keys %{ NUMERIC() }),
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'x' || $_ eq 't' ? : 16 64 80
Condition100%3/3
$_ eq "x" or $_ eq "t"
l!l&&r!l&&!r
8864
MC/DC100%2/2
$_ eq "x" or $_ eq "t"
$_ eq "x" $_ eq "t"
Truth table100%3/3
A or B
A= $_ eq "x"B= $_ eq "t"
ABresult
1X1
011
000
31 8 (map { $_ => length pack STRING()->{$_} } keys %{ STRING() }),
32 8 };
33  
34 8 ▶use constant ALIGNMENT => {
Subroutine BEGIN: called CC=1 SCAR=0.0
35 8 %{ WIDTH() },
36 8 map { $_ => length pack( substr( STRING()->{$_}, 0, 1 ) ) } keys %{ STRING() },
37 8 };
38  
39 # Increments the 1st arg in-place to align on a boundary of the 2nd arg.
40 # ex. align( 7, 8 ) will change the $_[0] to be 8.
41 1942 ▶sub align {
Subroutine align: called CC=2 SCAR=6.9
Pod undocumented
42 1942 ▶ if ($_[0] % $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] % $_[1]) 242 1700 1942
43 242 $_[0] += ($_[1] - ($_[0] % $_[1]));
44 }
45 }
46  
47 295 ▶sub align_str {
Subroutine align_str: called CC=2 SCAR=6.9
Pod undocumented
48 295 ▶ if (my $mod = length($_[0]) % $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mod = length($_[0]) % $_[1]) 44 251 295
49 44 $_[0] .= "\0" x ($_[1] - $mod);
50 }
51 }
52  
53 8 1;
« DBus/X/SurpriseShutdown.pm ↑ Summary DBus/Authn/Mechanism.pm »