uuid(3pm)

πŸ“¦
version 1.6.2 Β· 4 versions
, in ubuntu jammy

πŸ’– uuid(3pm) πŸ’–

okay bestie, pull up a chair, we're reading the User Contributed Perl Documentation entry for OSSP::uuid, and it is genuinely iconic. this is the man page for the Perl binding, and yes it has three whole API flavours because it contains multitudes. πŸ’…


✨ NAME ✨

OSSP::uuid β€” the OSSP uuid Perl Binding. that's it, that's the name, no notes. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so. OSSP uuid is an ISO-C:1999 application programming interface (API) plus a matching command line interface (CLI), and its whole job is generating DCE 1.1, ISO/IEC 11578:1996 and RFC 4122 compliant Universally Unique Identifiers (UUIDs). bestie it does not miss. πŸ’–

it supports DCE 1.1 variant UUIDs of these versions:

  • version 1 β€” time and node based
  • version 3 β€” name based, MD5
  • version 4 β€” random number based
  • version 5 β€” name based, SHA-1

additional API bindings are provided for the languages ISO-C++:1998, Perl:5 and PHP:4/5. and there's optional backward compatibility for the ISO-C DCE-1.1 and Perl Data::UUID APIs, because it's generous like that. 😌

OSSP::uuid is the Perl binding to the OSSP uuid API. three variants are provided, and we are going to meet all three of them like the main characters they are:


πŸŽ€ TIE-STYLE API πŸŽ€

the TIE-style API is a functionality-reduced wrapper around the OO-style API, and it exists purely for very high-level convenience programming. it's giving "i don't want to think about objects, i want a variable that just is a UUID". slay.

"use OSSP::uuid;"
tie" my $uuid, 'OSSP::uuid::tie', $mode, ...;"
"$uuid = [ $mode, ... ];"
"print "UUID=$uuid\n";"
"untie $uuid;"

πŸ¦‹ OO-STYLE API πŸ¦‹

the OO-style API is a wrapper around the C-style API and is meant for high-level regular programming. object-oriented, well-mannered, brings a gift to the function.

"use OSSP::uuid;"
"my $uuid = "new" OSSP::uuid;"
"$uuid->"load"($name);"
"$uuid->"make"($mode, ...);"
"$result = $uuid->"isnil"();"
"$result = $uuid->"compare"($uuid2);"
"$uuid->"import"($fmt, $data_ptr);"
"$data_ptr = $uuid->"export"($fmt);"
"[(]$str[, $rc)] = $uuid->"error"();"
"$ver = $uuid->"version"();"
"undef $uuid;"

bonus bestie behaviour: the strings v1, v3, v4, v5 and mc can all be used in $mode, and the strings bin, str, and txt can be used for $fmt. no cap. πŸŽ€


πŸ’… C-STYLE API πŸ’…

the C-style API is a direct mapping of the OSSP uuid ISO-C API onto Perl, and it's intended for low-level programming. see uuid(3) for a description of the functions and their expected arguments. it's the raw, unfiltered version and honestly? respect.

"use OSSP::uuid qw(:all);"
"my $uuid; $rc = "uuid_create"($uuid);"
"$rc = "uuid_load"($uuid, $name);"
"$rc = "uuid_make"($uuid, $mode, ...);"
"$rc = "uuid_isnil"($uuid, $result);"
"$rc = "uuid_compare"($uuid, $uuid2, $result);"
"$rc = "uuid_import"($uuid, $fmt, $data_ptr, $data_len);"
"$rc = "uuid_export"($uuid, $fmt, $data_ptr, $data_len);"
"$str = "uuid_error"($rc);"
"$ver = "uuid_version"();"
"$rc = "uuid_destroy"($uuid);"

and additionally, these constants are exported for use in $rc, $mode, $fmt and $ver:

"UUID_VERSION", "UUID_LEN_BIN", "UUID_LEN_STR", "UUID_RC_OK", "UUID_RC_ARG", "UUID_RC_MEM", "UUID_RC_SYS", "UUID_RC_INT", "UUID_RC_IMP", "UUID_MAKE_V1", "UUID_MAKE_V3", "UUID_MAKE_V4", "UUID_MAKE_V5", "UUID_MAKE_MC", "UUID_FMT_BIN", "UUID_FMT_STR", "UUID_FMT_SIV", "UUID_FMT_TXT".


🌈 EXAMPLES 🌈

okay so the following two examples create the version 3 UUID 02d9e6d5-9467-382e-8f9b-9300a64ac3cd, both via the OO-style and the C-style API. ✨

heads up bestie: error handling is omitted here for easier reading, but it has to be added for production-quality code. do not come for me when it breaks, i warned you. 😭
#   TIE-style API (very high-level)
use OSSP::uuid;
tie my $uuid, 'OSSP::uuid::tie';
$uuid = [ "v1" ];
print "UUIDs: $uuid, $uuid, $uuid\n";
$uuid = [ "v3", "ns:URL", "http://www.ossp.org/" ];
print "UUIDs: $uuid, $uuid, $uuid\n";
untie $uuid;

#   OO-style API (high-level)
use OSSP::uuid;
my $uuid    = new OSSP::uuid;
my $uuid_ns = new OSSP::uuid;
$uuid_ns->load("ns:URL");
$uuid->make("v3", $uuid_ns, "http://www.ossp.org/");
undef $uuid_ns;
my $str = $uuid->export("str");
undef $uuid;
print "$str\n";

#   C-style API (low-level)
use OSSP::uuid qw(:all);
my $uuid;    uuid_create($uuid);
my $uuid_ns; uuid_create($uuid_ns);
uuid_load($uuid_ns, "ns:URL");
uuid_make($uuid, UUID_MAKE_V3, $uuid_ns, "http://www.ossp.org/");
uuid_destroy($uuid_ns);
my $str; uuid_export($uuid, UUID_FMT_STR, $str, undef);
uuid_destroy($uuid);
print "$str\n";

three whole vibes, one UUID. obsessed. πŸ’–


πŸ” SEE ALSO πŸ”

go read these next, bestie, they're the extended universe:


πŸ“œ HISTORY πŸ“œ

the Perl binding OSSP::uuid to OSSP uuid was implemented in November 2004 by Ralf S. Engelschall <rse@engelschall.com>. legend behaviour, honestly. πŸ‘‘


and that's the whole page, babe β€” this one shipped as part of perl v5.34.0 and the page itself is dated 2022-02-06, so if you're reading it, you're reading the good stuff. go make some UUIDs, you've got this. πŸ¦‹βœ¨πŸ’œ

πŸ“¦ where this page comes from