NAME

Data::Identifier::Generate - format independent identifier object

VERSION

version v0.06

SYNOPSIS

use Data::Identifier::Generate;

This module allows generation of instances of Data::Identifier from common non-identifier values. For generation of UUIDs from identifier values see "uuid" in Data::Identifier. The generated identifiers are of type UUID.

This can be used standalone if only an identifier for the given value is needed or as part of a generation logic.

The methods of this module might perform (limited and quick) checks for validity of the given data. If a request is found invalid the method dies. However it is in the responsibility of the caller to ensure the data is correct. Any checks by this module are solely meant as a last resort to finding obvious errors.

The method may also perform auto-correction. This may for example the case a obsolete value is passed and a more current value is known.

See also: Data::TagDB::Factory.

METHODS

integer

my Data::Identifier $identifier = Data::Identifier::Generate->integer($int [, %opts] );

Creates an identifier for the given integer.

The following options (all optional) are supported:

displayname

The displayname as to be used for the identifier. This is the same as defined by "new" in Data::Identifier.

Defaults to the passed number.

date

my Data::Identifier $identifier = Data::Identifier::Generate->date($date [, %opts ] );

Generates an identifier for a given date.

The date must be one of the following: A string (in form YYYYZ, YYYY-MMZ, or YYYY-MM-DDZ) representing a gregorian date, a number representing the time as a UNIX epoch (see "time" in perlfunc, "$^T" in perlvar), a blessed object that provides epoch such as DateTime, or the special values now or today.

Note: When dates are passed in string/ISO 8601 format they must refer to UTC and have the correct suffix Z. If you have timestamps in other timezones than UTC convert them to an epoch first and pass them as epoch. The standard module DateTime might be of help with that. Just appending Z to timestamps in local time or passing timestamps without the Z suffix will result in wrong results!

Note: This function currently only supports 4-digit gregorian dates. Therfore only values for the years 1583 to 9999 (inclusive) can be calculated.

Also if the value is passed in anything but the string form the limits of "gmtime" in perlfunc apply. This also means that this function is year 2038 safe if gmtime is. In this case the range is also limited to the year 2999 to detect common programming errors (the time passed as milliseconds rather than seconds).

The following options (all optional) are supported:

displayname

The displayname as to be used for the identifier. This is the same as defined by "new" in Data::Identifier.

Defaults to the passed date formatted as ISO 8601.

precision

The precision to use for the identifier. One of year, month, and day.

Defaults to the highest possible precision available with the given date.

generic

my Data::Identifier $identifier = Data::Identifier::Generate->generate(%opts);

This provides a most generic interface for generation. It should be avoided in in favour of more specific ones.

The following options are supported:

displayname

The displayname as to be used for the identifier. This is the same as defined by "new" in Data::Identifier.

This option is optional.

input

The raw input for the generator. Must be a string of raw bytes.

This option is to be avoided in favour of request, Exactly one of input or request must be given.

namespace

The namespace to use. Must be an Data::Identifier or raw UUID.

This option is optional if type is passed with the type holding an namespace. See also "namespace" in Data::Identifier.

request

The request to be passed to the generator. The type and range of this value depends on style which must be provided longside request.

Exactly one of request or input must be given.

style

The style to be used by the generator.

Currently supported: integer-based, id-based, name-based, tag-based, tagcombiner.

This option is required unless input is provided.

For tag-based the request must be a raw UUID, a Data::Identifier, or anything "new" in Data::Identifier takes via from.

For tagcombiner the request must be an array reference with each element of a type supported by tag-based. The array must also include at least two distinct identifiers.

type

The type of the identifier to be passed via request.

Must be a Data::Identifier.

This is optional.

AUTHOR

Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2023-2024 by Löwenfelsen UG (haftungsbeschränkt) <support@loewenfelsen.net>.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)