Export/LazyFileData.pm

filter: Statementstmt 90.7% 39 / 43 Branchbran 70.0% 7 / 10 Conditioncond 47.3% 9 / 19 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 85.7% 12 / 14 Podpod 100% 7 / 7 totaltotal 73.0% 76 / 104 CC 15 SCAR 19.8
CC
15
Cov
76%
new
14.1
as_string
6.0
as_scalarref
3.7
CRAP 7.3
« Export/VFAT/AllocationTable.pm ↑ Summary Export/VFAT/Directory.pm »
1 package Sys::Export::LazyFileData;
2  
3 12 our $VERSION = '0.006'; # VERSION
4 # ABSTRACT: Reference a path and optional range of bytes and load it on demand
5  
6 12 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use experimental qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use overload q{""} => \&as_string, q{${}} => \&as_scalarref;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use Sys::Export ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 32 ▶sub new($class, $src, $offset=0, $size=undef) {
Subroutine new: called CC=12 SCAR=26.4
Pod documented
16 32 my ($abs, $actual_size);
17 32 ▶ if (ref $src eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $src eq 'SCALAR') { } 3 29 32
18 # Ensure is only bytes
19 3 ▶ croak "Wide character in file data scalar ref"
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($src) and not utf8::downgrade($src, 1) 0 3 3
Condition33%1/3
utf8::is_utf8($src) and not utf8::downgrade($src, 1)
!ll&&!rl&&r
300
MC/DC0%0/2
utf8::is_utf8($src) and not utf8::downgrade($src, 1)
utf8::is_utf8($src) not utf8::downgrade($src, 1)
Truth table33%1/3
A and not(B)
A= utf8::is_utf8($src)B= not utf8::downgrade($src, 1)
ABresult
0X0
100
111
20 if utf8::is_utf8($src) && !utf8::downgrade($src, 1);
21 # If given a scalar-ref, and size and offset are the defaults, then we can just cache that directly.
22 3 ▶ return bless [ $src, $src, 0, length $$src ], $class
Branch: 1 branch
BranchTrueFalseTotal
if not $offset and !$size || $size == length $$src 1 2 3
Condition50%3/6
not $offset and !$size || $size == length $$src
!ll&&!rl&&r
201
not $size or $size == length $$src
l!l&&r!l&&!r
100
MC/DC33%1/3
not $offset and !$size || $size == length $$src
not $offset not $size $size == length $$src
Truth table50%2/4
not(A) and not(B) or C
A= not $offsetB= not $sizeC= $size == length $$src
ABCresult
0XX0
1000
11X1
1011
23 if !$offset && (!$size || $size == length $$src);
24 2 $actual_size= length $$src;
25 } else {
26 29 ▶ $abs= Cwd::abs_path($src) // croak "Can't resolve '$src' to a real file";
Condition50%1/2
Cwd::abs_path($src) // croak("Can't resolve '${src}' to a real file")
l!l
290
MC/DC0%0/1
Cwd::abs_path($src) // croak("Can't resolve '${src}' to a real file")
Cwd::abs_path($src)
Truth table50%1/2
A
A= Cwd::abs_path($src)
Aresult
11
00
27 29 $actual_size= -s $abs;
28 }
29 31 ▶ $size //= $actual_size - $offset;
Condition100%2/2
$size //= $actual_size - $offset
l!l
229
MC/DC100%1/1
$size //= $actual_size - $offset
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
30 31 ▶ croak "Requested size ($src, $offset+$size) exceeds actual size ($actual_size)"
Branch: 1 branch
BranchTrueFalseTotal
if $offset + $size > $actual_size 0 31 31
31 if $offset+$size > $actual_size;
32 31 return bless [ undef, $src, $offset, $size, $abs ], $class;
33 }
34  
35  
36 0 ▶sub source { $_[0][1] }
Subroutine source: not called CC=1 SCAR=6.9
Pod documented
37 6 ▶sub offset { $_[0][2] }
Subroutine offset: called CC=1 SCAR=0.0
Pod documented
38 7 ▶sub size { $_[0][3] }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
39 2 ▶sub abs_path { $_[0][4] }
Subroutine abs_path: called CC=1 SCAR=0.0
Pod documented
40  
41 43 ▶sub as_scalarref {
Subroutine as_scalarref: called CC=3 SCAR=13.1
Pod documented
42 0 ▶ $_[0][0] //= ref $_[0][1] eq 'SCALAR'? \substr(${$_[0][1]}, $_[0][2], $_[0][3])
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0][1] eq 'SCALAR' ? : 0 26 26
Condition66%2/3
$_[0][0] //= ref $_[0][1] eq "SCALAR" ? \substr(${$_[0][1];}, $_[0][2], $_[0][3]) : Sys::Export::map_or_load_file($_[0][1], $_[0][2], $_[0][3])
l!l&&r!l&&!r
17260
MC/DC0%0/2
$_[0][0] //= ref $_[0][1] eq "SCALAR" ? \substr(${$_[0][1];}, $_[0][2], $_[0][3]) : Sys::Export::map_or_load_file($_[0][1], $_[0][2], $_[0][3])
$_[0][0] ref $_[0][1] eq "SCALAR" ? \substr(${$_[0][1];}, $_[0][2], $_[0][3]) : Sys::Export::map_or_load_file($_[0][1], $_[0][2], $_[0][3])
Truth table66%2/3
A //= B
A= $_[0][0]B= ref $_[0][1] eq "SCALAR" ? \substr(${$_[0][1];}, $_[0][2], $_[0][3]) : Sys::Export::map_or_load_file($_[0][1], $_[0][2], $_[0][3])
ABresult
1X1
011
000
43 : Sys::Export::map_or_load_file($_[0][1], $_[0][2], $_[0][3]);
44 }
45  
46 0 ▶sub as_string {
Subroutine as_string: not called CC=2 SCAR=17.9
Pod documented
47 0 ▶ ${ $_[0][0] // $_[0]->as_scalarref }
Condition0%0/3
$_[0][0] // $_[0]->as_scalarref
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0][0] // $_[0]->as_scalarref
$_[0][0] $_[0]->as_scalarref
Truth table0%0/3
A // B
A= $_[0][0]B= $_[0]->as_scalarref
ABresult
1X1
011
000
48 }
49  
50 # Avoiding dependency on namespace::clean
51 12 delete @{Sys::Export::LazyFileData::}{qw( carp croak confess )};
52 12 1;
53  
54 __END__
« Export/VFAT/AllocationTable.pm ↑ Summary Export/VFAT/Directory.pm »