package MooseX::Types::UUID;
use strict;
use warnings;

our $VERSION = '0.03';

use MooseX::Types -declare => ['UUID'];
use MooseX::Types::Moose qw(Str);

sub _validate_uuid {
    my ($str) = @_;
    return $str =~ /^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$/;

subtype UUID,
  as Str, where { _validate_uuid($_) };

coerce UUID,
  # i've never seen lowercase UUIDs, but someone's bound to try it
  from Str, via { uc };



=head1 NAME

MooseX::Types::UUID - UUID type for Moose classes


  package Class;
  use Moose;
  use MooseX::Types::UUID qw(UUID);

  has 'uuid' => ( is => 'ro', isa => UUID );

  package main;
  Class->new( uuid => '77C71F92-0EC7-11DD-B986-DF138EE79F6F' );


This module lets you constrain attributes to only contain UUIDs (in
their usual human-readable form).  No coercion is attempted.

=head1 EXPORT

None by default, you'll usually want to request C<UUID> explicitly.

=head1 AUTHOR

Jonathan Rockway C<< <> >>

Infinity Interactive (L<>)


This program is Free software, you may redistribute it under the same
terms as Perl itself.