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

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

0.02 of URI::urn::uuid. Added docs/tests

Line 
1 package URI::urn::uuid;
2
3 use strict;
4 our $VERSION = '0.02';
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   $uri = URI->new("urn:uuid:");
41   $uri->uuid( lc Data::UUID->new->create_str );
42
43 =head1 DESCRIPTION
44
45 URI::urn::uuid is an URI class that implement UUID URN namespace.
46
47 =head1 METHODS
48
49 =over 4
50
51 =item uuid
52
53   $uuid = $uri->uuid;
54   $old  = $uri->uuid($new);
55
56 Returns UUID string as a canonicalized, lowercase form. If the given
57 UUID format is invalid, it just returns undef.
58
59 =item uuid_binary
60
61   $uuid_binary = $uri->uuid_binary;
62
63 Returns UUID as a 128 bit binary. Returns undef if the given UUID
64 format is invalid.
65
66 =back
67
68 =head1 AUTHOR
69
70 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
71
72 =head1 LICENSE
73
74 This library is free software; you can redistribute it and/or modify
75 it under the same terms as Perl itself.
76
77 =head1 SEE ALSO
78
79 L<http://www.ietf.org/rfc/rfc4122.txt>, L<Data::UUID>
80
81 =cut
Note: See TracBrowser for help on using the browser.