Blame UUID.pm

Packit Service 7500fa
package Data::UUID;
Packit Service 7500fa
Packit Service 7500fa
use strict;
Packit Service 7500fa
Packit Service 7500fa
use Carp;
Packit Service 7500fa
Packit Service 7500fa
require Exporter;
Packit Service 7500fa
require DynaLoader;
Packit Service 7500fa
require Digest::MD5;
Packit Service 7500fa
Packit Service 7500fa
our @ISA = qw(Exporter DynaLoader);
Packit Service 7500fa
our @EXPORT = qw(
Packit Service 7500fa
   NameSpace_DNS
Packit Service 7500fa
   NameSpace_OID
Packit Service 7500fa
   NameSpace_URL
Packit Service 7500fa
   NameSpace_X500
Packit Service 7500fa
);
Packit Service 7500fa
our $VERSION = '1.221';
Packit Service 7500fa
Packit Service 7500fa
bootstrap Data::UUID $VERSION;
Packit Service 7500fa
Packit Service 7500fa
1;
Packit Service 7500fa
__END__
Packit Service 7500fa
Packit Service 7500fa
=head1 NAME
Packit Service 7500fa
Packit Service 7500fa
Data::UUID - Globally/Universally Unique Identifiers (GUIDs/UUIDs)
Packit Service 7500fa
Packit Service 7500fa
=head1 SEE INSTEAD?
Packit Service 7500fa
Packit Service 7500fa
The module L<Data::GUID> provides another interface for generating GUIDs.
Packit Service 7500fa
Right now, it relies on Data::UUID, but it may not in the future.  Its
Packit Service 7500fa
interface may be just a little more straightforward for the average Perl
Packit Service 7500fa
programer.
Packit Service 7500fa
Packit Service 7500fa
=head1 SYNOPSIS
Packit Service 7500fa
Packit Service 7500fa
  use Data::UUID;
Packit Service 7500fa
  
Packit Service 7500fa
  $ug    = Data::UUID->new;
Packit Service 7500fa
  $uuid1 = $ug->create();
Packit Service 7500fa
  $uuid2 = $ug->create_from_name(<namespace>, <name>);
Packit Service 7500fa
Packit Service 7500fa
  $res   = $ug->compare($uuid1, $uuid2);
Packit Service 7500fa
Packit Service 7500fa
  $str   = $ug->to_string( $uuid );
Packit Service 7500fa
  $uuid  = $ug->from_string( $str );
