Test2-Plugin-UUID-0.002010000755001750001750 014772043642 15267 5ustar00exodistexodist000000000000README100644001750001750 535514772043642 16240 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010NAME Test2::Plugin::UUID - Use REAL UUIDs in Test2 DESCRIPTION Test2 normally uses unique IDs generated by appending pid, thread-id, and an incrementing integer. These work fine most of the time, but are not sufficient if you want to keep a database of events, in that case a real UUID is much more useful. SYNOPSIS use Test2::Plugin::UUID; This is also useful at the command line for 1-time use: $ perl -MTest2::Plugin::UUID path/to/test.t CONTROLLING WARNINGS AND BACKENDS You can turn off backend warnings, and choose your own backend order preference: use Test2::Plugin::UUID warn => 0, backends => ['UUID', ...]; Or at the command line: perl -MTest2::Plugin::UUID=warn,0 path/to/test.t Or via env vars: TEST2_UUID_BACKEND="UUID,Data::UUID::MT" TEST2_UUID_WARN=0 perl path/to/test.t Normally warnings will be issued if UUID::Tiny or Data::UUID are used as the first is slow and the second is not suitible for database keys. BACKENDS One of the following modules will be used under the hood, they are listed here in order of preference. UUID >= 0.35 When possible this module will use the UUID cpan module, but it must be version 0.35 or greater to avoid a fork related bug. It will generate version 7 UUIDs as they are most suitible for database entry. Data::UUID::MT Data::UUID::MT is the second choice for UUID generation. With this module version 4 UUIDs are generated as they are fairly usable in databases. UUID::Tiny - slow UUID::Tiny is used if the previous 2 are not available. This module is pure perl and thus could be slower than the others. Version 4 UUIDs are generated when this module is used. A warning will be issued with this module. You can surpress the warning with either the $TEST2_UUID_NO_WARN environment variable or the warn => 0 import argument. Data::UUID - Not Suitible for Databases This is the last resort module. This generates UUIDs fast, but they are of a type/version that is not suitible for database keys. A warning will be issued with this module. You can surpress the warning with either the $TEST2_UUID_NO_WARN environment variable or the warn => 0 import argument. SOURCE The source code repository for Test2-Plugin-UUID can be found at https://github.com/Test-More/Test2-Plugin-UUID/. MAINTAINERS Chad Granum AUTHORS Chad Granum COPYRIGHT Copyright Chad Granum . 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/ LICENSE100644001750001750 4642414772043642 16407 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010This software is copyright (c) 2025 by Chad Granum. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2025 by Chad Granum. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Perl Artistic License 1.0 --- This software is Copyright (c) 2025 by Chad Granum. This is free software, licensed under: The Perl Artistic License 1.0 The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Changes100644001750001750 217714772043642 16652 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.0020100.002010 2025-03-29 12:18:57-07:00 America/Los_Angeles - Remove void use of warnings {} 0.002009 2024-08-13 08:35:13-07:00 America/Los_Angeles - Improve warnings 0.002008 2024-06-03 18:37:17-07:00 America/Los_Angeles - Add uuid<->bin converters 0.002007 2024-05-31 21:49:10-07:00 America/Los_Angeles - Bump minimum version to 5.10 0.002006 2024-05-31 12:11:32-07:00 America/Los_Angeles - Documentation fixes 0.002005 2024-05-31 10:06:31-07:00 America/Los_Angeles - Add diagnostics test that prints module versions 0.002004 2024-05-30 15:32:33-07:00 America/Los_Angeles - Expand for multiple UUID generators - Some warnings about UUID generator quality - Add tests for each backend - Add tests for forking to make sure there are no duplicates on fork - Add Test2::Util::UUID to make logic reusable 0.002003 2024-05-12 11:56:39-07:00 America/Los_Angeles - Fix issue where duplicate UUIDs could be generated after forking 0.002002 2024-04-25 12:16:42+01:00 Europe/Lisbon - Fix a debian issue (#2) 0.002001 2019-08-16 15:45:11-07:00 America/Los_Angeles - Initial Import MANIFEST100644001750001750 41214772043642 16456 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.032. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README README.md cpanfile dist.ini lib/Test2/Plugin/UUID.pm lib/Test2/Util/UUID.pm t/00-report.t t/uuid.t xt/author/pod-syntax.t dist.ini100644001750001750 431714772043642 17021 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010name = Test2-Plugin-UUID author = Chad Granum license = Perl_5 copyright_holder = Chad Granum [RewriteVersion] ; sets dist version from main module's $VERSION [License] [ManifestSkip] [Manifest] [NextRelease] [GatherDir] exclude_match = ^cover exclude_match = ^nyt exclude_match = ^test-logs exclude_filename = LICENSE exclude_filename = Makefile.PL exclude_filename = cpanfile exclude_filename = README exclude_filename = README.md exclude_filename = .yath-persist.json [PodSyntaxTests] [TestRelease] [MetaResources] bugtracker.web = http://github.com/Test-More/Test2-Plugin-UUID/issues repository.url = http://github.com/Test-More/Test2-Plugin-UUID/ repository.type = git [Prereqs] perl = 5.010000 Test2::API = 1.302165 UUID::Tiny = 1.04 [Prereqs / RuntimeRecommends] UUID = 0.35 Data::UUID::MT = 1.001 Data::UUID = 1.227 [Prereqs / RuntimeSuggests] UUID = 0.35 Data::UUID::MT = 1.001 Data::UUID = 1.227 [Prereqs / TestRequires] Test2::V0 = 0.000162 Test2::Require::Module = 0.000162 Test2::Util::Table = 0.000162 [Prereqs / DevelopRequires] Test::Spelling = 0.12 ; for xt/author/pod-spell.t UUID = 0.35 Data::UUID::MT = 1.001 Data::UUID = 1.227 Atomic::Pipe = 0.022 [MakeMaker] [CPANFile] [MetaYAML] [MetaJSON] ; authordep Pod::Markdown [ReadmeFromPod / Markdown] filename = lib/Test2/Plugin/UUID.pm type = markdown readme = README.md [ReadmeFromPod / Text] filename = lib/Test2/Plugin/UUID.pm type = text readme = README [CopyFilesFromBuild] copy = LICENSE copy = cpanfile copy = README copy = README.md copy = Makefile.PL [Git::Check] allow_dirty = Makefile.PL allow_dirty = README allow_dirty = README.md allow_dirty = cpanfile allow_dirty = LICENSE allow_dirty = Changes [Git::Commit] allow_dirty = Makefile.PL allow_dirty = README allow_dirty = README.md allow_dirty = cpanfile allow_dirty = LICENSE allow_dirty = Changes [Git::Tag] [FakeRelease] [BumpVersionAfterRelease] [Git::Commit / Commit_Changes] munge_makefile_pl = true allow_dirty_match = ^lib allow_dirty_match = ^scripts allow_dirty = Makefile.PL allow_dirty = README allow_dirty = README.md allow_dirty = cpanfile allow_dirty = LICENSE commit_msg = Automated Version Bump t000755001750001750 014772043642 15453 5ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010uuid.t100644001750001750 1227514772043642 16775 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010/tuse Test2::V0; use Test2::API qw/intercept context/; require Test2::Require::RealFork; require Test2::Require::Module; require Test2::Plugin::UUID; use Test2::Util::UUID qw/looks_like_uuid/; my %backends = ( 'UUID' => [0.35, []], 'Data::UUID::MT' => [undef, []], 'UUID::Tiny' => [undef, ["Using UUID::Tiny for uuid generation. UUID::Tiny is significantly slower than the 'UUID' or 'Data::UUID::MT' modules, please install 'UUID' or 'Data::UUID::MT' if possible. If you insist on using UUID::Tiny you can set the TEST2_UUID_NO_WARN environment variable.\n"]], 'Data::UUID' => [undef, ["Using Data::UUID to generate UUIDs, this works, but the UUIDs will not be suitible as database keys. Please install the 'UUID', 'Data::UUID::MT' or the slower but pure perl 'UUID::Tiny' cpan modules for better UUIDs. If you insist on using Data::UUID you can set the TEST2_UUID_NO_WARN environment variable.\n"]], ); for my $backend (sort keys %backends) { subtest $backend => sub { my ($ver, $warn) = @{$backends{$backend}}; Test2::Require::Module->import($backend, $ver ? $ver : ()); subtest import => sub { Test2::Util::UUID->clear_cache; is( warnings { Test2::Plugin::UUID->import(backends => [$backend], warn => 0) }, [], "No warnings", ); my $events = intercept { sub { ok(1) }->() }; my $uuid_check = validator(is_uuid => sub { looks_like_uuid($_) }); like( $events->[0], hash { field uuid => $uuid_check; field trace => {uuid => $uuid_check, huuid => $uuid_check}; field hubs => [{uuid => $uuid_check}]; etc; }, "Used uuids" ); }; subtest apply => sub { Test2::Util::UUID->clear_cache; is( warnings { is( Test2::Plugin::UUID->apply_plugin(backends => [$backend], warn => 0), $backend, "Used correct backend", ); }, [], "No warnings", ); my $events = intercept { sub { ok(1) }->() }; my $uuid_check = validator(is_uuid => sub { looks_like_uuid($_) }); like( $events->[0], hash { field uuid => $uuid_check; field trace => {uuid => $uuid_check, huuid => $uuid_check}; field hubs => [{uuid => $uuid_check}]; etc; }, "Used uuids" ); }; subtest util => sub { $SIG{__WARN__} = sub { return if $_[0] =~ m/redefine/; die "Got warning: $_[0]"; }; Test2::Util::UUID->clear_cache; Test2::Util::UUID->import('gen_uuid', 'uuid2bin', 'bin2uuid', 'GEN_UUID_BACKEND', 'looks_like_uuid', warn => 0, backends => [$backend]); imported_ok('gen_uuid', 'GEN_UUID_BACKEND', 'looks_like_uuid'); is(GEN_UUID_BACKEND(), $backend, "Got correct backend"); ok(looks_like_uuid(gen_uuid()), "Generated a UUID"); }; subtest bin_string_convert => sub { my $subs; my $ignore = warnings { $subs = Test2::Util::UUID->get_gen_uuid(backends => [$backend]) }, my $uuid = $subs->{gen_uuid}->(); ok(looks_like_uuid($uuid), "Looks like a uuid ($uuid)"); my $bin = $subs->{uuid2bin}->($uuid); isnt($bin, $uuid, "Not the same"); is($subs->{bin2uuid}->($bin), $uuid, "Round trip!"); }; subtest fork => sub { Test2::Require::RealFork->import(); Test2::Require::Module->import('Atomic::Pipe'); Test2::Util::UUID->clear_cache; my $subs; like( warnings { $subs = Test2::Util::UUID->get_gen_uuid(backends => [$backend]) }, $warn, "Got expected warnings" ); is($subs->{GEN_UUID_BACKEND}->(), $backend, "Used correct backend"); my $gen_uuid = $subs->{gen_uuid}; my ($r, $w) = Atomic::Pipe->pair; my @uuids; push @uuids => $gen_uuid->() for 1 .. 5; my @pids; for (1 .. 4) { my $pid = fork // die "Could not fork: $!"; if ($pid) { push @pids => $pid; next; } $w->write_message($gen_uuid->()) for 1 .. 10; exit 0; } push @uuids => $gen_uuid->() for 1 .. 5; waitpid($_, 0) for @pids; $w->close; while (my $new_uuid = $r->read_message) { push @uuids => $new_uuid; } $r->close; is(@uuids, 50, "Got 50 uuids"); my %seen; $seen{$_}++ for @uuids; ok(!(grep { $_ > 1 } values %seen), "Did not generate any duplicate UUIDs"); }; }; } done_testing; cpanfile100644001750001750 163014772043642 17054 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010# This file is generated by Dist::Zilla::Plugin::CPANFile v6.032 # Do not edit this file directly. To change prereqs, edit the `dist.ini` file. requires "Test2::API" => "1.302165"; requires "UUID::Tiny" => "1.04"; requires "perl" => "5.010000"; recommends "Data::UUID" => "1.227"; recommends "Data::UUID::MT" => "1.001"; recommends "UUID" => "0.35"; suggests "Data::UUID" => "1.227"; suggests "Data::UUID::MT" => "1.001"; suggests "UUID" => "0.35"; on 'test' => sub { requires "Test2::Require::Module" => "0.000162"; requires "Test2::Util::Table" => "0.000162"; requires "Test2::V0" => "0.000162"; }; on 'configure' => sub { requires "ExtUtils::MakeMaker" => "0"; }; on 'develop' => sub { requires "Atomic::Pipe" => "0.022"; requires "Data::UUID" => "1.227"; requires "Data::UUID::MT" => "1.001"; requires "Test::Pod" => "1.41"; requires "Test::Spelling" => "0.12"; requires "UUID" => "0.35"; }; META.yml100644001750001750 162714772043642 16627 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010--- abstract: 'Use REAL UUIDs in Test2' author: - 'Chad Granum ' build_requires: Test2::Require::Module: '0.000162' Test2::Util::Table: '0.000162' Test2::V0: '0.000162' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.032, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test2-Plugin-UUID recommends: Data::UUID: '1.227' Data::UUID::MT: '1.001' UUID: '0.35' requires: Test2::API: '1.302165' UUID::Tiny: '1.04' perl: '5.010000' resources: bugtracker: http://github.com/Test-More/Test2-Plugin-UUID/issues repository: http://github.com/Test-More/Test2-Plugin-UUID/ version: '0.002010' x_generated_by_perl: v5.40.1 x_serialization_backend: 'YAML::Tiny version 1.76' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' META.json100644001750001750 362014772043642 16772 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010{ "abstract" : "Use REAL UUIDs in Test2", "author" : [ "Chad Granum " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.032, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Test2-Plugin-UUID", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Atomic::Pipe" : "0.022", "Data::UUID" : "1.227", "Data::UUID::MT" : "1.001", "Test::Pod" : "1.41", "Test::Spelling" : "0.12", "UUID" : "0.35" } }, "runtime" : { "recommends" : { "Data::UUID" : "1.227", "Data::UUID::MT" : "1.001", "UUID" : "0.35" }, "requires" : { "Test2::API" : "1.302165", "UUID::Tiny" : "1.04", "perl" : "5.010000" }, "suggests" : { "Data::UUID" : "1.227", "Data::UUID::MT" : "1.001", "UUID" : "0.35" } }, "test" : { "requires" : { "Test2::Require::Module" : "0.000162", "Test2::Util::Table" : "0.000162", "Test2::V0" : "0.000162" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "http://github.com/Test-More/Test2-Plugin-UUID/issues" }, "repository" : { "type" : "git", "url" : "http://github.com/Test-More/Test2-Plugin-UUID/" } }, "version" : "0.002010", "x_generated_by_perl" : "v5.40.1", "x_serialization_backend" : "Cpanel::JSON::XS version 4.39", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" } README.md100644001750001750 575514772043642 16643 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010# NAME Test2::Plugin::UUID - Use REAL UUIDs in Test2 # DESCRIPTION Test2 normally uses unique IDs generated by appending pid, thread-id, and an incrementing integer. These work fine most of the time, but are not sufficient if you want to keep a database of events, in that case a real UUID is much more useful. # SYNOPSIS use Test2::Plugin::UUID; This is also useful at the command line for 1-time use: $ perl -MTest2::Plugin::UUID path/to/test.t # CONTROLLING WARNINGS AND BACKENDS You can turn off backend warnings, and choose your own backend order preference: use Test2::Plugin::UUID warn => 0, backends => ['UUID', ...]; Or at the command line: perl -MTest2::Plugin::UUID=warn,0 path/to/test.t Or via env vars: TEST2_UUID_BACKEND="UUID,Data::UUID::MT" TEST2_UUID_WARN=0 perl path/to/test.t Normally warnings will be issued if [UUID::Tiny](https://metacpan.org/pod/UUID%3A%3ATiny) or [Data::UUID](https://metacpan.org/pod/Data%3A%3AUUID) are used as the first is slow and the second is not suitible for database keys. # BACKENDS One of the following modules will be used under the hood, they are listed here in order of preference. - [UUID](https://metacpan.org/pod/UUID) >= 0.35 When possible this module will use the [UUID](https://metacpan.org/pod/UUID) cpan module, but it must be version 0.35 or greater to avoid a fork related bug. It will generate version 7 UUIDs as they are most suitible for database entry. - [Data::UUID::MT](https://metacpan.org/pod/Data%3A%3AUUID%3A%3AMT) [Data::UUID::MT](https://metacpan.org/pod/Data%3A%3AUUID%3A%3AMT) is the second choice for UUID generation. With this module version 4 UUIDs are generated as they are fairly usable in databases. - [UUID::Tiny](https://metacpan.org/pod/UUID%3A%3ATiny) - slow [UUID::Tiny](https://metacpan.org/pod/UUID%3A%3ATiny) is used if the previous 2 are not available. This module is pure perl and thus could be slower than the others. Version 4 UUIDs are generated when this module is used. A warning will be issued with this module. You can surpress the warning with either the `$TEST2_UUID_NO_WARN` environment variable or the `warn => 0` import argument. - [Data::UUID](https://metacpan.org/pod/Data%3A%3AUUID) - Not Suitible for Databases This is the last resort module. This generates UUIDs fast, but they are of a type/version that is not suitible for database keys. A warning will be issued with this module. You can surpress the warning with either the `$TEST2_UUID_NO_WARN` environment variable or the `warn => 0` import argument. # SOURCE The source code repository for Test2-Plugin-UUID can be found at `https://github.com/Test-More/Test2-Plugin-UUID/`. # MAINTAINERS - Chad Granum # AUTHORS - Chad Granum # COPYRIGHT Copyright Chad Granum . 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/` Makefile.PL100644001750001750 241714772043642 17326 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.032. use strict; use warnings; use 5.010000; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Use REAL UUIDs in Test2", "AUTHOR" => "Chad Granum ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Test2-Plugin-UUID", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.010000", "NAME" => "Test2::Plugin::UUID", "PREREQ_PM" => { "Test2::API" => "1.302165", "UUID::Tiny" => "1.04" }, "TEST_REQUIRES" => { "Test2::Require::Module" => "0.000162", "Test2::Util::Table" => "0.000162", "Test2::V0" => "0.000162" }, "VERSION" => "0.002010", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Test2::API" => "1.302165", "Test2::Require::Module" => "0.000162", "Test2::Util::Table" => "0.000162", "Test2::V0" => "0.000162", "UUID::Tiny" => "1.04" ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); 00-report.t100600001750001750 145614772043642 17526 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010/tuse Test2::Tools::Basic; use Test2::Util::Table qw/table/; use strict; use warnings; use IPC::Cmd qw/can_run/; # Nothing in the tables in this file should result in a table wider than 80 # characters, so this is an optimization. BEGIN { $ENV{TABLE_TERM_SIZE} = 80 } diag "\nDIAGNOSTICS INFO IN CASE OF FAILURE:\n"; diag(join "\n", table(rows => [[ 'perl', $] ]])); print STDERR "\n"; { my @mods = qw{ Atomic::Pipe Data::UUID Data::UUID::MT Test2::API Test2::V0 UUID UUID::Tiny }; my @rows; for my $mod (sort @mods) { my $installed = eval "require $mod; $mod->VERSION"; push @rows => [$mod, $installed || "N/A"]; } my @table = table( header => ['MODULE', 'VERSION'], rows => \@rows, ); diag(join "\n", @table); } pass('pass'); done_testing; Util000755001750001750 014772043642 17674 5ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010/lib/Test2UUID.pm100644001750001750 2023014772043642 21155 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010/lib/Test2/Utilpackage Test2::Util::UUID; use strict; use warnings; our $VERSION = '0.002010'; use Carp qw/croak/; my %EXPORT = ( looks_like_uuid => 1, gen_uuid => 1, GEN_UUID_BACKEND => 1, uuid2bin => 1, bin2uuid => 1, ); sub import { my $class = shift; my $caller = caller; my %gen_params; my %import; while (my $arg = shift @_) { if ($EXPORT{$arg}) { $import{$arg}++; next; } if ($arg eq 'warn' || $arg eq 'backends') { $gen_params{$arg} = shift @_; next; } croak "Invalid argument '$arg'"; } my $subs = $class->get_gen_uuid(%gen_params); for my $name (keys %import) { my $sub = $subs->{$name} || $class->can($name) or croak "'$name' is not available for import"; no strict 'refs'; *{"$caller\::$name"} = $sub; } return; } my %GEN_UUID_CACHE; sub clear_cache { %GEN_UUID_CACHE = () } sub get_gen_uuid { my $class = shift; my %params = @_; my $warn = $params{warn} // ($ENV{TEST2_UUID_NO_WARN} ? 0 : 1); my $backends = $params{backends} // ($ENV{TEST2_UUID_BACKEND} ? [split /\s*,\s*/, $ENV{TEST2_UUID_BACKEND}] : ['UUID', 'Data::UUID::MT', 'UUID::Tiny', 'Data::UUID']); for my $backend (@$backends) { return $GEN_UUID_CACHE{$backend} if $GEN_UUID_CACHE{$backend}; my $meth = lc("_gen_$backend"); $meth =~ s/::/_/g; croak "'$backend' is not supported" unless $class->can($meth); $GEN_UUID_CACHE{$backend} = $class->$meth($warn) or next; $GEN_UUID_CACHE{$backend}->{GEN_UUID_BACKEND} = sub() { $backend }; return $GEN_UUID_CACHE{$backend}; } croak "No UUID generator found, please install one of these: UUID, Data::UUID::MT, Data::UUID, or UUID::Tiny. ('UUID' is preferred over the others)\n"; } sub _gen_uuid { my $class = shift; my ($warn) = @_; local $@; return undef unless eval { require UUID; 1 }; unless (eval { UUID->VERSION('0.35'); 1 }) { warn "UUID version is too old, need 0.35 or greater to avoid a fork related bug. Please upgrade the UUID module.\n" if $warn; return; } return { gen_uuid => sub { uc(UUID::uuid7->()) }, bin2uuid => sub { my $out; UUID::unparse($_[0], $out); uc($out) }, uuid2bin => sub { my $out; UUID::parse($_[0], $out); $out }, }; } sub _gen_data_uuid_mt { my $class = shift; my ($warn) = @_; local $@; return undef unless eval { require Data::UUID::MT; 1 }; my $ug = Data::UUID::MT->new(version => 4); my $out = { gen_uuid => sub { uc($ug->create_string()) }, }; if (eval { require UUID::Tiny; 1 }) { $out->{uuid2bin} = sub { UUID::Tiny::string_to_uuid($_[0]) }, $out->{bin2uuid} = sub { uc(UUID::Tiny::uuid_to_string($_[0])) }, } return $out; } sub _gen_uuid_tiny { my $class = shift; my ($warn) = @_; local $@; return undef unless eval { require UUID::Tiny; 1 }; warn "Using UUID::Tiny for uuid generation. UUID::Tiny is significantly slower than the 'UUID' or 'Data::UUID::MT' modules, please install 'UUID' or 'Data::UUID::MT' if possible. If you insist on using UUID::Tiny you can set the TEST2_UUID_NO_WARN environment variable.\n" if $warn; return { gen_uuid => sub { uc(UUID::Tiny::create_uuid_as_string(UUID::Tiny::UUID_V4())) }, bin2uuid => sub { uc(UUID::Tiny::uuid_to_string($_[0])) }, uuid2bin => sub { UUID::Tiny::string_to_uuid($_[0]) }, }; } sub _gen_data_uuid { my $class = shift; my ($warn) = @_; local $@; return undef unless eval { require Data::UUID; 1 }; warn "Using Data::UUID to generate UUIDs, this works, but the UUIDs will not be suitible as database keys. Please install the 'UUID', 'Data::UUID::MT' or the slower but pure perl 'UUID::Tiny' cpan modules for better UUIDs. If you insist on using Data::UUID you can set the TEST2_UUID_NO_WARN environment variable.\n" if $warn; my ($UG, $UG_PID); my $UG_INIT = sub { return $UG if $UG && $UG_PID && $UG_PID == $$; $UG_PID = $$; return $UG = Data::UUID->new; }; # Initialize it here in this PID to start $UG_INIT->(); return { gen_uuid => sub { uc($UG_INIT->()->create_str()) }, bin2uuid => sub { uc($UG_INIT->()->to_string($_[0])) }, uuid2bin => sub { $UG_INIT->()->from_string($_[0]) }, }; } sub looks_like_uuid { my ($in) = @_; return $in if $in && $in =~ m/^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$/i; return undef; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Test2::Util::UUID - Utils for generating UUIDs under Test2. =head1 DESCRIPTION This module provides a consistent UUID source for all of Test2. =head1 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); =head1 UNDER THE HOOD One of the following modules will be used under the hood, they are listed here in order of preference. =over 4 =item L >= 0.35 When possible this module will use the L cpan module, but it must be version 0.35 or greater to avoid a fork related bug. It will generate version 7 UUIDs as they are most suitible for database entry. =item L L is the second choice for UUID generation. With this module version 4 UUIDs are generated as they are fairly usable in databases. =item L - slow L is used if the previous 2 are not available. This module is pure perl and thus could be slower than the others. Version 4 UUIDs are generated when this module is used. A warning will be issued with this module. You can surpress the warning with either the C<$TEST2_UUID_NO_WARN> environment variable or the C<< warn => 0 >> import argument. =item L - Not Suitible for Databases This is the last resort module. This generates UUIDs fast, but they are of a type/version that is not suitible for database keys. A warning will be issued with this module. You can surpress the warning with either the C<$TEST2_UUID_NO_WARN> environment variable or the C<< warn => 0 >> import argument. =back =head2 CONTROLLING WARNINGS =head3 AT IMPORT use Test2::Util::UUID 'gen_uuid', warn => 0; Passing in C<< warn => 0 >> will disable the warnings normally issued when using L or L as a backend. =head2 SELECTING A BACKEND =head3 AT IMPORT If you wish to override the order and specify which backend to use you may do so by listing them during import prefixed with ':'. use Test2::Util::UUID 'gen_uuid', backends => [':UUID', ':UUID::Tiny']; The above will try the L module first, followed by the L module. It will not try L or L. B You must include these import arguments anywhere you import this module, otherwise the other imports will use the default list, resulting in different places using different UUIDs. =head3 THE $TEST2_UUID_BACKEND ENV VAR Setting the $TEST2_UUID_BACKEND env var to one of the backends, or a comma seperated list will override the default list for all imports. It will B override imports that specify their own lists. =head1 EXPORTS =over 4 =item $uuid = gen_uuid() Generate a UUID, always normalized to upper case. =item $uuid_or_undef = looks_like_uuid($UUID) Checks if the provided value looks like a UUID. Make 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, otherise it returns undef. =back =head1 SOURCE The source code repository for Test2-Plugin-UUID can be found at F. =head1 MAINTAINERS =over 4 =item Chad Granum Eexodist@cpan.orgE =back =head1 AUTHORS =over 4 =item Chad Granum Eexodist@cpan.orgE =back =head1 COPYRIGHT Copyright Chad Granum Eexodist@cpan.orgE. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See F =cut author000755001750001750 014772043642 17145 5ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010/xtpod-syntax.t100644001750001750 25214772043642 21557 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Plugin000755001750001750 014772043642 20215 5ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010/lib/Test2UUID.pm100644001750001750 643214772043642 21466 0ustar00exodistexodist000000000000Test2-Plugin-UUID-0.002010/lib/Test2/Pluginpackage Test2::Plugin::UUID; use strict; use warnings; our $VERSION = '0.002010'; use Carp qw/croak/; use Test2::API qw/test2_add_uuid_via/; require Test2::Util::UUID; sub import { my $class = shift; $class->apply_plugin(@_); return; } sub apply_plugin { my $class = shift; my $subs = Test2::Util::UUID->get_gen_uuid(@_); test2_add_uuid_via($subs->{gen_uuid}); require Test2::Hub; Test2::Hub->new; # Make sure the UUID generator is found return $subs->{GEN_UUID_BACKEND}->(); } 1; __END__ =pod =encoding UTF-8 =head1 NAME Test2::Plugin::UUID - Use REAL UUIDs in Test2 =head1 DESCRIPTION Test2 normally uses unique IDs generated by appending pid, thread-id, and an incrementing integer. These work fine most of the time, but are not sufficient if you want to keep a database of events, in that case a real UUID is much more useful. =head1 SYNOPSIS use Test2::Plugin::UUID; This is also useful at the command line for 1-time use: $ perl -MTest2::Plugin::UUID path/to/test.t =head1 CONTROLLING WARNINGS AND BACKENDS You can turn off backend warnings, and choose your own backend order preference: use Test2::Plugin::UUID warn => 0, backends => ['UUID', ...]; Or at the command line: perl -MTest2::Plugin::UUID=warn,0 path/to/test.t Or via env vars: TEST2_UUID_BACKEND="UUID,Data::UUID::MT" TEST2_UUID_WARN=0 perl path/to/test.t Normally warnings will be issued if L or L are used as the first is slow and the second is not suitible for database keys. =head1 BACKENDS One of the following modules will be used under the hood, they are listed here in order of preference. =over 4 =item L >= 0.35 When possible this module will use the L cpan module, but it must be version 0.35 or greater to avoid a fork related bug. It will generate version 7 UUIDs as they are most suitible for database entry. =item L L is the second choice for UUID generation. With this module version 4 UUIDs are generated as they are fairly usable in databases. =item L - slow L is used if the previous 2 are not available. This module is pure perl and thus could be slower than the others. Version 4 UUIDs are generated when this module is used. A warning will be issued with this module. You can surpress the warning with either the C<$TEST2_UUID_NO_WARN> environment variable or the C<< warn => 0 >> import argument. =item L - Not Suitible for Databases This is the last resort module. This generates UUIDs fast, but they are of a type/version that is not suitible for database keys. A warning will be issued with this module. You can surpress the warning with either the C<$TEST2_UUID_NO_WARN> environment variable or the C<< warn => 0 >> import argument. =back =head1 SOURCE The source code repository for Test2-Plugin-UUID can be found at F. =head1 MAINTAINERS =over 4 =item Chad Granum Eexodist@cpan.orgE =back =head1 AUTHORS =over 4 =item Chad Granum Eexodist@cpan.orgE =back =head1 COPYRIGHT Copyright Chad Granum Eexodist@cpan.orgE. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See F =cut