```{index} single: Peta::FFI::UUID ``` # Peta::FFI::UUID ```{pperl-module-badges} Peta::FFI::UUID ``` Generate and parse RFC 4122 UUIDs via the system's libuuid library. The library is located at run time, so pperl needs no build-time dependency on it. If `libuuid.so` is not installed, `use Peta::FFI::UUID` still succeeds and every call croaks with an instruction telling you which package to install. ```perl use Peta::FFI::UUID qw(uuid_generate_random uuid_parse uuid_unparse uuid_is_null); my $text = uuid_generate_random(); # "2d6c8b1e-0f4a-4c3e-9b7d-5a1e2f3c4d5e" my $bytes = uuid_parse($text); # the same UUID as 16 raw bytes print uuid_unparse($bytes) eq $text ? "round trip\n" : "differs\n"; print uuid_is_null("\0" x 16) ? "nil UUID\n" : "not nil\n"; ``` The generators return the text form; `uuid_parse` and `uuid_unparse` convert between it and the binary form. Nothing is exported by default. Peta::FFI::UUID is pperl's own module, version 0.2.0. ## Functions ### Other Functions #### `uuid_generate` `uuid_generate()`: a new UUID as its 36-character text form - random (version 4) when the system has a good random source, else time-based (version 1). #### `uuid_generate_random` `uuid_generate_random()`: a new random (version 4) UUID, as text: `"2d6c8b1e-0f4a-4c3e-9b7d-5a1e2f3c4d5e"`. #### `uuid_generate_time` `uuid_generate_time()`: a new time-based (version 1) UUID, as text. It carries the generation time and a node identifier, so it reveals when and where it was made. #### `uuid_parse` `uuid_parse($text)`: the 16-byte binary form of a UUID's text form, or undef when `$text` is not one. #### `uuid_is_null` `uuid_is_null($bytes)`: 1 when the 16-byte binary UUID is all zeros (the nil UUID), else 0. Anything but 16 bytes dies "requires a 16-byte UUID". #### `uuid_unparse` `uuid_unparse($bytes)`: the 36-character text form of a 16-byte binary UUID, in lower case. Anything but 16 bytes dies "requires a 16-byte UUID".