The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

BarcodeID - Perform simple identification and validation on UPC-A, UPC-E, EAN-8, EAN-13, CODE39 barcodes

SYNOPSIS

  use BarcodeID qw/validate identify barcode type/;

  my $id = BarcodeID->new('barcode' => '012345');
  print $id->barcode();
  $id->identify();
  print $id->type();
  if($id->validate())
  {
    print "Invalid barcode";
  }

  #### OR

  my $id = BarcodeID->new('barcode' => '012345', 'type' => 'UPCE');

  if($id->validate())
  {
    print "Invalid barcode";
  }

DESCRIPTION

When passing the barcode you should omit the check digit, so for a UPCA you should only be passing 11 digits, for a UPCE you should just be passing 6, EAN-8 should be 7 EAN-13 should be 12, the only difference in CODE39 which is variable length and as such the only checking performed here is that is doesn't contain invalid characters.

You can just pass in a barcode and identify it or you can pass in a barcode and a type and validate it.

FUNCTIONS

new

my $id = BarcodeID->new('barcode' => 'A12345');

You can pass in the optional parameters 'barcode' and 'type'

validate

my $a = $id->validate();

This will check and see if the type has been set if not it will identify the type and then validate, if the type is set it will just validate.

This returns 0 for pass and 1 for fail.

new

my $type = $id->identify();

The identify function just checks the length of the barcode, additionally if checks to see if it contains none numeric characters, if it does it automatically identifys it as CODE39, please note it is not validated 'A##$@%' would be identified as a CODE39 but it is invalid when the validate function is call it would fail this.

This function will return the name of the type, or a 2 on the event of failure to identify.

barcode

my $barcode = $id->barcode(); # or $id->barcode('1029384');

This function will allow you to view or set the barcode parameter, if you pass a parameter it will set the barcode to that parameter, if you do not it will just return the currently set barcode.

type

my $type = $id->type(); # or $id->type('EAN8');

This function will allow you to view or set the barcode type parameter, if you pass a parameter it will set the type to that parameter, if you do not it will just return the currently set barcode type.

BUGS

None known please email if you find any!

TODO

Add a method to determine and return the check character.

BUGS and QUERIES

Please direct all correspondence regarding this module to: bmaynard@cpan.org

AUTHOR

Ben Maynard, <cpan@geekserv.com> <http://www.webcentric-hosting.com>

COPYRIGHT AND LICENSE

Copyright (C) 2006 by Ben Maynard

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.