File Coverage

blib/lib/PDF/Builder/Resource/XObject/Form/BarCode/codabar.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 2 50.0
total 23 24 95.8


line stmt bran cond sub pod time code
1             package PDF::Builder::Resource::XObject::Form::BarCode::codabar;
2              
3 2     2   1088 use base 'PDF::Builder::Resource::XObject::Form::BarCode';
  2         6  
  2         592  
4              
5 2     2   13 use strict;
  2         5  
  2         39  
6 2     2   10 use warnings;
  2         3  
  2         383  
7              
8             our $VERSION = '3.023'; # VERSION
9             our $LAST_UPDATE = '2.029'; # manually update whenever code is changed
10              
11             =head1 NAME
12              
13             PDF::Builder::Resource::XObject::Form::BarCode::codabar - specific information for CodaBar bar codes. Inherits from L
14              
15             =cut
16              
17             sub new {
18 1     1 1 4 my ($class, $pdf, %options) = @_;
19              
20 1         8 my $self = $class->SUPER::new($pdf, %options);
21              
22 1         14 my @bars = $self->encode($options{'-code'});
23              
24 1         8 $self->drawbar([@bars], $options{'caption'});
25              
26 1         8 return $self;
27             }
28              
29             # allowed alphabet and translation to bar widths
30             my $codabar = q|0123456789-$:/.+ABCD|;
31              
32             my @barcodabar = qw(
33             11111221 11112211 11121121 22111111 11211211
34             21111211 12111121 12112111 12211111 21121111
35             11122111 11221111 21112121 21211121 21212111
36             11212121 aabbabaa ababaaba ababaaba aaabbbaa
37             );
38              
39             sub encode_char {
40 17     17 0 21 my $self = shift;
41 17         30 my $char = uc(shift());
42              
43 17         45 return $barcodabar[index($codabar, $char)];
44             }
45              
46             1;