Packit Service 7500fa
Packit Service 7500fa
=head1 DESCRIPTION
Packit Service 7500fa
Packit Service 7500fa
This module provides a framework for generating v3 UUIDs (Universally Unique
Packit Service 7500fa
Identifiers, also known as GUIDs (Globally Unique Identifiers). A UUID is 128
Packit Service 7500fa
bits long, and is guaranteed to be different from all other UUIDs/GUIDs
Packit Service 7500fa
generated until 3400 CE.
Packit Service 7500fa
Packit Service 7500fa
UUIDs were originally used in the Network Computing System (NCS) and later in
Packit Service 7500fa
the Open Software Foundation's (OSF) Distributed Computing Environment.
Packit Service 7500fa
Currently many different technologies rely on UUIDs to provide unique identity
Packit Service 7500fa
for various software components. Microsoft COM/DCOM for instance, uses GUIDs
Packit Service 7500fa
very extensively to uniquely identify classes, applications and components
Packit Service 7500fa
across network-connected systems.
Packit Service 7500fa
Packit Service 7500fa
The algorithm for UUID generation, used by this extension, is described in the
Packit Service 7500fa
Internet Draft "UUIDs and GUIDs" by Paul J. Leach and Rich Salz.  (See RFC
Packit Service 7500fa
4122.)  It provides reasonably efficient and reliable framework for generating
Packit Service 7500fa
UUIDs and supports fairly high allocation rates -- 10 million per second per
Packit Service 7500fa
machine -- and therefore is suitable for identifying both extremely short-lived
Packit Service 7500fa
and very persistent objects on a given system as well as across the network.
Packit Service 7500fa
Packit Service 7500fa
This modules provides several methods to create a UUID.  In all methods, C<<
Packit Service 7500fa
<namespace> >> is a UUID and C<< <name> >> is a free form string.
Packit Service 7500fa
 
Packit Service 7500fa
   # creates binary (16 byte long binary value) UUID.
Packit Service 7500fa
   $ug->create();
Packit Service 7500fa
   $ug->create_bin();
Packit Service 7500fa
Packit Service 7500fa
   # creates binary (16-byte long binary value) UUID based on particular
Packit Service 7500fa
   # namespace and name string.
Packit Service 7500fa
   $ug->create_from_name(<namespace>, <name>);
Packit Service 7500fa
   $ug->create_from_name_bin(<namespace>, <name>);
Packit Service 7500fa
Packit Service 7500fa
   # creates UUID string, using conventional UUID string format,
Packit Service 7500fa
   # such as: 4162F712-1DD2-11B2-B17E-C09EFE1DC403
Packit Service 7500fa
   # Note that digits A-F are capitalized, which is contrary to rfc4122
Packit Service 7500fa
   $ug->create_str();
Packit Service 7500fa
   $ug->create_from_name_str(<namespace>, <name>);
Packit Service 7500fa
Packit Service 7500fa
   # creates UUID string as a hex string,
Packit Service 7500fa
   # such as: 0x4162F7121DD211B2B17EC09EFE1DC403
Packit Service 7500fa
   # Note that digits A-F are capitalized, which is contrary to rfc4122
Packit Service 7500fa
   $ug->create_hex();
Packit Service 7500fa
   $ug->create_from_name_hex(<namespace>, <name>);
Packit Service 7500fa
Packit Service 7500fa
   # creates UUID string as a Base64-encoded string
Packit Service 7500fa
   $ug->create_b64();
Packit Service 7500fa
   $ug->create_from_name_b64(<namespace>, <name>);
Packit Service 7500fa
Packit Service 7500fa
   Binary UUIDs can be converted to printable strings using following methods:
Packit Service 7500fa
Packit Service 7500fa
   # convert to conventional string representation
Packit Service 7500fa
   $ug->to_string(<uuid>);
Packit Service 7500fa
Packit Service 7500fa
   # convert to hex string (using upper, rather than lower, case letters)
Packit Service 7500fa
   $ug->to_hexstring(<uuid>);
Packit Service 7500fa
Packit Service 7500fa
   # convert to Base64-encoded string
Packit Service 7500fa
   $ug->to_b64string(<uuid>);
Packit Service 7500fa
Packit Service 7500fa
   Conversly, string UUIDs can be converted back to binary form:
Packit Service 7500fa
Packit Service 7500fa
   # recreate binary UUID from string
Packit Service 7500fa
   $ug->from_string(<uuid>);
Packit Service 7500fa
   $ug->from_hexstring(<uuid>);
Packit Service 7500fa
Packit Service 7500fa
   # recreate binary UUID from Base64-encoded string
Packit Service 7500fa
   $ug->from_b64string(<uuid>);
Packit Service 7500fa
Packit Service 7500fa
   Finally, two binary UUIDs can be compared using the following method:
Packit Service 7500fa
Packit Service 7500fa
   # returns -1, 0 or 1 depending on whether uuid1 less
Packit Service 7500fa
   # than, equals to, or greater than uuid2
Packit Service 7500fa
   $ug->compare(<uuid1>, <uuid2>);
Packit Service 7500fa
Packit Service 7500fa
Examples:
Packit Service 7500fa
Packit Service 7500fa
   use Data::UUID;
Packit Service 7500fa
Packit Service 7500fa
   # this creates a new UUID in string form, based on the standard namespace
Packit Service 7500fa
   # UUID NameSpace_URL and name "www.mycompany.com"
Packit Service 7500fa
Packit Service 7500fa
   $ug = Data::UUID->new;
Packit Service 7500fa
   print $ug->create_from_name_str(NameSpace_URL, "www.mycompany.com");
Packit Service 7500fa
Packit Service 7500fa
=head2 EXPORT
Packit Service 7500fa
Packit Service 7500fa
The module allows exporting of several standard namespace UUIDs:
Packit Service 7500fa
Packit Service 7500fa
=over
Packit Service 7500fa
Packit Service 7500fa
=item NameSpace_DNS
Packit Service 7500fa
Packit Service 7500fa
=item NameSpace_URL
Packit Service 7500fa
Packit Service 7500fa
=item NameSpace_OID
Packit Service 7500fa
Packit Service 7500fa
=item NameSpace_X500
Packit Service 7500fa
Packit Service 7500fa
=back
Packit Service 7500fa
 
Packit Service 7500fa
=head1 AUTHOR
Packit Service 7500fa
Packit Service 7500fa
Alexander Golomshtok <agolomsh@cpan.org>
Packit Service 7500fa
Packit Service 7500fa
=head1 SEE ALSO
Packit Service 7500fa
Packit Service 7500fa
The Internet Draft "UUIDs and GUIDs" by Paul J. Leach and Rich Salz (RFC 4122)
Packit Service 7500fa
Packit Service 7500fa
=cut