Builder/Resource/XObject/Form/BarCode/code3of9.pm

filter: Statementstmt 96.3% 52 / 54 Branchbran 64.2% 9 / 14 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 7 / 7 Podpod 25.0% 1 / 4 totaltotal 76.6% 72 / 94 CC 12 SCAR 21.7
CC
12
Cov
83%
new
15.6
encode_3of9_string
3.0
encode_3of9
2.0
CRAP 8.7
« Builder/Basic/PDF/Filter/LZWDecode.pm ↑ Summary Builder/Basic/PDF/Filter/RunLengthDecode.pm »
1 package PDF::Builder::Resource::XObject::Form::BarCode::code3of9;
2  
3 2 ▶use base 'PDF::Builder::Resource::XObject::Form::BarCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '3.028'; # VERSION
9 2 our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
10  
11 =head1 NAME
12  
13 PDF::Builder::Resource::XObject::Form::BarCode::code3of9 - Specific information for 3-of-9 bar codes
14  
15 Inherits from L<PDF::Builder::Resource::XObject::Form::BarCode>
16  
17 =head1 METHODS
18  
19 =head2 new
20  
21 PDF::Builder::Resource::XObject::Form::BarCode::code3of9->new()
22  
23 =over
24  
25 Create a Code 3 of 9 bar code object. Note that it is invoked from the
26 Builder.pm level method!
27  
28 =back
29  
30 =cut
31  
32 2 ▶sub new {
Subroutine new: called CC=9 SCAR=27.5
Pod documented
33 2 my ($class, $pdf, %options) = @_;
34 # copy dashed option names to preferred undashed names
35 2 ▶ if (defined $options{'-code'} && !defined $options{'code'}) { $options{'code'} = delete($options{'-code'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{"-code"} and not defined $options{"code"}) 2 0 2
Condition33%1/3
defined $options{"-code"} and not defined $options{"code"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $options{"-code"} and not defined $options{"code"}
defined $options{"-code"} not defined $options{"code"}
Truth table33%1/3
A and not(B)
A= defined $options{"-code"}B= not defined $options{"code"}
ABresult
0X0
100
111
36 0 ▶ if (defined $options{'-chk'} && !defined $options{'chk'}) { $options{'chk'} = delete($options{'-chk'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{"-chk"} and not defined $options{"chk"}) 0 2 2
Condition33%1/3
defined $options{"-chk"} and not defined $options{"chk"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $options{"-chk"} and not defined $options{"chk"}
defined $options{"-chk"} not defined $options{"chk"}
Truth table33%1/3
A and not(B)
A= defined $options{"-chk"}B= not defined $options{"chk"}
ABresult
0X0
100
111
37 0 ▶ if (defined $options{'-ext'} && !defined $options{'ext'}) { $options{'ext'} = delete($options{'-ext'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{"-ext"} and not defined $options{"ext"}) 0 2 2
Condition33%1/3
defined $options{"-ext"} and not defined $options{"ext"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $options{"-ext"} and not defined $options{"ext"}
defined $options{"-ext"} not defined $options{"ext"}
Truth table33%1/3
A and not(B)
A= defined $options{"-ext"}B= not defined $options{"ext"}
ABresult
0X0
100
111
38  
39 2 my $self = $class->SUPER::new($pdf, %options);
40 my @bars = encode_3of9($options{'code'},
41 $options{'chk'}? 1: 0,
42 2 ▶ $options{'ext'}? 1: 0);
Branch: 2 branches
BranchTrueFalseTotal
$options{'chk'} ? : 0 2 2
$options{'ext'} ? : 0 2 2
43  
44 2 $self->drawbar([@bars], $options{'caption'});
45  
46 2 return $self;
47 }
48  
49 # allowed alphabet and bar widths
50 2 my $code3of9 = q(0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*);
51  
52 2 my @bar3of9 = qw(
53 1112212111 2112111121 1122111121 2122111111
54 1112211121 2112211111 1122211111 1112112121
55 2112112111 1122112111 2111121121 1121121121
56 2121121111 1111221121 2111221111 1121221111
57 1111122121 2111122111 1121122111 1111222111
58 2111111221 1121111221 2121111211 1111211221
59 2111211211 1121211211 1111112221 2111112211
60 1121112211 1111212211 2211111121 1221111121
61 2221111111 1211211121 2211211111 1221211111
62 1211112121 2211112111 1221112111 1212121111
63 1212111211 1211121211 1112121211 abaababaa1
64 );
65  
66 2 my @extended_map = (
67 '%U', '$A', '$B', '$C', '$D', '$E', '$F', '$G', '$H', '$I',
68 '$J', '$K', '$L', '$M', '$N', '$O', '$P', '$Q', '$R', '$S',
69 '$T', '$U', '$V', '$W', '$X', '$Y', '$Z', '%A', '%B', '%C',
70 '%D', '$E', ' ', '/A', '/B', '/C', '/D', '/E', '/F', '/G',
71 '/H', '/I', '/J', '/K', '/L', '-', '.', '/O', '0', '1',
72 '2', '3', '4', '5', '6', '7', '8', '9', '/Z', '%F',
73 '%G', '%H', '%I', '%J', '%V', 'A', 'B', 'C', 'D', 'E',
74 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
75 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
76 'Z', '%K', '%L', '%M', '%N', '%O', '%W', '+A', '+B', '+C',
77 '+D', '+E', '+F', '+G', '+H', '+I', '+J', '+K', '+L', '+M',
78 '+N', '+O', '+P', '+Q', '+R', '+S', '+T', '+U', '+V', '+W',
79 '+X', '+Y', '+Z', '%P', '%Q', '%R', '%S', '%T'
80 );
81  
82 36 ▶sub encode_3of9_char {
Subroutine encode_3of9_char: called CC=1 SCAR=0.0
Pod undocumented
83 36 my $character = shift;
84
85 36 return $bar3of9[index($code3of9, $character)];
86 }
87  
88 6 ▶sub encode_3of9_string {
Subroutine encode_3of9_string: called CC=3 SCAR=11.0
Pod undocumented
89 6 my ($string, $is_mod43) = @_;
90  
91 6 my $bar;
92 6 my $checksum = 0;
93 6 foreach my $char (split //, $string) {
94 24 $bar .= encode_3of9_char($char);
95 24 $checksum += index($code3of9, $char);
96 }
97  
98 6 ▶ if ($is_mod43) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_mod43) 2 4 6
99 2 $checksum %= 43;
100 2 $bar .= $bar3of9[$checksum];
101 }
102  
103 6 return $bar;
104 }
105  
106 # Note: encode_3of9_string_w_chk now encode_3of9_string(*, 1)
107  
108 6 ▶sub encode_3of9 {
Subroutine encode_3of9: called CC=2 SCAR=6.9
Pod undocumented
109 6 my ($string, $is_mod43, $is_extended) = @_;
110  
111 6 my $display;
112 6 ▶ unless ($is_extended) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_extended) { } 2 4 6
113 4 $string = uc($string);
114 4 $string =~ s/[^0-9A-Z\-\.\ \$\/\+\%]+//g;
115 4 $display = $string;
116 } else {
117 # Extended Code39 supports all 7-bit ASCII characters
118 2 $string =~ s/[^\x00-\x7f]//g;
119 2 $display = $string;
120  
121 # Encode, but don't display, non-printable characters
122 2 $display =~ s/[[:cntrl:]]//g;
123  
124 2 $string = join('', map { $extended_map[ord($_)] } split(//, $string));
125 }
126  
127 6 my @bars;
128 6 push @bars, encode_3of9_char('*');
129 6 push @bars, [ encode_3of9_string($string, $is_mod43), $display ];
130 6 push @bars, encode_3of9_char('*');
131  
132 6 return @bars;
133 }
134  
135 # Note: encode_3of9_w_chk now encode_3of9(*, 1, 0)
136 # Note: encode_3of9_ext now encode_3of9(*, 0, 1)
137 # Note: encode_3of9_ext_w_chk now encode_3of9(*, 1, 1)
138  
139 2 1;
« Builder/Basic/PDF/Filter/LZWDecode.pm ↑ Summary Builder/Basic/PDF/Filter/RunLengthDecode.pm »