| 1 | package PDF::Builder::Resource::XObject::Form::BarCode::int2of5; | ||||||||||||||||||||||||||||
| 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::int2of5 - Specific information for interleaved 2-of-5 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::int2of5->new() | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =over | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Create an Interleaved 2 of 5 bar code object. Note that it is invoked from the | ||||||||||||||||||||||||||||
| 26 | Builder.pm level method! | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =back | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Interleaved 2 of 5 Barcodes | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # Pairs of digits are encoded; the first digit is represented by five | ||||||||||||||||||||||||||||
| 35 | # bars, and the second digit is represented by five spaces interleaved | ||||||||||||||||||||||||||||
| 36 | # with the bars. | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 1 | my ($class, $pdf, %options) = @_; | |||||||||||||||||||||||||||
| 40 | # copy dashed option names to preferred undashed names | ||||||||||||||||||||||||||||
| 41 | 1 | ▶ | if (defined $options{'-code'} && !defined $options{'code'}) { $options{'code'} = delete($options{'-code'}); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $options{"-code"} and not defined $options{"code"}
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"}
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | my $self = $class->SUPER::new($pdf,%options); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | my @bars = $self->encode($options{'code'}); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | $self->drawbar([@bars], $options{'caption'}); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | return $self; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 2 | my @bar25interleaved = qw(11221 21112 12112 22111 11212 21211 12211 11122 21121 12121); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub encode { | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 2 | my ($self, $string) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Remove any character that isn't a digit | ||||||||||||||||||||||||||||
| 58 | 2 | $string =~ s/[^0-9]//g; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Prepend a 0 if there are an odd number of digits | ||||||||||||||||||||||||||||
| 61 | 2 | ▶ | $string = '0' . $string if length($string) % 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Start Code | ||||||||||||||||||||||||||||
| 64 | 2 | my @bars = ('aaaa'); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # Encode pairs of digits | ||||||||||||||||||||||||||||
| 67 | 2 | my ($c1, $c2, $s1, $s2, $pair); | |||||||||||||||||||||||||||
| 68 | 2 | ▶ | while (length($string)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 6 | ($c1, $c2, $string) = split(//, $string, 3); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 6 | $s1 = $bar25interleaved[$c1]; | |||||||||||||||||||||||||||
| 72 | 6 | $s2 = $bar25interleaved[$c2]; | |||||||||||||||||||||||||||
| 73 | 6 | $pair = ''; | |||||||||||||||||||||||||||
| 74 | 6 | foreach my $i (0 .. 4) { | |||||||||||||||||||||||||||
| 75 | 30 | $pair .= substr($s1, $i, 1); | |||||||||||||||||||||||||||
| 76 | 30 | $pair .= substr($s2, $i, 1); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 6 | push @bars, [$pair, ($c1 . $c2)]; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Stop Code | ||||||||||||||||||||||||||||
| 82 | 2 | push @bars, 'baaa'; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | return @bars; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 2 | 1; | |||||||||||||||||||||||||||