SimpleBackuper/DB/Packer.pm

filter: Statementstmt 87.7% 43 / 49 Branchbran 50.0% 10 / 20 Conditioncond 78.5% 11 / 14 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 6 totaltotal 69.1% 74 / 107 CC 17 SCAR 20.5
CC
17
Cov
77%
pack
12.7
print_state
12.0
unpack
4.0
CRAP 7.8
« SimpleBackuper/Info.pm ↑ Summary SimpleBackuper/BackupDB.pm »
1 package App::SimpleBackuper::DB::Packer;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Const::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 const my %LENGTH => ( map { $_ => length(pack $_.8, 1)/8 } qw(J H a C) );
9  
10 12 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
11 12 my($class, $data) = @_;
12
13 12 ▶ return bless {
Condition100%2/2
$data || ''
l!l
66
MC/DC100%1/1
$data || ''
$data
Truth table100%2/2
A
A= $data
Aresult
11
00
14 data => $data || '',
15 offset => 0,
16 } => $class;
17 }
18  
19 117 ▶sub at_end { $_[0]->{offset} >= length( $_[0]->{data} ) }
Subroutine at_end: called CC=1 SCAR=0.0
Pod undocumented
20  
21 57 ▶sub unpack {
Subroutine unpack: called CC=4 SCAR=13.9
Pod undocumented
22 57 my($self, $type, $count) = @_;
23
24 57 ▶ if($count ne '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($count ne '*') { } 56 1 57
25 56 ▶ croak "Too much count ($count)" if $count >= 2147483648;
Branch: 1 branch
BranchTrueFalseTotal
if $count >= 2147483648 0 56 56
26 56 ▶ confess "At end of data" if $self->at_end;
Branch: 1 branch
BranchTrueFalseTotal
if $self->at_end 0 56 56
27 56 my $length = $LENGTH{$type} * $count;
28 56 my $res = unpack( $type.$count, substr( $self->{data}, $self->{offset}, $length ) );
29 56 $self->{offset} += $length;
30 56 return $res;
31 } else {
32 1 my $res = unpack( $type.$count, substr( $self->{data}, $self->{offset} ) );
33 1 $self->{offset} = length( $self->{data} );
34 1 return $res;
35 }
36 }
37  
38 56 ▶sub pack {
Subroutine pack: called CC=11 SCAR=25.4
Pod undocumented
39 56 my($self, $type, $count, @values) = @_;
40
41 56 ▶ croak "Not at end of data" if ! $self->at_end;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->at_end 0 56 56
42 56 ▶ confess "Undefined count (type=$type)" if ! defined $count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 0 56 56
43 56 ▶ croak "Too much count ($count)" if $count ne '*' and $count >= 2147483648;
Branch: 1 branch
BranchTrueFalseTotal
if $count ne "*" and $count >= 2147483648 0 56 56
Condition66%2/3
$count ne "*" and $count >= 2147483648
!ll&&!rl&&r
4520
MC/DC0%0/2
$count ne "*" and $count >= 2147483648
$count ne "*" $count >= 2147483648
Truth table66%2/3
A and B
A= $count ne "*"B= $count >= 2147483648
ABresult
0X0
100
111
44 56 ▶ confess "Undefined value" if grep {! defined} @values;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} @values 0 56 56
45 56 ▶ confess "Is not a number" if $type eq 'J' and grep { /\D/ } @values;
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "J" and grep {/\D/;} @values 0 56 56
Condition66%2/3
$type eq "J" and grep {/\D/;} @values
!ll&&!rl&&r
13430
MC/DC0%0/2
$type eq "J" and grep {/\D/;} @values
$type eq "J" grep {/\D/;} @values
Truth table66%2/3
A and B
A= $type eq "J"B= grep {/\D/;} @values
ABresult
0X0
100
111
46 56 ▶ croak "Can't pack a* with multiple values" if $type eq 'a' and $count eq '*' and @values > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "a" and $count eq "*" and @values > 1 0 56 56
Condition83%5/6
$type eq "a" and $count eq "*" and @values > 1
!ll&&!rl&&r
5240
$type eq "a" and $count eq "*"
!ll&&!rl&&r
4574
MC/DC0%0/3
$type eq "a" and $count eq "*" and @values > 1
$type eq "a" $count eq "*" @values > 1
Truth table75%3/4
A and B and C
A= $type eq "a"B= $count eq "*"C= @values > 1
ABCresult
0XX0
10X0
1100
1111
47
48 56 my $value = pack($type.$count, (@values));
49 56 $self->{offset} += length $value;
50 56 $self->{data} .= $value;
51
52 56 return $self;
53 }
54  
55 6 ▶sub data {shift->{data}}
Subroutine data: called CC=1 SCAR=0.0
Pod undocumented
56  
57 0 ▶sub print_state {
Subroutine print_state: not called CC=3 SCAR=24.8
Pod undocumented
58 0 my $self = shift;
59 0 for my $q (0 .. length($self->{data}) - 1) {
60 0 ▶ print "->" if $q == $self->{offset};
Branch: 1 branch
BranchTrueFalseTotal
if $q == $self->{"offset"} 0 0 0
61 0 printf "\\x%02x", ord(substr( $self->{data}, $q, 1 ));
62 }
63 0 print "\n";
64 0 return $self;
65 }
66  
67 4 1;
« SimpleBackuper/Info.pm ↑ Summary SimpleBackuper/BackupDB.pm »