Net::UPCDatabase - Simple OO interface to UPCDatabase.com
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"; }
Connects to UPCDatabase.com to get information about a given UPC.
$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.
$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}.
$itemInfo->{error}
$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).
$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.
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.
The internal function that calculates the check digit. You won't want to use this yourself.
Frontier::Client Frontier::RPC2
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.
Report bugs on the CPAN bug tracker. Please, do complain if something is broken.
http://www.upcdatabase.com/
Copyright 2005-2009 by Dusty Wilson
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Net::UPCDatabase, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::UPCDatabase
CPAN shell
perl -MCPAN -e shell install Net::UPCDatabase
For more information on module installation, please visit the detailed CPAN module installation guide.