#!/usr/bin/perl
use strict;
use warnings;
use Data::UUID;
use UUID::Tiny;
sub v3_data_uuid {
my $namespace = shift;
my $name = shift;
my $ug = shift;
$ug = new Data::UUID unless defined $ug;
return lc($ug->create_from_name_str($namespace, $name));
}
sub v3_uuid_tiny {
my $namespace = shift;
my $name = shift;
return UUID_to_string(create_UUID(UUID_V3, $namespace, $name));
}
# Generate a v3 UUID using Data::UUID
print "Data::UUID\n";
my $ug = new Data::UUID;
print ' 1. ', lc($ug->create_from_name_str(UUID_NS_DNS, 'abc')), "\n";
print ' 2. ', lc($ug->create_from_name_str(UUID_NS_DNS, 'abc')), "\n";
print ' 3. ', v3_data_uuid(UUID_NS_DNS, 'abc'), "\n";
print ' 4. ', v3_data_uuid(UUID_NS_DNS, 'abc'), "\n";
print ' 5. ', v3_data_uuid(UUID_NS_DNS, 'abc', $ug), "\n";
# Generate a v3 UUID using UUID::Tiny
print "UUID::Tiny\n";
print ' 1. ', UUID_to_string(create_UUID(UUID_V3, UUID_NS_DNS, 'abc')), "\n";
print ' 2. ', UUID_to_string(create_UUID(UUID_V3, UUID_NS_DNS, 'abc')), "\n";
print ' 3. ', v3_uuid_tiny(UUID_NS_DNS, 'abc'), "\n";
print ' 4. ', v3_uuid_tiny(UUID_NS_DNS, 'abc'), "\n";
# Generate a v3 UUID using Data::UUID with an invalid namespace
print "Data::UUID - bad namespace\n";
my $namespace = 'namespace';
print ' 1. ', lc($ug->create_from_name_str($namespace, 'abc')), "\n";
print ' 2. ', lc($ug->create_from_name_str($namespace, 'abc')), "\n";
print ' 3. ', v3_data_uuid($namespace, 'abc'), "\n";
print ' 4. ', v3_data_uuid($namespace, 'abc'), "\n";
print ' 5. ', v3_data_uuid($namespace, 'abc', $ug), "\n";
# Generate a v3 UUID using UUID::Tiny with an invalid namespace
print "UUID::Tiny - bad namespace\n";
print ' 1. ', UUID_to_string(create_UUID(UUID_V3, $namespace, 'abc')), "\n";
No comments:
Post a Comment