Class::DBI::UUID - Provide Globally Unique Column Values
package MyApp::User; use base qw[Class::DBI]; __PACKAGE__->connection('dbi:SQLite:dbfile', '', ''); __PACKAGE__->table(q[users]); __PACKAGE__->columns(Primary => 'id'); __PACKAGE__->columns(Essential => qw[username password]); use Class::DBI::UUID; __PACKAGE__->uuid_columns('id'); # Elsewhere.. my $user = MyApp::User->create({ username => 'user', password => 'pass', }); print $user->id; # A UUID string.
This module implements globally unique columns values. When an object is created, the columns specified are given unique IDs. This is particularly helpful when running in an environment where auto incremented primary keys won't work, such as multi-master replication.
MyApp::User->uuid_columns(MyApp::User->columns('Primary'));
A before_create trigger will be set up to set the values of each column listed as input to a Data::UUID string. Change the type of string output using the uuid_columns_type class method.
before_create
Data::UUID
uuid_columns_type
MyApp::User->uuid_columns_type('bin'); # keep it small
By default the type will be str. It's the largest, but its also the safest for general use. Possible values are bin, str, hex, and b64. Basically, anything that you can append to create_ and still get a valid method name from Data::UUID. Also returns the type to be used.
str
bin
hex
b64
create_
Do not change this value on a whim. If you do change it, change it before your call to uuid_columns, or, call uuid_columns again after it is changed (therefore calling it before uuid_columns, but also adding extra triggers without need).
uuid_columns
This module is implemented as a mixin and therefore exports the functions uuid_columns, and uuid_columns_type into the caller's namespace. If you don't want these to be exported, then load this module using require.
require
Class::DBI, Data::UUID, perl.
Casey West, <casey@geeknest.com>.
Copyright (c) 2005 Casey West. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::DBI::UUID, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::DBI::UUID
CPAN shell
perl -MCPAN -e shell install Class::DBI::UUID
For more information on module installation, please visit the detailed CPAN module installation guide.