Net::UPCDatabase - Simple OO interface to UPCDatabase.com


Net-UPCDatabase documentation  | view source Contained in the Net-UPCDatabase distribution.

Index


NAME

Top

Net::UPCDatabase - Simple OO interface to UPCDatabase.com

SYNOPSIS

Top

  use Net::UPCDatabase;
  my $upcdb = Net::UPCDatabase->new;

  print "\n[lookup]\n";
  my $upc = '035000764119';
  my $item = $upcdb->lookup($upc);
  print "UPC: $item->{upc}\n";
  if ($item->{error}) {
    print "Error: $item->{error}\n";
  }
  else {
    print "Product: $item->{description}\n";
    print "Size: $item->{size}\n";
  }

  print "\n[convertUpcE]\n";
  my $upcE = '01212901';
  my $upcA = $upcdb->convertUpcE($upcE);
  print "UPCE: $upcA->{upcE}\n";
  if ($upcA->{error}) {
    print "Error: $upcA->{error}\n";
  }
  else {
    print "UPCA: $upcA->{upc}\n";
  }

  print "\n[calculateCheckDigit]\n";
  my $upcC = '01200000129C';
  my $upcA = $upcdb->calculateCheckDigit($upcE);
  print "UPCC: $upcA->{upcC}\n";
  if ($upcA->{error}) {
    print "Error: $upcA->{error}\n";
  }
  else {
    print "UPCA: $upcA->{upc}\n";
  }

DESCRIPTION

Top

Connects to UPCDatabase.com to get information about a given UPC.

FUNCTIONS

Top

new

  $upcObject = Net::UPCDatabase->new;

  # .. or ..

  $upcObject = Net::UPCDatabase->new( url => $aDifferentUrlThanDefault );

Accepts an OPTIONAL argument, a URL to use instead of the default. Unless you're really sure what you're doing, don't give it a URL. It defaults to 'http://www.upcdatabase.com/rpc', which is probably the right thing.

Returns the object.

lookup

  $itemInfo = $upcObject->lookup($upc);

  # example usage
  my $ean = '0012000000133'; # pepsi 12oz can
  print "EAN: $ean\n";
  my $item = $upcdb->lookup($ean);
  die "LOOKUP-ERROR: $item->{error}\n" if $item->{error};
  print Dumper($item);

Accepts a REQUIRED argument, the UPC to lookup. The UPC can be UPC-E (8 digits), UPC-A (12 digits), or EAN (13 digits).

Returns the data about the given UPC in a hash reference.

On error, it returns the given error reason as $itemInfo->{error}.

convertUpcE

  $ean = $upcObject->convertUpcE($upcE);
  die "ERROR: $ean->{error}\n" if $ean->{error};
  print "EAN: $ean->{ean}\n";

  # example usage
  my $upce = '01201701'; # pepsi 24 pack
  print "UPCE: $upce\n";
  $ean = $upcdb->convertUpcE($upce);
  die "EAN-ERROR: $ean->{error}\n" if $ean->{error};
  print "EAN: $ean->{ean}\n";
  $item = $upcdb->lookup($ean->{ean});
  die "LOOKUP-ERROR: $item->{error}\n" if $item->{error};
  print Dumper($item);

Accepts a REQUIRED argument, the UPC-E to convert.

Returns the EAN (exactly 13 digits).

On error, it returns the given error reason as $itemInfo->{error}.

calculateCheckDigit

  $ean = '001200000C2X1';  # bad (more than one digit being calculated)
  $ean = '001200000C29C';  # bad (more than one digit being calculated)
  $ean = '001200000129C';  # good (only one digit)
  $ean = '00120000012C1';  # good (only one digit)
  $ean = $upcObject->calculateCheckDigit($ean);
  die "ERROR: $ean->{error}\n" if $ean->{error};
  print "EAN: $ean->{ean}\n";

Accepts a REQUIRED argument, the UPC-A or EAN with checkdigit placeholder (C or X) to calculate. This function will calculate the missing digit for any position, not just the last position. This only works if only one digit being calculated. This doesn't work with UPC-E. There is no difference between using "X" or "C" as the placeholder.

Returns the EAN with the checkdigit properly calculated.

On error, it returns the given error reason as $itemInfo->{error}.

NOTE: This uses an internal function, not the function on UPCDatabase.com because it appears that it is currently not implemented on the UPCDatabase.com side of things. If it is implemented to the same extent on UPCDatabase.com, it is a simple change to use it instead.

_calculateCheckDigit

The internal function that calculates the check digit. You won't want to use this yourself.

DEPENDENCIES

Top

Frontier::Client Frontier::RPC2

TODO

Top

UPC checksum checking/creation

Clean up calculation of odd-position checkdigit calculation. It currently uses an inefficient brute-force method of calculation for that position. Even-position and checksum position calculation is pretty efficient. OEOEOEOEOEOX (O=odd, E=even, X=checksum) It's not *really* that wasteful, just not as efficient as it could be.

BUGS

Top

Report bugs on the CPAN bug tracker. Please, do complain if something is broken.

SEE ALSO

Top

http://www.upcdatabase.com/

COPYRIGHT AND LICENSE

Top


Net-UPCDatabase documentation  | view source Contained in the Net-UPCDatabase distribution.