OSSP::uuid(3perl)

πŸ“¦
version 1.6.6 Β· 2 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– OSSP::uuid β€” the Perl binding, bestie edition πŸ’–

okay so this is OSSP::uuid, from the 3perl manual section, and it's the Perl glow-up of the OSSP uuid library. sit with me, we're gonna go through the whole thing. no skipping. ✨


🌸 NAME 🌸

OSSP::uuid β€” the OSSP uuid Perl Binding. that's it, that's the name, she's serving exactly what it says on the tin. πŸ’…


✨ DESCRIPTION ✨

so. OSSP uuid is a ISO-C:1999 application programming interface (API) and a corresponding command line interface (CLI) for generating Universally Unique Identifier (UUID) values that comply with RFC 9562, ISO/IEC 11578:1996 and IETF RFC-4122. she's compliant with all of them, she's an overachiever, we love her. πŸ‘‘

she 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 πŸ”

and there are additional API bindings provided for the Perl:5 language (hi, that's us 🫢). plus, optional backward compatibility exists for the ISO-C DCE-1.1 and Perl Data::UUID APIs, in case you're running old code and can't let go. no judgment, i get it.

OSSP::uuid is the Perl binding to the OSSP uuid API, and it comes in three delicious variants. pick your fighter:

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

the TIE-style API is a functionality-reduced wrapper around the OO-style API and it's intended for very high-level convenience programming. it's the "just make it work, i'm tired" option. πŸ™ˆ

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 it's intended for high-level regular programming. this is the everyday main character. ✨

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;

additionally β€” and this is the cute part β€” the strings "v1", "v3", "v4", "v5", "v6", "v7", and "mc" can be used in $mode, and the strings "bin", "str", and "txt" can be used in $fmt. short, sweet, iconic. πŸ’…

🌈 C-STYLE API 🌈

the C-style API is a direct mapping of the OSSP uuid ISO-C API to Perl, and it's intended for low-level programming. we're down in the engine room now. see uuid(3) for a description of the functions and their expected arguments.

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_ismax($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);

additionally, the following constants are exported for use in $rc, $mode, $fmt, and $ver β€” here's the full squad, all of them, not a single one left behind:

  • 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_MAKE_V6
  • UUID_MAKE_V7
  • UUID_FMT_BIN
  • UUID_FMT_STR
  • UUID_FMT_SIV
  • UUID_FMT_TXT

πŸ“ EXAMPLES πŸ“

okay bestie, here's where it all clicks. the following two examples create the version 3 UUID 02d9e6d5-9467-382e-8f9b-9300a64ac3cd, both via the OO-style and the C-style API. (yes, that's a real value, and yes, it slaps. πŸ”₯)

heads up though β€” error handling is omitted here for easier reading, but it has to be added for production-quality code. do not ship the vibes-only version. i'm serious. 😭
#   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 flavours, same delicious UUID. it's giving range. 🌈


πŸ‘€ SEE ALSO πŸ‘€

go read these next, they're all part of the same friend group:


πŸ“œ HISTORY πŸ“œ

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


and that's the whole page, bestie, you ate it. 🫢 this was OSSP::uuid(3perl) from ossp-uuid 1.6.6, dated December 8, 2025 β€” go make some UUIDs, you've got this. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from