'Storable' => 0,
'Module::Find' => 0,
},
+ reommends => {
+ 'Data::UUID' => 0,
+ },
create_makefile_pl => 'passthrough',
create_readme => 1,
test_files => [ glob('t/*.t'), glob('t/*/*.t') ]
0.03002\r
- Minor bugfix to new (Row.pm)\r
- Schema doesn't die if it can't load a class (Schema.pm)\r
+ - New UUID columns plugin (UUIDColumns.pm)\r
\r
0.03001 2005-09-23 14:00:00\r
- Fixes to relationship helpers\r
--- /dev/null
+package DBIx::Class::UUIDColumns;
+use base qw/Class::Data::Inheritable/;
+
+use Data::UUID;
+
+__PACKAGE__->mk_classdata( 'uuid_auto_columns' => [] );
+
+=head1 NAME
+
+DBIx::Class::UUIDColumns - Implicit uuid columns
+
+=head1 SYNOPSIS
+
+ pacakge Artist;
+ __PACKAGE__->load_components(qw/UUIDColumns Core DB/);
+ __PACKAGE__->uuid_columns( 'artist_id' );x
+
+=head1 DESCRIPTION
+
+This L<DBIx::Class> component resambles the behaviour of
+L<Class::DBI::UUID>, to make some columns implicitly created as uuid.
+
+Note that the component needs to be loaded before Core.
+
+=head1 METHODS
+
+=over 4
+
+=item uuid_columns
+
+=cut
+
+# be compatible with Class::DBI::UUID
+sub uuid_columns {
+ my $self = shift;
+ for (@_) {
+ die "column $_ doesn't exist" unless exists $self->_columns->{$_};
+ }
+ $self->uuid_auto_columns(\@_);
+}
+
+sub insert {
+ my ($self) = @_;
+ for my $column (@{$self->uuid_auto_columns}) {
+ $self->$column( $self->get_uuid )
+ unless defined $self->$column;
+ }
+ $self->NEXT::ACTUAL::insert;
+}
+
+sub get_uuid {
+ return Data::UUID->new->to_string(Data::UUID->new->create),
+}
+
+=back
+
+=head1 AUTHORS
+
+Chia-liang Kao <clkao@clkao.org>
+
+=head1 LICENSE
+
+You may distribute this code under the same terms as Perl itself.
+
+=cut
+
+1;
--- /dev/null
+sub run_tests {
+
+eval 'use Data::UUID ; 1'
+ or plan skip_all, 'Install Data::UUID run this test';
+
+plan tests => 1;
+DBICTest::Artist->load_components('UUIDColumns');
+DBICTest::Artist->uuid_columns('name');
+
+my $artist = DBICTest::Artist->create( { artistid => 100 } );
+like $artist->name, qr/[\w-]{36}/, 'got something like uuid';
+
+}
+
+1;