Export/Extent.pm

filter: Statementstmt 98.5% 66 / 67 Branchbran 78.5% 33 / 42 Conditioncond 63.8% 23 / 36 MC/DCmcdc 17.6% 3 / 17 Subroutinesub 100% 17 / 17 Podpod 100% 9 / 9 totaltotal 80.3% 151 / 188 CC 37 SCAR 16.5
CC
37
Cov
84%
new
8.0
size
7.5
end_lba
6.6
CRAP 5.2
« Export/VFAT/Directory.pm ↑ Summary Export/LogAny.pm »
1 package Sys::Export::Extent;
2  
3 3 our $VERSION = '0.006'; # VERSION
4 # ABSTRACT: Represents a range of bytes and data that needs written there
5  
6 3 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use experimental qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Sys::Export qw( round_up_to_multiple :isa );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 44 ▶sub new($class, %attrs) {
Subroutine new: called CC=8 SCAR=20.8
Pod documented
15 44 my $self= bless { name => delete $attrs{name} }, $class;
16 # Some fields need to be initialized in a specific order:
17 44 ▶ $self->block_size(delete $attrs{block_size}) if defined $attrs{block_size};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attrs{"block_size"} 25 19 44
18 44 ▶ $self->size(delete $attrs{size}) if defined $attrs{size};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attrs{"size"} 1 43 44
19 44 ▶ $self->data(delete $attrs{data}) if defined $attrs{data};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attrs{"data"} 1 43 44
20 44 ▶ $self->device_offset(delete $attrs{device_offset}) if defined $attrs{device_offset};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attrs{"device_offset"} 1 43 44
21 44 ▶ $self->start_lba(delete $attrs{start_lba}) if defined $attrs{start_lba};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attrs{"start_lba"} 1 43 44
22 # The rest have no interdependencies
23 44 for (keys %attrs) {
24 24 ▶ my $m= $self->can($_) or croak "Unknown attribute '$_'";
Branch: 1 branch
BranchTrueFalseTotal
my $m = $self->can($_) or croak("Unknown attribute '${_}'") 24 0 24
25 24 $m->($self, $attrs{$_});
26 }
27 44 $self;
28 }
29  
30  
31 5 ▶sub coerce($class, $x) {
Subroutine coerce: called CC=4 SCAR=17.9
Pod documented
32 5 ▶ return $x if blessed($x) && $x->isa($class);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($x) and $x->isa($class) 0 5 5
Condition33%1/3
builtin::blessed($x) and $x->isa($class)
!ll&&!rl&&r
500
MC/DC0%0/2
builtin::blessed($x) and $x->isa($class)
builtin::blessed($x) $x->isa($class)
Truth table33%1/3
A and B
A= builtin::blessed($x)B= $x->isa($class)
ABresult
0X0
100
111
33 5 ▶ return $class->new(%$x) if isa_hash $x;
Branch: 1 branch
BranchTrueFalseTotal
if &isa_hash($x) 5 0 5
34 0 croak "Don't know how to coerce $x into $class";
35 }
36  
37  
38 109 ▶sub name($self) { $self->{name} // 'extent' }
Subroutine name: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
$self->{"name"} // "extent"
l!l
1090
MC/DC0%0/1
$self->{"name"} // "extent"
$self->{"name"}
Truth table50%1/2
A
A= $self->{"name"}
Aresult
11
00
39  
40 274 ▶sub block_size($self, @v) {
Subroutine block_size: called CC=4 SCAR=13.9
Pod documented
41 274 ▶ if (@v) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v) 40 234 274
42 40 ▶ croak "block_size $v[0] not a power of 2" unless isa_pow2 $v[0];
Branch: 1 branch
BranchTrueFalseTotal
unless &isa_pow2($v[0]) 0 40 40
43 40 $self->{block_size}= $v[0];
44 }
45 274 ▶ $self->{block_size} // 512;
Condition100%2/2
$self->{"block_size"} // 512
l!l
24430
MC/DC100%1/1
$self->{"block_size"} // 512
$self->{"block_size"}
Truth table100%2/2
A
A= $self->{"block_size"}
Aresult
11
00
46 }
47  
48  
49 328 ▶sub size($self, @v) {
Subroutine size: called CC=7 SCAR=20.2
Pod documented
50 328 ▶ if (@v) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v) 67 261 328
51 croak "Attempt to change ector length of ".$self->name." after choosing LBA"
52 if ($self->{size} // 0) > 0 && ($self->device_offset // -1) >= 0
53 67 ▶ && round_up_to_multiple($v[0], $self->block_size) != round_up_to_multiple($self->{size}, $self->block_size);
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"size"} // 0) > 0 and ($self->device_offset // -1) >= 0 and round_up_to_multiple($v[0], $self->block_size) != round_up_to_multiple($self->{"size"}, $self->block_size) 0 67 67
Condition70%7/10
($self->{"size"} // 0) > 0 and ($self->device_offset // -1) >= 0 and round_up_to_multiple($v[0], $self->block_size) != round_up_to_multiple($self->{"size"}, $self->block_size)
!ll&&!rl&&r
46210
($self->{"size"} // 0) > 0 and ($self->device_offset // -1) >= 0
!ll&&!rl&&r
46021
$self->{"size"} // 0
l!l
2344
$self->device_offset // -1
l!l
210
MC/DC0%0/3
($self->{"size"} // 0) > 0 and ($self->device_offset // -1) >= 0 and round_up_to_multiple($v[0], $self->block_size) != round_up_to_multiple($self->{"size"}, $self->block_size)
$self->{"size"} $self->device_offset round_up_to_multiple($v[0], $self->block_size) != round_up_to_multiple($self->{"size"}, $self->block_size)
Truth table50%2/4
A and B and C
A= $self->{"size"}B= $self->device_offsetC= round_up_to_multiple($v[0], $self->block_size) != round_up_to_multiple($self->{"size"}, $self->block_size)
ABCresult
0XX0
10X0
1100
1111
54 67 $self->{size}= $v[0];
55 }
56 $self->{size}
57 328 }
58  
59  
60 405 ▶sub device_offset($self, @v) {
Subroutine device_offset: called CC=5 SCAR=16.3
Pod documented
61 405 ▶ if (@v) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v) 48 357 405
62 48 ▶ croak "device_offset $v[0] not a multiple of ".$self->block_size
Branch: 1 branch
BranchTrueFalseTotal
if ($v[0] // 0) > 0 and $v[0] & $self->block_size - 1 0 48 48
Condition80%4/5
($v[0] // 0) > 0 and $v[0] & $self->block_size - 1
!ll&&!rl&&r
4440
$v[0] // 0
l!l
471
MC/DC0%0/2
($v[0] // 0) > 0 and $v[0] & $self->block_size - 1
$v[0] $v[0] & $self->block_size - 1
Truth table66%2/3
A and B
A= $v[0]B= $v[0] & $self->block_size - 1
ABresult
0X0
100
111
63 if ($v[0]//0) > 0 && ($v[0] & ($self->block_size-1));
64 48 $self->{device_offset}= $v[0];
65 }
66 $self->{device_offset}
67 405 }
68  
69  
70 143 ▶sub start_lba($self, @v) {
Subroutine start_lba: called CC=5 SCAR=16.2
Pod documented
71 143 ▶ if (@v) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v) 1 142 143
72 1 ▶ $self->device_offset($v[0] && ($v[0] * $self->block_size));
Condition33%1/3
$v[0] && $v[0] * $self->block_size
!ll&&!rl&&r
001
MC/DC0%0/2
$v[0] && $v[0] * $self->block_size
$v[0] $v[0] * $self->block_size
Truth table33%1/3
A && B
A= $v[0]B= $v[0] * $self->block_size
ABresult
0X0
100
111
73 }
74 143 my $ofs= $self->device_offset;
75 3 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 143 ▶ return defined $ofs && $ofs >= 0? ($ofs / $self->block_size) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ofs && $ofs >= 0 ? : 139 4 143
Condition100%3/3
defined $ofs and $ofs >= 0
!ll&&!rl&&r
31139
MC/DC100%2/2
defined $ofs and $ofs >= 0
defined $ofs $ofs >= 0
Truth table100%3/3
A and B
A= defined $ofsB= $ofs >= 0
ABresult
0X0
100
111
77 }
78  
79 3 *lba= *start_lba;
80  
81 37 ▶sub end_lba($self, @v) {
Subroutine end_lba: called CC=6 SCAR=18.8
Pod documented
82 37 ▶ if (@v) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v) 1 36 37
83 1 my $lba= $self->start_lba;
84 1 ▶ croak "Can't set end_lba until start_lba is defined"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lba 0 1 1
85 unless defined $lba;
86 # Using 'size' accessor would trigger the check for altering the size after setting
87 # device offset, which is less likely to be a useful safeguard when someone is setting
88 # start_lba/end_lba.
89 1 $self->{size}= ($v[0] + 1 - $lba) * $self->block_size;
90 }
91 37 my ($ofs, $size)= ($self->device_offset, $self->size);
92 3 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 37 ▶ return ($ofs//-1) < 0 || !$size ? undef : ($ofs + $size - 1) / $self->block_size;
Branch: 1 branch
BranchTrueFalseTotal
($ofs // -1) < 0 || !$size ? : 0 37 37
Condition40%2/5
($ofs // -1) < 0 or not $size
l!l&&r!l&&!r
0037
$ofs // -1
l!l
370
MC/DC0%0/2
($ofs // -1) < 0 or not $size
$ofs not $size
Truth table0%0/3
A or not(B)
A= $ofsB= not $size
ABresult
1X1
011
000
94 }
95  
96  
97 142 ▶sub data($self, @v) {
Subroutine data: called CC=4 SCAR=14.1
Pod documented
98 142 ▶ if (@v) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v) 64 78 142
99 64 ▶ croak "data must be a scalar-ref or LazyFileData object"
Branch: 1 branch
BranchTrueFalseTotal
if defined $v[0] and not &isa_data_ref($v[0]) 0 64 64
Condition66%2/3
defined $v[0] and not &isa_data_ref($v[0])
!ll&&!rl&&r
40240
MC/DC0%0/2
defined $v[0] and not &isa_data_ref($v[0])
defined $v[0] not &isa_data_ref($v[0])
Truth table66%2/3
A and not(B)
A= defined $v[0]B= not &isa_data_ref($v[0])
ABresult
0X0
100
111
100 if defined $v[0] && !isa_data_ref $v[0];
101 64 $self->{data}= $v[0];
102 }
103 $self->{data}
104 142 }
105  
106 # Avoiding dependency on namespace::clean
107 3 delete @{Sys::Export::Extent::}{qw(
108 carp croak confess blessed isa_array isa_data_ref isa_export_dst isa_exporter isa_group
109 isa_handle isa_hash isa_int isa_pow2 isa_user isa_userdb round_up_to_multiple
110 )};
111 3 1;
112  
113 __END__
« Export/VFAT/Directory.pm ↑ Summary Export/LogAny.pm »