Universally Unique Identifiers FFI style
my $uuid = UUID::FFI->new_random;
print $uuid->as_hex, "\n";
This module provides an FFI interface to libuuid
.
libuuid
library is used to generate unique identifiers
for objects that may be accessible beyond the local system
my $uuid = UUID::FFI->new($hex);
Create a new UUID object from the hex representation $hex
.
my $uuid = UUID::FFI->new_random;
Create a new UUID object with a randomly generated value.
my $uuid = UUID::FFI->new_time;
Create a new UUID object generated using the time and mac address. This can leak information about when and where the UUID was generated.
my $uuid = UUID::FFI->new_null;
Create a new UUID NULL UUID
object (all zeros).
my $bool = $uuid->is_null;
Returns true if the UUID is NULL UUID
.
my $uuid2 = $uuid->clone;
Create a new UUID object with the identical value to the original.
my $hex = $uuid->as_hex;
my $hex = "$uuid";
Returns the hex representation of the UUID. The stringification of UUID::FFI uses this function, so you can also use it in a double quoted string.
my $cmp = $uuid1->compare($uuid2);
my $cmp = $uuid1 <=> $uuid2;
my @sorted_uuids = sort { $a->compare($b) } @uuids;
my @sorted_uuids = sort { $a <=> $b } @uuids;
Returns an integer less than, equal to or greater than zero
if $uuid1
is found, respectively, to be lexicographically
less than, equal, or greater that $uuid2
. The <=>
is also overloaded so you can use that too.
my $type = $uuid->type;
Returns the type of UUID, either time
or random
,
if it can be identified.
my $variant = $uuid->variant
Returns the variant of the UUID, either ncs
, dce
, microsoft
or other
.
my $time = $uuid->time;
Returns the time the UUID was generated. The value returned is in seconds since the UNIX epoch, so is compatible with perl builtins like time and localtime.
Graham Ollis [email protected]
This software is copyright (c) 2014-2022 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.