root/URI-urn-uuid/trunk/lib/URI/urn/uuid.pm

Revision 1936 (checked in by miyagawa, 14 years ago)

import URI::urn::uuid

Line 
1 package URI::urn::uuid;
2
3 use strict;
4 our $VERSION = '0.01';
5
6 use base qw(URI::urn);
7 use Data::UUID;
8
9 sub uuid {
10     my $self = shift;
11     my $nss  = $self->nss(@_);
12
13     my $ug = Data::UUID->new;
14     my $uuid = eval { $ug->from_string($nss) } or return;
15     return lc $ug->to_string($uuid);
16 }
17
18 sub uuid_binary {
19     my $self = shift;
20     my $ug = Data::UUID->new;
21     return eval { $ug->from_string($self->nss) } || undef;
22 }
23
24 1;
25 __END__
26
27 =head1 NAME
28
29 URI::urn::uuid - UUID URN Namespace
30
31 =head1 SYNOPSIS
32
33   use URI;
34   use URI::urn::uuid;
35
36   my $uri = URI->new("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6");
37   $uri->uuid;        # f81d4fae-7dec-11d0-a765-00a0c91e6bf6
38   $uri->uuid_binary; # in 128 bit binary form of Data::UUID
39
40 =head1 DESCRIPTION
41
42 URI::urn::uuid is an URI class that implement UUID URN namespace.
43
44 =head1 METHODS
45
46 =over 4
47
48 =item uuid
49
50   $uuid = $uri->uuid;
51   $old  = $uri->uuid($new);
52
53 Returns UUID string as a canonicalized, lowercase form. If the given
54 UUID format is invalid, it just returns undef.
55
56 =item uuid_binary
57
58   $uuid_binary = $uri->uuid_binary;
59
60 Returns UUID as a 128 bit binary. Returns undef if the given UUID
61 format is invalid.
62
63 =back
64
65 =head1 AUTHOR
66
67 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
68
69 =head1 LICENSE
70
71 This library is free software; you can redistribute it and/or modify
72 it under the same terms as Perl itself.
73
74 =head1 SEE ALSO
75
76 L<http://www.ietf.org/rfc/rfc4122.txt>, L<Data::UUID>
77
78 =cut
Note: See TracBrowser for help on using the browser.