Cpio/OldBinary.pm

filter: Statementstmt 14.0% 7 / 50 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 12.5% 1 / 8 Podpod 0.0% 0 / 7 totaltotal 10.8% 8 / 74 CC 10 SCAR 24.7
CC
10
Cov
12%
read_one_header
20.0
cleanup_entry
20.0
read_one
6.0
CRAP 11.8
« Cpio.pm ↑ Summary Cpio/Common.pm »
1 package Archive::Cpio::OldBinary;
2  
3 1 ▶use Archive::Cpio::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 my $TRAILER = 'TRAILER!!!';
6 1 my $BLOCK_SIZE = 512;
7  
8 1 my @HEADER = qw(
9 magic
10 dev
11 ino
12 mode
13 uid
14 gid
15 nlink
16 rdev
17 mtime_high
18 mtime_low
19 namesize
20 datasize_high
21 datasize_low
22 );
23  
24 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
25 0 my ($class, $magic) = @_;
26 0 bless { magic => unpack('v', $magic) }, $class;
27 }
28  
29 0 ▶sub read_one {
Subroutine read_one: not called CC=2 SCAR=17.9
Pod undocumented
30 0 my ($o, $FHwp) = @_;
31 0 my $entry = read_one_header($o, $FHwp);
32  
33 0 $entry->{name} = $FHwp->read($entry->{namesize});
34 0 $entry->{name} =~ s/\0$//;
35  
36 0 ▶ $entry->{name} ne $TRAILER or return;
Branch: 1 branch
BranchTrueFalseTotal
$entry->{"name"} ne $TRAILER or return 0 0 0
37 0 $FHwp->read(padding(2, $entry->{namesize}));
38  
39 0 $entry->{data} = $FHwp->read($entry->{datasize});
40 0 $FHwp->read(padding(2, $entry->{datasize}));
41  
42 0 cleanup_entry($entry);
43  
44 0 $entry;
45 }
46  
47 0 ▶sub read_one_header {
Subroutine read_one_header: not called CC=4 SCAR=30.0
Pod undocumented
48 0 my ($o, $FHwp) = @_;
49  
50 0 my %h;
51 0 my @vals = unpack('v*', $FHwp->read(2 * @HEADER));
52 0 foreach my $field (@HEADER) {
53 0 $h{$field} = shift @vals;
54 }
55 0 foreach ('mtime', 'datasize') {
56 0 $h{$_} = $h{$_ . '_high'} * 0x10000 + $h{$_ . '_low'};
57 }
58  
59 0 ▶ $h{magic} == $o->{magic} or die "bad magic ($h{magic} vs $o->{MAGIC})\n";
Branch: 1 branch
BranchTrueFalseTotal
$h{"magic"} == $o->{"magic"} or die qq[bad magic ($h{"magic"} vs $o->{"MAGIC"})\n] 0 0 0
60  
61 0 \%h;
62 }
63  
64 0 ▶sub write_one {
Subroutine write_one: not called CC=2 SCAR=17.9
Pod undocumented
65 0 my ($o, $F, $entry) = @_;
66  
67 0 $entry->{magic} = $o->{magic};
68 0 $entry->{namesize} = length($entry->{name}) + 1;
69 0 $entry->{datasize} = length($entry->{data});
70  
71 0 foreach ('mtime', 'datasize') {
72 0 $entry->{$_ . '_high'} = int($entry->{$_} / 0x10000);
73 0 $entry->{$_ . '_low'} = $entry->{$_} % 0x10000;
74 }
75  
76 write_or_die($F, pack_header($entry) .
77 $entry->{name} . "\0" .
78 0 "\0" x padding(2, $entry->{namesize}));
79 0 write_or_die($F, $entry->{data});
80 0 write_or_die($F, "\0" x padding(2, $entry->{datasize}));
81  
82 0 cleanup_entry($entry);
83 }
84  
85 0 ▶sub write_trailer {
Subroutine write_trailer: not called CC=1 SCAR=6.9
Pod undocumented
86 0 my ($o, $F) = @_;
87  
88 0 write_one($o, $F, { name => $TRAILER, data => '', nlink => 1 });
89 0 write_or_die($F, "\0" x padding($BLOCK_SIZE, tell($F)));
90 }
91  
92 0 ▶sub cleanup_entry {
Subroutine cleanup_entry: not called CC=4 SCAR=30.0
Pod undocumented
93 0 my ($entry) = @_;
94  
95 0 foreach ('datasize', 'namesize', 'magic') {
96 0 delete $entry->{$_};
97 }
98 0 foreach (keys %$entry) {
99 0 ▶ /_low$|_high$/ and delete $entry->{$_};
Branch: 1 branch
BranchTrueFalseTotal
/_low$|_high$/ and delete $entry->{$_} 0 0 0
100 }
101 }
102  
103 0 ▶sub pack_header {
Subroutine pack_header: not called CC=2 SCAR=17.9
Pod undocumented
104 0 my ($h) = @_;
105 0 ▶ pack('v*', map { $h->{$_} || 0 } @HEADER);
Condition0%0/2
$h->{$_} || 0
l!l
00
MC/DC0%0/1
$h->{$_} || 0
$h->{$_}
Truth table0%0/2
A
A= $h->{$_}
Aresult
11
00
106 }
107  
108 1 1;
« Cpio.pm ↑ Summary Cpio/Common.pm »