The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Data::Identifier - format independent identifier object

VERSION

version v0.01

SYNOPSIS

    use Data::Identifier;

This module provides an common interface to identifiers of different types. Each identifier stores both it's raw value (called id) and it's type (type).

Note: This module performs basic deduplication and normalisation. This means that you might not always get back exactly the identifier you passed in but an equivalent one. Also note that deduplication is done with performance in mind. This means that there is no guarantee for two equal identifiers to become deduplicated. See also "register".

new

    my Data::Identifier $identifier = Data::Identifier->new($type => $id, %opts);

Creates a new identifier.

$type needs to be a Data::Identifier, a well known name, a UUID, wellknown, or ise. If it is an UUID a type is created as needed. If it is ise it is parsed as uuid, oid, or uri according to it's format. If it is wellknown it refers to an identifier from the well known list.

The following type names are currently well known:

uuid

An UUID.

oid

An OID.

uri

An URI.

wd

An wikidata identifier (Q, P, or L).

gtin

An GTIN (or EAN).

The following options are supported:

validate

A regex that should be used to validate identifiers if this identifier is used as a type.

namespace

The namespace used by a type. Must be a Data::Identifier or an ISE. Must also resolve to an UUID.

wellknown

    my @wellknown = Data::Identifier->wellknown;

Returns a list with all well known identifiers.

This is mostly useful to prime a database.

type

    my Data::Identifier $type = $identifier->type;

Returns the type of the identifier.

id

    my $id = $identifier->id;

Returns the raw id of the identifier.

uuid, oid, uri, sid

    my $uuid = $identifier->uuid;
    my $oid  = $identifier->oid;
    my $uri  = $identifier->uri;
    my $sid  = $identifier->sid;

Return the UUID, OID, URI, or SID (small-identifier) of the current identifier or die if no identifier of that type is known nor can be calculated.

ise

    my $ise = $identifier->ise;

Returns the ISE (UUID, OID, or URI) for the current identifier or die if no ISE is known nor can be calculated.

namespace

    my Data::Identifier $namespace = $identifier->namespace;

Gets the namespace for the type $identifier or dies. This call is only valid for identifiers that are types.

register

    $identifier->register;

Registers the identifier for deduplication. This can be used to register much used identifiers and types early in an application to increase performance. However, note that once registered an identifier object is cached for the life time of the process.

userdata

    my $value = $identifier->userdata(__PACKAGE__, $key);
    $identifier->userdata(__PACKAGE__, $key => $value);

Get or set user data to be used with this identifier. The data is stored using the given $key. The package of the caller is given to provide namespaces for the userdata, so two independent packages can use the same $key.

The meaning of $key, and $value is up to __PACKAGE__.

displayname

    my $displayname = $identifier->displayname;

Returns a display name suitable to display to the user. This function always returns a string. This is mostly for compatibility with Data::TagDB::Tag.

displaycolour, icontext, description

    my $displaycolour = $identifier->displaycolour;
    my $icontext      = $identifier->icontext;
    my $description   = $identifier->description;

These functions always return undef. They are for compatibility with Data::TagDB::Tag.

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)