Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s/Any::Moose/Moo/, cleanup #1

Merged
merged 1 commit into from
Feb 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Revision history for Barcode-Code93

0.03 Mon Feb, 2 01:00:06 CET 2015
- Moved from deprecated Any::Moose to Moo
- Refactor for readability

0.02 Fri Apr 1 09:49:05 CDT 2011
- Renamed _calculateSums to calculateSums because GD::Barcode::Code93
needs it (made non-private, indicating we won't break it in the
Expand Down
32 changes: 14 additions & 18 deletions lib/Barcode/Code93.pm
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package Barcode::Code93;
use Any::Moose;
use strict; use warnings;
use Moo;

=head1 NAME

Barcode::Code93 - Generate data for Code 93 barcodes

=cut

our $VERSION = '0.02';
our $VERSION = '0.03';


=head1 SYNOPSIS
Expand Down Expand Up @@ -86,10 +87,9 @@ See http://dev.perl.org/licenses/ for more information.
# barcode (from GD::Barcode::Code93)
#------------------------------------------------------------------------------
sub _barcode {
my $self = shift;
my $text = shift;
my ($self, $text) = @_;

my $code93bar = {
my %code93bar = (
0 =>'100010100',
1 =>'101001000',
2 =>'101000100',
Expand Down Expand Up @@ -138,11 +138,11 @@ sub _barcode {
'.' =>'111010100',
'/' =>'101101110',
'*' =>'101011110', ##Start/Stop
};
);

my @sum_text = ('*', $self->calculateSums($text), '*');

my @rv = map { split //, $code93bar->{$_} } @sum_text;
my @rv = map { split //, $code93bar{$_} } @sum_text;
push @rv, 1;
return @rv;
}
Expand All @@ -152,8 +152,7 @@ sub _barcode {
# calculateSums (from GD::Barcode::Code93)
#-----------------------------------------------------------------------------
sub calculateSums {
my $self = shift;
my $text = shift;
my ($self, $text) = @_;
$text = '' unless defined $text;
my @array = split(//, scalar reverse $text);

Expand Down Expand Up @@ -209,24 +208,21 @@ sub calculateSums {
);

my %invCode93Values = reverse %code93values;
my $weighted_sum;

foreach my $counter ( qw/4 3/ ) {
for (my $i = 0, my $x = 1; $i <= $#array; $i++, $x++) {
my $letter = $array[$i];

if ($x > ($counter * 5)) { $x = 1 }
foreach my $counter (20, 15) {
my $weighted_sum = 0;
my $x = 1;
foreach my $letter (@array) {
if ($x > $counter) { $x = 1 }
$weighted_sum += ($code93values{$letter} * $x);
$x++;
}

my $check = $invCode93Values{($weighted_sum % 47)};
unshift @array, $check;
$weighted_sum = ();
}

return reverse @array;
}

no Any::Moose;

1;