NAME
Data::URIID::Barcode - Extractor for identifiers from URIs
VERSION
version v0.16
SYNOPSIS
use Data::URIID::Barcode;
my Data::URIID::Barcode $barcode = Data::URIID::Barcode->new(type => ..., data => ..., [ %opts ] );
# or:
my Data::URIID::Barcode $barcode = Data::URIID::Barcode->new(from => ..., [ %opts ] );
This module represents a single barcode.
This package inherits from Data::URIID::Base.
METHODS
sheet
my @barcodes = Data::URIID::Barcode->sheet(%opts);
# or:
my $barcode = Data::URIID::Barcode->sheet(%opts);
# e.g.:
my @barcodes = Data::URIID::Barcode->sheet(filename => 'bla.jpg');
# or:
my @barcodes = Data::URIID::Barcode->sheet(type => Data::URIID::Barcode->TYPE_QRCODE, template => 'IDX-%03u', values => [0 .. 9]);
Creates a set of barcode objects from a sheet.
When called in scalar context returns the best result (best for a metric not further defined, which may also change in later versions) or die
s if none was found.
Experimental: This method is currently experimental. It might change at any time.
The following options are supported:
filename
-
A file to read from.
filter_type
-
Filters the barcodes based on their type. This takes the same values as "has_type".
This value might also be used to hint any scanners.
filter_data
-
Filters the barcodes based on their data. This is a regex or a function (coderef).
If it's a function the data of the barcode is passed as first argument. All other arguments are undefined by this version and later versions may define values for them.
from
-
A perl object to use. If given
values
must beundef
. values
-
A list (arrayref) of values to be used as data barcodes to be generated. If given
from
must beundef
. template
-
A template (see "sprintf" in perlfunc) that is applied to each value in
values
.Defaults to no transformation. If defined, must not be used with values that are references.
type
-
The type of the barcode to be used with
values
.
new
my Data::URIID::Barcode $barcode = Data::URIID::Barcode->new(type => ..., data => ..., [ %opts ] );
# or:
my Data::URIID::Barcode $barcode = Data::URIID::Barcode->new(from => ..., [ %opts ] );
This method creates a new barcode object.
The following options are supported:
data
-
The raw data of the barcode.
extractor
-
optionally, an instance of Data::URIID.
from
-
optionally, an instance of another object to read the values from. Depending on the given object the non-optional values might become optional.
Currently the following types are supported: Data::URIID::Base, Data::Identifier, URI. Other types might be supported as well.
type
-
The type of the barcode. One of
TYPE_*
. Future versions of this module might improve this definition.
data
my $data = $barcode->data;
Returns the data of the barcode.
The returned value might differ from the value passed to "new" as it might have been normalised, decoded (character set), or otherwise altered.
No options are supported. However the options default
, and no_defaults
are ignored.
type
my $type = $barcode->type;
Returns the type of the barcode.
The returned value might differ from the value passed to "new" as it might have been normalised, replaced with a cached reference, or otherwise altered.
No options are supported. However the options default
, and no_defaults
are ignored.
See "has_type" for a more convenient method.
has_type
my $bool = $barcode->has_type(Data::URIID::Barcode->TYPE_*);
# or:
my $bool = $barcode->has_type([Data::URIID::Barcode->TYPE_*, ...]);
Returns whether or not this barcode is of the given type.
If the type is given as an arrayref then it is checked if the type matches any of the elements.
No options are supported. However the options default
, and no_defaults
are ignored.
render
$barcode->render(filename => ...);
Render the barcode as a image file.
Experimental: This method is experimental. It may change completly or may be removed on future versions.
Note: Currently this method exports as PNG. Later versions might support other formats.
type_info
my @info = Data::URIID::Barcode->type_info;
# or:
my @info = Data::URIID::Barcode->type_info($type0, $type1, ...);
# or:
my $info = Data::URIID::Barcode->type_info($type);
# or:
my $info = $barcode->type_info;
Returns information on a barcode type. If called in list context returns a list. If called in scalar context returns the only one result (or die
s if there is not exactly one result).
Takes a list of TYPE_*
constants as arguments. If the provided value is not a TYPE_*
constant the value is checked against an internal alias list. If no types are given, returns information for all known types (if called on the package) or for the type of the current barcode (if called on an instance).
Each element returned is an hash reference containing the following keys:
type
-
The value of the
TYPE_*
constant. special
-
Whether the type is a special one (not a real barcode type). Such include
TYPE_OTHER
, andTYPE_UNKNOWN
. Later versions of this module might add more special types. aliases
-
An arrayref with alias names for the given type. Note: This list might be empty.
TYPES
This module supports a number of types of barcodes.
Note: This module does not define the type or value the TYPE_*
constants have. Future versions of this module might change this at any release. Always use the type constants.
TYPE_UNKNOWN
The type of the barcode is unknown. This might be used if e.g. the scanner software does not tell. However this limits the set of features this module can provide.
TYPE_OTHER
The type of barcode is known, but not supported by this module. Future versions of this module might implement the given type.
TYPE_QRCODE
A QR-Code.
TYPE_EAN13
A EAN-13 code commonly found on products.
TYPE_EAN8
A EAN-8 code commonly found on products in small packages.
AUTHOR
Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2023-2025 by Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)