| 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 || ''
MC/DC100%1/1
$data || ''
$data
Truth table100%2/2
A
A= $data
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 56 | ▶ | croak "Too much count ($count)" if $count >= 2147483648; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 56 | ▶ | confess "At end of data" if $self->at_end; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 56 | ▶ | confess "Undefined count (type=$type)" if ! defined $count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 56 | ▶ | croak "Too much count ($count)" if $count ne '*' and $count >= 2147483648; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count ne "*" and $count >= 2147483648
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
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 56 | ▶ | confess "Undefined value" if grep {! defined} @values; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 56 | ▶ | confess "Is not a number" if $type eq 'J' and grep { /\D/ } @values; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "J" and grep {/\D/;} @values
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
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 56 | ▶ | croak "Can't pack a* with multiple values" if $type eq 'a' and $count eq '*' and @values > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$type eq "a" and $count eq "*" and @values > 1
$type eq "a" and $count eq "*"
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||