API2/Resource/XObject/Form/BarCode/ean13.pm

filter: Statementstmt 77.7% 35 / 45 Branchbran 33.3% 2 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 33.3% 1 / 3 totaltotal 71.6% 43 / 60 SCAR 20.8
CC
7
Cov
73%
calculate_check_digit
20.0
encode
4.0
BEGIN
1.0
CRAP 8.0
« API2/Resource/XObject/Image.pm ↑ Summary API2/Basic/PDF/Name.pm »
1 package PDF::API2::Resource::XObject::Form::BarCode::ean13;
2  
3 2 ▶use base 'PDF::API2::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 = '2.044'; # VERSION
9  
10 sub new {
11 1 ▶ my ($class, $pdf, %options) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12 1 my $self = $class->SUPER::new($pdf, %options);
13  
14 1 my @bars = $self->encode($options{'-code'});
15  
16 1 $self->drawbar([@bars], $options{'caption'});
17  
18 1 return $self;
19 }
20  
21 2 my @ean_code_odd = qw(3211 2221 2122 1411 1132 1231 1114 1312 1213 3112);
22 2 my @ean_code_even = qw(1123 1222 2212 1141 2311 1321 4111 2131 3121 2113);
23 2 my @parity = qw(OOOOOO OOEOEE OOEEOE OOEEEO OEOOEE OEEOOE OEEEOO OEOEOE OEOEEO OEEOEO);
24  
25 sub encode {
26 11 ▶ my ($self, $string) = @_;
Subroutine encode: called CC=4 SCAR=13.9
Pod undocumented
27 11 my @digits = split //, $string;
28  
29 # The first digit determines the even/odd pattern of the next six
30 # digits, and is printed to the left of the barcode
31 11 my $first = shift @digits;
32 11 my @bars = (['07', $first]);
33  
34 # Start Guard
35 11 push @bars, 'a1a';
36  
37 # Digits 2-7
38 11 foreach my $i (0 .. 5) {
39 66 my $digit = shift @digits;
40 66 ▶ if (substr($parity[$first], $i, 1) eq 'O') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($parity[$first], $i, 1) eq 'O') { } 39 27 66
41 39 push @bars, [$ean_code_odd[$digit], $digit];
42 }
43 else {
44 27 push @bars, [$ean_code_even[$digit], $digit];
45 }
46 }
47  
48 # Center Guard
49 11 push @bars, '1a1a1';
50  
51 # Digits 8-13
52 11 for (0..5) {
53 66 my $digit = shift @digits;
54 66 push @bars, [$ean_code_odd[$digit], $digit];
55 }
56  
57 # Right Guard
58 11 push @bars, 'a1a';
59  
60 11 return @bars;
61 }
62  
63 sub calculate_check_digit {
64 0 ▶ my ($self, $string) = @_;
Subroutine calculate_check_digit: not called CC=4 SCAR=30.0
Pod undocumented
65 0 my @digits = split //, $string;
66 0 my $weight = 1;
67 0 my $checksum = 0;
68 0 foreach my $i (0..11) {
69 0 $checksum += $digits[$i] * $weight;
70 0 ▶ $weight = $weight == 1 ? 3 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$weight == 1 ? : 0 0 0
71 }
72  
73 0 $checksum = $checksum % 10;
74 0 ▶ return 0 unless $checksum;
Branch: 1 branch
BranchTrueFalseTotal
unless $checksum 0 0 0
75 0 return 10 - $checksum;
76 }
77  
78 2 1;
« API2/Resource/XObject/Image.pm ↑ Summary API2/Basic/PDF/Name.pm »