From: Christopher H. Laco Date: Mon, 23 Jun 2008 03:12:45 +0000 (+0000) Subject: Added UUID::Random support. X-Git-Tag: v0.02005^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7c374301bb0b8e051d2417eb78dff4c9ce44afd7;p=dbsrgits%2FDBIx-Class-UUIDColumns.git Added UUID::Random support. --- diff --git a/Changes b/Changes index a7e34b8..2107164 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for DBIx::Class::UUIDColumns +0.02005 Sun June 22 23:10:23 2008 + - Added support for UUID::Random - Moritz Onken + 0.02004 Mon Apr 22 20:41:23 2008 - Fix test failure under SQL::Translator <= 0.07 - Removed Build.PL now that Module::Install no longer supports it diff --git a/Makefile.PL b/Makefile.PL index c353ac5..fa7c994 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -16,7 +16,8 @@ if ( !eval 'require UUID' && !eval 'require Win32::Guidgen' && !eval 'require Win32API::GUID' && - !eval 'require Data::Uniqid' + !eval 'require Data::Uniqid' && + !eval 'require UUID::Random' ) { requires 'Data::UUID'; }; @@ -30,6 +31,7 @@ recommends 'APR::UUID'; recommends 'UUID'; recommends 'Win32::Guidgen'; recommends 'Win32API::GUID'; +recommends 'UUID::Random'; tests 't/*.t'; clean_files "DBIx-Class-UUIDColumns-* t/var"; diff --git a/lib/DBIx/Class/UUIDColumns.pm b/lib/DBIx/Class/UUIDColumns.pm index 768ab15..487f946 100644 --- a/lib/DBIx/Class/UUIDColumns.pm +++ b/lib/DBIx/Class/UUIDColumns.pm @@ -14,7 +14,7 @@ __PACKAGE__->uuid_class(__PACKAGE__->_find_uuid_module); # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports # brain damage and presumably various other packaging systems too -$VERSION = '0.02004'; +$VERSION = '0.02005'; sub uuid_columns { my $self = shift; @@ -78,6 +78,8 @@ sub _find_uuid_module { return '::Win32::Guidgen'; } elsif (eval{require Win32API::GUID}) { return '::Win32API::GUID'; + } elsif (eval{require UUID::Random}) { + return '::UUID::Random'; } else { die 'no suitable uuid module could be found for use with DBIx::Class::UUIDColumns'; }; diff --git a/lib/DBIx/Class/UUIDColumns/UUIDMaker/UUID/Random.pm b/lib/DBIx/Class/UUIDColumns/UUIDMaker/UUID/Random.pm new file mode 100644 index 0000000..fb6756c --- /dev/null +++ b/lib/DBIx/Class/UUIDColumns/UUIDMaker/UUID/Random.pm @@ -0,0 +1,48 @@ +package DBIx::Class::UUIDColumns::UUIDMaker::UUID::Random; + +use strict; +use warnings; + +use base qw/DBIx::Class::UUIDColumns::UUIDMaker/; +use UUID::Random (); + +sub as_string { + return UUID::Random::generate; +}; + +1; +__END__ + +=head1 NAME + +DBIx::Class::UUIDColumns::UUIDMaker::UUID::Random - Create uuids using UUID::Random + +=head1 SYNOPSIS + + package Artist; + __PACKAGE__->load_components(qw/UUIDColumns Core DB/); + __PACKAGE__->uuid_columns( 'artist_id' ); + __PACKAGE__->uuid_class('::UUID::Random'); + +=head1 DESCRIPTION + +This DBIx::Class::UUIDColumns::UUIDMaker subclass uses UUID::Random to generate +uuid strings using UUID::Random::generate. + +=head1 METHODS + +=head2 as_string + +Returns the new uuid as a string. + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Moritz Onken + +=head1 LICENSE + +You may distribute this code under the same terms as Perl itself. diff --git a/t/pod_spelling.t b/t/pod_spelling.t index 3495678..6a97db0 100644 --- a/t/pod_spelling.t +++ b/t/pod_spelling.t @@ -20,6 +20,8 @@ add_stopwords(); all_pod_files_spelling_ok(); __DATA__ +Moritz +Onken uuid uuids Chia diff --git a/t/uuid.t b/t/uuid.t index 9a58c15..e4029e6 100644 --- a/t/uuid.t +++ b/t/uuid.t @@ -5,7 +5,7 @@ use warnings; BEGIN { use lib 't/lib'; - use DBIC::Test tests => 13; + use DBIC::Test tests => 14; }; my $schema = DBIC::Test->init_schema; @@ -85,6 +85,15 @@ SKIP: { ok $row->id, 'got something from Data::Uniqid'; }; +SKIP: { + skip 'UUID::Random not installed', 1 unless eval 'require UUID::Random'; + + DBIC::Test::Schema::Test->uuid_class('::UUID::Random'); + Class::C3->reinitialize(); + $row = $schema->resultset('Test')->create({ }); + ok $row->id, 'got something from UUID::Random'; +}; + eval { DBIC::Test::Schema::Test->uuid_class('::JunkIDMaker'); };