Test2:...l::UUID(3pm)

πŸ“¦
version 0.002010 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Test2::Util::UUID πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation for the module Test2::Util::UUID, and it's literally just the UUID factory for the whole Test2 universe πŸ¦‹


✨ NAME ✨

Test2::Util::UUID β€” utils for generating UUIDs under Test2. that's it, that's the whole job, and she does it flawlessly πŸ’…


🌸 DESCRIPTION 🌸

This module is the one-stop glow-up spot for UUIDs across all of Test2. Like, every part of Test2 that needs a UUID gets it from here, so everybody's on the same page. consistent queen energy πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

use Test2::Util::UUID qw/gen_uuid looks_like_uuid uuid2bin bin2uuid/;

my $uuid = gen_uuid;

my $bin = bin2uuid($uuid);

my $uuid_again = uuid2bin($uuid);

no cap, that's the whole vibe ✨


πŸ”₯ UNDER THE HOOD πŸ”₯

So here's the tea πŸ“ β€” this module doesn't do the UUID-making all by herself. She picks a helper module, and the candidates are listed in order of preference, most-favored first.

  • UUID >= 0.35 β€” when it's possible, she'll use the UUID cpan module. BUT 🚨 it has to be version 0.35 or greater, because anything older has a fork-related bug and we do not do bugs in this house. This one generates version 7 UUIDs, because those are the most suitable for database entry. iconic behavior fr fr πŸ’–
  • Data::UUID::MT β€” the second choice for UUID generation. With this one you get version 4 UUIDs, which are fairly usable in databases. solid, dependable, no notes 🫢
  • UUID::Tiny - slow β€” used only if the previous two aren't available. This module is pure perl, so it could be slower than the others 😭. Version 4 UUIDs get generated when this one is used. Also, a warning will be issued with this module. You can suppress that warning with either the $TEST2_UUID_NO_WARN environment variable or the "warn => 0" import argument.
  • Data::UUID - Not Suitable for Databases β€” this is the last resort, bestie, we're scraping the bottom of the barrel πŸ’€. It generates UUIDs fast, but they're of a type/version that is not suitable for database keys. A warning will be issued with this module too, and you can suppress it with either the $TEST2_UUID_NO_WARN environment variable or the "warn => 0" import argument.

CONTROLLING WARNINGS

AT IMPORT

use Test2::Util::UUID 'gen_uuid', warn => 0;

Passing in "warn => 0" will disable the warnings that normally get issued when using UUID::Tiny or Data::UUID as a backend. peace and quiet, periodt 🀫

SELECTING A BACKEND

AT IMPORT

If you want to override the order and pick exactly which backend gets used, you can do that by listing them during import, each one prefixed with a ':'. watch this ✨

use Test2::Util::UUID 'gen_uuid', backends => [':UUID', ':UUID::Tiny'];

The above will try the UUID module first, followed by the UUID::Tiny module. It will not try Data::UUID::MT or Data::UUID. main character choices only πŸ’…

Note: you must include these import arguments anywhere you import this module, otherwise the other imports will use the default list, which results in different places using different UUIDs 😭. keep it consistent, bestie.

THE $TEST2_UUID_BACKEND ENV VAR

Setting the $TEST2_UUID_BACKEND env var to one of the backends β€” or a comma separated list β€” will override the default list for all imports. It will NOT override imports that specify their own lists though. she respects a girl who makes her own choices πŸŽ€


πŸ¦‹ EXPORTS πŸ¦‹

  • $uuid = gen_uuid() β€” generates a UUID, and it's always normalized to upper case. uppercase only, we don't do lowercase here πŸ’…
  • $uuid_or_undef = looks_like_uuid($UUID) β€” checks if the value you handed over actually looks like a UUID. It makes sure it is defined, 36 characters long, has dashes, and only contains 0-9, a-f and dash (case insensitive). Returns the input value if it looks like a UUID, otherwise it returns undef. vibe check passed or failed, no in-between ✨

🌈 SOURCE 🌈

The source code repository for Test2-Plugin-UUID can be found at https://github.com/Test-More/Test2-Plugin-UUID/. go peek, bestie, the code is right there 🫢


πŸ‘‘ MAINTAINERS πŸ‘‘

  • Chad Granum <exodist@cpan.org>

πŸ’œ AUTHORS πŸ’œ

  • Chad Granum <exodist@cpan.org>

Copyright Chad Granum <exodist@cpan.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://dev.perl.org/licenses/


okay and that's a wrap πŸŽ€ this page came from the perl manual, version v5.40.1, dated 2025-03-31, and honestly? she ate. go generate some UUIDs, you've got this πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from