blib/lib/Convert/Ascii85.pm

filter: Statementstmt 100% 52 / 52 Branchbran 100% 8 / 8 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 100% 77 / 77 CC 12 SCAR 18.3
CC
12
Cov
100%
encode
9.0
decode
4.0
BEGIN
1.0
CRAP 6.2
↑ Summary
1 package Convert::Ascii85;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = '0.01';
7  
8 4 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 our @EXPORT_OK = qw(ascii85_encode ascii85_decode);
11  
12 4 my $_space_no = unpack 'N', ' ' x 4;
13  
14 11 ▶sub encode {
Subroutine encode: called CC=9 SCAR=22.0
Pod documented
15 11 my ($in, $opt) = @_;
16 11 ▶ my $compress_zero = exists $opt->{compress_zero} ? $opt->{compress_zero} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{'compress_zero'} ? : 2 9 11
17 11 my $compress_space = $opt->{compress_space};
18  
19 11 my $padding = -length($in) % 4;
20 11 $in .= "\0" x $padding;
21 11 my $out = '';
22  
23 11 for my $n (unpack 'N*', $in) {
24 86 ▶ if ($n == 0 && $compress_zero) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 0 and $compress_zero) 7 79 86
Condition100%3/3
$n == 0 and $compress_zero
!ll&&!rl&&r
7727
MC/DC100%2/2
$n == 0 and $compress_zero
$n == 0 $compress_zero
Truth table100%3/3
A and B
A= $n == 0B= $compress_zero
ABresult
0X0
100
111
25 7 $out .= 'z';
26 7 next;
27 }
28 79 ▶ if ($n == $_space_no && $compress_space) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == $_space_no and $compress_space) 1 78 79
Condition100%3/3
$n == $_space_no and $compress_space
!ll&&!rl&&r
7621
MC/DC100%2/2
$n == $_space_no and $compress_space
$n == $_space_no $compress_space
Truth table100%3/3
A and B
A= $n == $_space_noB= $compress_space
ABresult
0X0
100
111
29 1 $out .= 'y';
30 1 next;
31 }
32  
33 78 my $tmp = '';
34 78 for my $i (reverse 0 .. 4) {
35 390 my $mod = $n % 85;
36 390 $n = int($n / 85);
37 390 vec($tmp, $i, 8) = $mod + 33;
38 }
39 78 $out .= $tmp;
40 }
41  
42 11 ▶ $padding or return $out;
Branch: 1 branch
BranchTrueFalseTotal
$padding or return $out 7 4 11
43  
44 7 $out =~ s/z\z/!!!!!/;
45 7 substr $out, 0, length($out) - $padding
46 }
47  
48 4 *ascii85_encode = \&encode;
49  
50 11 ▶sub decode {
Subroutine decode: called CC=4 SCAR=13.9
Pod documented
51 11 my ($in) = @_;
52 11 for ($in) {
53 11 tr[ \t\r\n\f][]d;
54 11 s/z/!!!!!/g;
55 11 s/y/+<VdL/g;
56 }
57  
58 11 my $padding = -length($in) % 5;
59 11 $in .= 'u' x $padding;
60 11 my $out = '';
61  
62 11 for my $n (unpack '(a5)*', $in) {
63 86 my $tmp = 0;
64 86 for my $i (unpack 'C*', $n) {
65 430 $tmp *= 85;
66 430 $tmp += $i - 33;
67 }
68 86 $out .= pack 'N', $tmp;
69 }
70  
71 11 substr $out, 0, length($out) - $padding
72 }
73  
74 4 *ascii85_decode = \&decode;
75  
76 4 1
77  
78 __END__
↑ Summary