| 1 | package Barcode::Code93; | ||||||||||
| 2 | 2 | ▶ | use strict; use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Barcode::Code93 - Generate data for Code 93 barcodes | ||||||||||
| 8 | |||||||||||
| 9 | =cut | ||||||||||
| 10 | |||||||||||
| 11 | 2 | our $VERSION = '0.04'; | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | use Barcode::Code93; | ||||||||||
| 17 | my $data = Barcode::Code93->new->barcode('MONKEY'); | ||||||||||
| 18 | print for map { $_ ? "#" : ' ' } @$data; | ||||||||||
| 19 | |||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||
| 21 | |||||||||||
| 22 | This class is used to generate data for Code 93 barcodes. It is primarily | ||||||||||
| 23 | useful as a data source for barcode modules that do rendering, | ||||||||||
| 24 | such as L<HTML::Barcode::Code93>. You can easily make a version that | ||||||||||
| 25 | renders an image, PDF, or anything else. | ||||||||||
| 26 | |||||||||||
| 27 | =head1 METHODS | ||||||||||
| 28 | |||||||||||
| 29 | =head2 new | ||||||||||
| 30 | |||||||||||
| 31 | Instantiate a new Barcode::Code93 object. | ||||||||||
| 32 | |||||||||||
| 33 | =head2 barcode ($text) | ||||||||||
| 34 | |||||||||||
| 35 | Generate barcode data representing the C<$text> string. This returns | ||||||||||
| 36 | an array (or arrayref in scalar context) containing true and false values | ||||||||||
| 37 | that represent lines and spaces. | ||||||||||
| 38 | |||||||||||
| 39 | =cut | ||||||||||
| 40 | |||||||||||
| 41 | sub barcode { | ||||||||||
| 42 | 1 | ▶ | my ($self, $text) = @_; | ||||||||
|
Subroutine
barcode: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 43 | 1 | my @data = $self->_barcode(uc $text); | |||||||||
| 44 | 1 | ▶ | return wantarray ? @data : \@data; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | =head1 AUTHOR | ||||||||||
| 48 | |||||||||||
| 49 | Chris DiMartino C<<chris DOT dimartino AT gmail DOT com>> (L<GD::Barcode::Code93>, from which this distribution originates) | ||||||||||
| 50 | |||||||||||
| 51 | Mark A. Stratman, C<< <stratman at gmail.com> >> | ||||||||||
| 52 | |||||||||||
| 53 | Jan Bieron L<https://github.com/bieron> | ||||||||||
| 54 | |||||||||||
| 55 | =head1 CONTRIBUTERS | ||||||||||
| 56 | |||||||||||
| 57 | The L<GD::Barcode::Code93> module, from which this module originates, was based on code provided by Kawai Takanori. Japan. | ||||||||||
| 58 | |||||||||||
| 59 | The L<GD::Barcode::Code93> module was written by Chris DiMartino, 2004. Thanks to Lobanov Igor, Joel Richard, and Joshua Fortriede for their excellent Bug Reports and patches. All rights reserved. | ||||||||||
| 60 | |||||||||||
| 61 | =head1 SOURCE REPOSITORY | ||||||||||
| 62 | |||||||||||
| 63 | L<http://github.com/mstratman/Barcode-Code93> | ||||||||||
| 64 | |||||||||||
| 65 | =head1 SEE ALSO | ||||||||||
| 66 | |||||||||||
| 67 | =over 4 | ||||||||||
| 68 | |||||||||||
| 69 | =item L<GD::Barcode::Code93> | ||||||||||
| 70 | |||||||||||
| 71 | =item L<HTML::Barcode::Code93> | ||||||||||
| 72 | |||||||||||
| 73 | =back | ||||||||||
| 74 | |||||||||||
| 75 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 76 | |||||||||||
| 77 | Copyright 2011 the AUTHORs and CONTRIBUTERS listed above. | ||||||||||
| 78 | |||||||||||
| 79 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 80 | under the terms of either: the GNU General Public License as published | ||||||||||
| 81 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 82 | |||||||||||
| 83 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | =cut | ||||||||||
| 87 | |||||||||||
| 88 | #------------------------------------------------------------------------------ | ||||||||||
| 89 | # barcode (from GD::Barcode::Code93) | ||||||||||
| 90 | #------------------------------------------------------------------------------ | ||||||||||
| 91 | sub _barcode { | ||||||||||
| 92 | 1 | ▶ | my ($self, $text) = @_; | ||||||||
|
Subroutine
_barcode: called CC=1 SCAR=0.0
| |||||||||||
| 93 | |||||||||||
| 94 | 1 | my %code93bar = ( | |||||||||
| 95 | 0 =>'100010100', | ||||||||||
| 96 | 1 =>'101001000', | ||||||||||
| 97 | 2 =>'101000100', | ||||||||||
| 98 | 3 =>'101000010', | ||||||||||
| 99 | 4 =>'100101000', | ||||||||||
| 100 | 5 =>'100100100', | ||||||||||
| 101 | 6 =>'100100010', | ||||||||||
| 102 | 7 =>'101010000', | ||||||||||
| 103 | 8 =>'100010010', | ||||||||||
| 104 | 9 =>'100001010', | ||||||||||
| 105 | A =>'110101000', | ||||||||||
| 106 | B =>'110100100', | ||||||||||
| 107 | C =>'110100010', | ||||||||||
| 108 | D =>'110010100', | ||||||||||
| 109 | E =>'110010010', | ||||||||||
| 110 | F =>'110001010', | ||||||||||
| 111 | G =>'101101000', | ||||||||||
| 112 | H =>'101100100', | ||||||||||
| 113 | I =>'101100010', | ||||||||||
| 114 | J =>'100110100', | ||||||||||
| 115 | K =>'100011010', | ||||||||||
| 116 | L =>'101011000', | ||||||||||
| 117 | M =>'101001100', | ||||||||||
| 118 | N =>'101000110', | ||||||||||
| 119 | O =>'100101100', | ||||||||||
| 120 | P =>'100010110', | ||||||||||
| 121 | Q =>'110110100', | ||||||||||
| 122 | R =>'110110010', | ||||||||||
| 123 | S =>'110101100', | ||||||||||
| 124 | T =>'110100110', | ||||||||||
| 125 | U =>'110010110', | ||||||||||
| 126 | V =>'110011010', | ||||||||||
| 127 | W =>'101101100', | ||||||||||
| 128 | X =>'101100110', | ||||||||||
| 129 | Y =>'100110110', | ||||||||||
| 130 | Z =>'100111010', | ||||||||||
| 131 | ' ' =>'111010010', | ||||||||||
| 132 | '$' =>'111001010', | ||||||||||
| 133 | '%' =>'110101110', | ||||||||||
| 134 | '($)'=>'100100110', | ||||||||||
| 135 | '(%)'=>'111011010', | ||||||||||
| 136 | '(+)'=>'100110010', | ||||||||||
| 137 | '(/)'=>'111010110', | ||||||||||
| 138 | '+' =>'101110110', | ||||||||||
| 139 | '-' =>'100101110', | ||||||||||
| 140 | '.' =>'111010100', | ||||||||||
| 141 | '/' =>'101101110', | ||||||||||
| 142 | '*' =>'101011110', ##Start/Stop | ||||||||||
| 143 | ); | ||||||||||
| 144 | |||||||||||
| 145 | 1 | my @sum_text = ('*', $self->calculateSums($text), '*'); | |||||||||
| 146 | |||||||||||
| 147 | 1 | my @rv = map { split //, $code93bar{$_} } @sum_text; | |||||||||
| 148 | 1 | push @rv, 1; | |||||||||
| 149 | 1 | return @rv; | |||||||||
| 150 | } | ||||||||||
| 151 | |||||||||||
| 152 | |||||||||||
| 153 | #----------------------------------------------------------------------------- | ||||||||||
| 154 | # calculateSums (from GD::Barcode::Code93) | ||||||||||
| 155 | #----------------------------------------------------------------------------- | ||||||||||
| 156 | sub calculateSums { | ||||||||||
| 157 | 1 | ▶ | my ($self, $text) = @_; | ||||||||
|
Subroutine
calculateSums: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||
| 158 | 1 | ▶ | $text = '' unless defined $text; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | 1 | my @array = split(//, scalar reverse $text); | |||||||||
| 160 | |||||||||||
| 161 | 1 | my %code93values = ( | |||||||||
| 162 | '0' =>'0', | ||||||||||
| 163 | '1' =>'1', | ||||||||||
| 164 | '2' =>'2', | ||||||||||
| 165 | '3' =>'3', | ||||||||||
| 166 | '4' =>'4', | ||||||||||
| 167 | '5' =>'5', | ||||||||||
| 168 | '6' =>'6', | ||||||||||
| 169 | '7' =>'7', | ||||||||||
| 170 | '8' =>'8', | ||||||||||
| 171 | '9' =>'9', | ||||||||||
| 172 | 'A' =>'10', | ||||||||||
| 173 | 'B' =>'11', | ||||||||||
| 174 | 'C' =>'12', | ||||||||||
| 175 | 'D' =>'13', | ||||||||||
| 176 | 'E' =>'14', | ||||||||||
| 177 | 'F' =>'15', | ||||||||||
| 178 | 'G' =>'16', | ||||||||||
| 179 | 'H' =>'17', | ||||||||||
| 180 | 'I' =>'18', | ||||||||||
| 181 | 'J' =>'19', | ||||||||||
| 182 | 'K' =>'20', | ||||||||||
| 183 | 'L' =>'21', | ||||||||||
| 184 | 'M' =>'22', | ||||||||||
| 185 | 'N' =>'23', | ||||||||||
| 186 | 'O' =>'24', | ||||||||||
| 187 | 'P' =>'25', | ||||||||||
| 188 | 'Q' =>'26', | ||||||||||
| 189 | 'R' =>'27', | ||||||||||
| 190 | 'S' =>'28', | ||||||||||
| 191 | 'T' =>'29', | ||||||||||
| 192 | 'U' =>'30', | ||||||||||
| 193 | 'V' =>'31', | ||||||||||
| 194 | 'W' =>'32', | ||||||||||
| 195 | 'X' =>'33', | ||||||||||
| 196 | 'Y' =>'34', | ||||||||||
| 197 | 'Z' =>'35', | ||||||||||
| 198 | '-' =>'36', | ||||||||||
| 199 | '.' =>'37', | ||||||||||
| 200 | ' ' =>'38', | ||||||||||
| 201 | '$' =>'39', | ||||||||||
| 202 | '/' =>'40', | ||||||||||
| 203 | '+' =>'41', | ||||||||||
| 204 | '%' =>'42', | ||||||||||
| 205 | '($)' =>'43', | ||||||||||
| 206 | '(%)' =>'44', | ||||||||||
| 207 | '(/)' =>'45', | ||||||||||
| 208 | '(+)' =>'46', | ||||||||||
| 209 | '*' => '', | ||||||||||
| 210 | ); | ||||||||||
| 211 | |||||||||||
| 212 | 1 | my %invCode93Values = reverse %code93values; | |||||||||
| 213 | |||||||||||
| 214 | 1 | foreach my $counter (20, 15) { | |||||||||
| 215 | 2 | my $weighted_sum = 0; | |||||||||
| 216 | 2 | my $x = 1; | |||||||||
| 217 | 2 | foreach my $letter (@array) { | |||||||||
| 218 | 13 | ▶ | if ($x > $counter) { $x = 1 } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 219 | 13 | $weighted_sum += ($code93values{$letter} * $x); | |||||||||
| 220 | 13 | $x++; | |||||||||
| 221 | } | ||||||||||
| 222 | |||||||||||
| 223 | 2 | my $check = $invCode93Values{($weighted_sum % 47)}; | |||||||||
| 224 | 2 | unshift @array, $check; | |||||||||
| 225 | } | ||||||||||
| 226 | |||||||||||
| 227 | 1 | return reverse @array; | |||||||||
| 228 | } | ||||||||||
| 229 | |||||||||||
| 230 | 2 | 1; | |||||||||