fix missing comma; rafl++
[gitmo/MooseX-Types-UUID.git] / lib / MooseX / Types / UUID.pm
CommitLineData
c2cadbcb 1package MooseX::Types::UUID;
2use strict;
3use warnings;
4
269cb952 5our $VERSION = '0.02';
f9517489 6our $AUTHORITY = 'CPAN:JROCKWAY';
7
316d7a7e 8use MooseX::Types -declare => ['UUID'];
9use MooseX::Types::Moose qw(Str);
10
11sub _validate_uuid {
12 my ($str) = @_;
13 return $str =~ /^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$/;
14}
c2cadbcb 15
316d7a7e 16subtype UUID,
17 as Str, where { _validate_uuid($_) };
c2cadbcb 18
269cb952 19coerce UUID,
316d7a7e 20 # i've never seen lowercase UUIDs, but someone's bound to try it
21 from Str, via { uc };
c2cadbcb 22
231;
316d7a7e 24
25__END__
26
27=head1 NAME
28
29MooseX::Types::UUID - UUID type for Moose classes
30
31=head1 SYNOPSIS
32
33 package Class;
34 use Moose;
35 use MooseX::Types::UUID qw(UUID);
269cb952 36
316d7a7e 37 has 'uuid' => ( is => 'ro', isa => UUID );
38
39 package main;
40 Class->new( uuid => '77C71F92-0EC7-11DD-B986-DF138EE79F6F' );
41
42=head1 DESCRIPTION
43
44This module lets you constrain attributes to only contain UUIDs (in
45their usual human-readable form). No coercion is attempted.
46
47=head1 EXPORT
48
49None by default, you'll usually want to request C<UUID> explicitly.
50
51=head1 AUTHOR
52
53Jonathan Rockway C<< <jrockway@cpan.org> >>
54
55Infinity Interactive (L<http://www.iinteractive.com/>)
56
57=head1 COPYRIGHT
58
59This program is Free software, you may redistribute it under the same
60terms as Perl itself.