| DBIx-Class-RandomColumns documentation | view source | Contained in the DBIx-Class-RandomColumns distribution. |
DBIx::Class::RandomColumns - Implicit random columns
package My::Schema::Utz;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/RandomColumns Core/);
__PACKAGE__->table('utz');
__PACKAGE__->add_columns(qw(id foo bar baz));
__PACKAGE__->random_columns('id', bar => {size => 10});
package My::Schema::Gnarf;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/RandomColumns Core/);
__PACKAGE__->table('gnarf');
__PACKAGE__->add_columns(
id => {
datatype => 'varchar',
is_random => 1,
size => 20,
},
foo => {
datatype => 'int',
size => 10,
},
bar => {
datatype => 'varchar',
is_random => {size => 10},
size => 32,
},
baz => {
datatype => 'varchar',
size => 255,
},
);
This is version 0.003000
This DBIx::Class component makes columns implicitly create random values.
The main reason why this module exists is to generate unpredictable primary keys to add some additional security to web applications.
Note that the component needs to be loaded before Core.
__PACKAGE__->random_columns(@column_names); __PACKAGE__->random_columns(name1 => \%options1, name2 => \%options2); $random_columns = __PACKAGE__->random_columns;
Define or query fields that get random strings at creation. Each column name can be followed by a hash reference containing options.
Valid options are:
A string or an array reference that contains the set of characters to use
for building the random key. The default set is ['0'..'9', 'a'..'z']
for character type fields and ['0'..'9'] for number type fields.
Length of the random string to create. Defaults to the size of the column or - if this cannot be determined for whatever reason - to 32.
Search table before insert until generated column value is not found.
Defaults to false and must be set to a true value to activate.
Provided Perl's rand() function has sufficient entropy this lookup is only
usefull for short fields, because with the default set there are
36^field-size possible combinations.
Returns a has reference, with column names of the random columns as keys and
array references as values, that contain set, size and check.
Hooks into DBIx::Class::Row::insert() to create a random value for each random column/random_columns that is not defined.
$value = $instance->get_random_value($column_name);
Compute a random value for the given $column_name.
Throws an exception if the concerning column has not been declared as a random column.
is_random => 1
is_random => {size => 16, set => ['0'..'9','A'..'F']}
Instead of calling random_columns it is also possible to specify option
is_random in add_columns.
The value is either a true scalar, indicating that this in fact is a
random column, or a hash reference, that has the same meaning as described
under random_columns.
Bernhard Graf <graf(a)cpan.org>
Please report any bugs or feature requests to
bug-dbix-class-randomclumns at rt.cpan.org, or through the web interface
at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-RandomColumns.
I will be notified, and then you'll automatically be notified of progress
on your bug as I make changes.
Copyright 2008 Bernhard Graf.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| DBIx-Class-RandomColumns documentation | view source | Contained in the DBIx-Class-RandomColumns distribution. |