Builder/Basic/PDF/Filter/ASCIIHexDecode.pm

filter: Statementstmt 100% 29 / 29 Branchbran 100% 8 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 100% 49 / 49 CC 6 SCAR 11.6
CC
6
Cov
100%
infilt
5.0
outfilt
2.0
BEGIN
1.0
CRAP 3.2
« Builder/Basic/PDF/Array.pm ↑ Summary Builder/Matrix.pm »
1 package PDF::Builder::Basic::PDF::Filter::ASCIIHexDecode;
2  
3 45 ▶use base 'PDF::Builder::Basic::PDF::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 45 our $VERSION = '3.028'; # VERSION
9 45 our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
10  
11 =head1 NAME
12  
13 PDF::Builder::Basic::PDF::Filter::ASCIIHexDecode - Compress and uncompress stream filters for ASCII-Hex
14  
15 Inherits from L<PDF::Builder::Basic::PDF::Filter>
16  
17 =cut
18  
19 # Maintainer's Note: ASCIIHexDecode is described in the PDF 1.7 spec
20 # in section 7.4.2.
21  
22 3 ▶sub outfilt {
Subroutine outfilt: called CC=2 SCAR=6.9
Pod documented
23 3 my ($self, $string, $include_eod) = @_;
24  
25 # Each byte of the input string gets encoded as two hexadecimal
26 # characters.
27 3 $string =~ s/(.)/sprintf('%02x', ord($1))/oge;
28  
29 # The EOD (end-of-document) marker is a greater-than sign
30 3 ▶ $string .= '>' if $include_eod;
Branch: 1 branch
BranchTrueFalseTotal
if $include_eod 2 1 3
31  
32 3 return $string;
33 }
34  
35 8 ▶sub infilt {
Subroutine infilt: called CC=5 SCAR=16.1
Pod documented
36 8 my ($self, $string) = @_;
37  
38 # "All white-space characters shall be ignored."
39 8 $string =~ s/\s//og;
40  
41 # "A GREATER-THAN SIGN (3Eh) indicates EOD."
42 8 my $has_eod_marker = 0;
43 8 ▶ if (substr($string, -1, 1) eq '>') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($string, -1, 1) eq ">") 3 5 8
44 3 $has_eod_marker = 1;
45 3 chop $string;
46 }
47  
48 # "Any other characters [than 0-9, A-F, or a-f] shall cause an
49 # error."
50 8 ▶ die "Illegal character found in ASCII hex-encoded stream"
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /[^0-9A-Fa-f]/ 1 7 8
51 if $string =~ /[^0-9A-Fa-f]/;
52  
53 # "If the filter encounters the EOD marker after reading an odd
54 # number of hexadecimal digits, it shall behave as if a 0 (zero)
55 # followed the last digit."
56 7 ▶ if ($has_eod_marker and length($string) % 2 == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_eod_marker and length($string) % 2 == 1) 1 6 7
Condition100%3/3
$has_eod_marker and length($string) % 2 == 1
!ll&&!rl&&r
421
MC/DC100%2/2
$has_eod_marker and length($string) % 2 == 1
$has_eod_marker length($string) % 2 == 1
Truth table100%3/3
A and B
A= $has_eod_markerB= length($string) % 2 == 1
ABresult
0X0
100
111
57 1 $string .= '0';
58 }
59  
60 # "The ASCIIHexDecode filter shall produce one byte of binary data
61 # for each pair of ASCII hexadecimal digits."
62 7 $string =~ s/([0-9A-Fa-f]{2})/pack("C", hex($1))/oge;
63  
64 7 return $string;
65 }
66  
67 45 1;
« Builder/Basic/PDF/Array.pm ↑ Summary Builder/Matrix.pm »