Data::GUID(3pm)
β¨ Data::GUID β¨
okay bestie, pull up a chair π«Ά this is Data::GUID, straight out of the User Contributed Perl Documentation, and it is exactly what it sounds like: globally unique identifiers and all the little ways to make them, read them, and compare them. it's giving utility. it's giving lowercase-perl-module excellence. let's go π
πΈ VERSION πΈ
version 0.051 β yes queen, we're on the current one β¨
π SYNOPSIS π
like, here's the whole vibe in one go:
use Data::GUID;
my $guid = Data::GUID->new;
my $string = $guid->as_string; # or "$guid"
my $other_guid = Data::GUID->from_string($string);
if (($guid <=> $other_guid) == 0) {
print "They're the same!\n";
}
look at that. make one, stringify it, parse it back, compare it. iconic behaviour, no notes π₯
π DESCRIPTION π
Data::GUID gives you a simple interface for generating and using globally unique identifiers. that's the whole pitch. it's not trying to be mysterious, it's just here to hand you GUIDs and take them apart again π¦
π§ PERL VERSION π§
bestie this thing is old-perl-friendly. it should run on perls released even an extremely long time ago, and it should work on any version of perl released in the last ten years π
that said β and listen, this part matters β even though it may work on older versions of perl, there's no guarantee that the minimum required version won't be raised. the version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl. so like, don't come for them with a downgrade PR, they said what they said π
π GETTING A NEW GUID π
new
my $guid = Data::GUID->new;
this method returns a new globally unique identifier. fresh out the oven, never been worn, brand new π
π GUIDS FROM EXISTING VALUES π
these methods return a new Data::GUID object for the given GUID value. and in all cases β every single one β these methods throw an exception if given invalid input. no silent nonsense, no vibes-based parsing. it will simply tell you π
from_string
my $guid = Data::GUID->from_string("B0470602-A64B-11DA-8632-93EBF1C0E05A");
from_hex
# note that a hex guid is a guid string without hyphens and with a leading 0x
my $guid = Data::GUID->from_hex("0xB0470602A64B11DA863293EBF1C0E05A");
from_base64
my $guid = Data::GUID->from_base64("sEcGAqZLEdqGMpPr8cDgWg==");
from_data_uuid
this method returns a new Data::GUID object if given a Data::UUID value. but β and this is the fine print β because Data::UUID values are not blessed, and because Data::UUID provides no validation method, this method will only throw an exception if the given data is of the wrong size. that's it. that's the only check it can do. anything size-correct sails right through π
π¦ IDENTIFYING GUIDS π¦
string_guid_regex
hex_guid_regex
base64_guid_regex
these methods return regex objects that match regex strings of the appropriate type. three flavours, three regexes, matching the three string shapes. iykyk β
from_any_string
my $string = get_string_from_ether;
my $guid = Data::GUID->from_any_string($string);
this method returns a Data::GUID object for the given string, trying all known string interpretations. and if the value is not a valid GUID string? exception. thrown. periodt π
best_guess
my $value = get_value_from_ether;
my $guid = Data::GUID->best_guess($value);
this method returns a Data::GUID object for the given value, trying everything it can. it works like from_any_string, but it will also accept Data::UUID values. (in effect, this means that any sixteen byte value is acceptable.) so yeah, it's the "sure, come in" of the family π«Ά
π GUIDS INTO STRINGS π
these methods return various string representations of a GUID. pick your fave, they're all valid β¨
as_string
this method returns a "traditional" GUID/UUID string representation. that's five hexadecimal strings, delimited by hyphens. for example:
B0470602-A64B-11DA-8632-93EBF1C0E05A
this method is also used to stringify Data::GUID objects β so interpolating "$guid" gives you this π
as_hex
this method returns a plain hexadecimal representation of the GUID, with a leading 0x. for example:
0xB0470602A64B11DA863293EBF1C0E05A
as_base64
this method returns a base-64 string representation of the GUID. for example:
sEcGAqZLEdqGMpPr8cDgWg==
π OTHER METHODS π
compare_to_guid
this method compares a GUID to another GUID and returns -1, 0, or 1, as do other comparison routines. standard comparison energy, we love to see it π
as_binary
this method returns the packed binary representation of the GUID. however β big however β at present this method relies on Data::GUID's underlying use of Data::UUID. it is not guaranteed to continue to work the same way, or at all. caveat invocator. that's latin-adjacent for "bestie, this one might break on you, don't build your whole house on it" π
π IMPORTING π
Data::GUID does not export any subroutines by default, but it does provide a few routines which will be imported on request π
these routines may be called as class methods, or may be imported to be called as subroutines. and listen β calling them by fully qualified name is incorrect. like, actually incorrect. don't do it π
use Data::GUID qw(guid);
my $guid = guid; # OK
my $guid = Data::GUID->guid; # OK
my $guid = Data::GUID::guid; # NOT OK
guid
this routine returns a new Data::GUID object.
guid_string
this returns the string representation of a new GUID.
guid_hex
this returns the hex representation of a new GUID.
guid_base64
this returns the base64 representation of a new GUID.
guid_from_anything
this returns the result of calling the from_any_string method.
π TODO π
the wishlist, the dream board, the "one day" board:
- add namespace support
- remove dependency on wretched
Data::UUID - make it work on
5.005
(they said wretched. that's their word. i'm just the messenger π)
β AUTHOR β
Ricardo SIGNES <cpan@semiotic.systems>
π¦ CONTRIBUTOR π¦
Ricardo Signes <rjbs@semiotic.systems>
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2006 by Ricardo SIGNES.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself πΈ
and that's the whole page, bestie!! this was Data::GUID, page 3pm, from perl v5.36.0, dated 2023-01-24 π go forth and make some globally unique identifiers, you absolute icon π«Άβ¨
π¦ where this page comes from
- debian bookworm: libdata-guid-perl 0.051-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdata-guid-perl 0.051-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdata-guid-perl 0.051-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-guid-perl 0.051-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms