DBIx::DataFactory::Type - the class for defining the rule of inserting data.
package DBIx::DataFactory::Type::Test; use strict; use warnings; use Carp; sub type_name { return 'Test'; } sub make_value { my ($class, %args) = @_; return 'test'; } 1;
you can define the rule of inserting data as class. you must define the method named type_name and make_value.
type_name is used to identify the class of type when create_factory_method is called. in following example, factory method insert data, defined by DBIx::DataFactory::Type::Test(see synopsis) make_value method, into 'test' column automatically.
$factory_maker->create_factory_method( method => 'create_factory_data', table => 'test_factory', auto_inserted_columns => { test => { type => 'Test', }, }, );
make_value is used to define data for inserting. hash specified in auto_inserted_columns except type is passed to make_value.
$factory_maker->create_factory_method( method => 'create_factory_data', table => 'test_factory', auto_inserted_columns => { test => { type => 'Test', size => 10, regexp => '[a-z]{10}', }, }, );
when the above case, make_value will be called in create_factory_data method as following.
DBIx::DataFactory::Type::Test->make_value( size => 10, regexp => '[a-z]{10}', );
the following type is already defined in this module.
random int maker. you can pass size parameter.
$factory_maker->create_factory_method( method => 'create_factory_data', table => 'test_factory', auto_inserted_columns => { int => { type => 'Int', size => 8, }, }, );
random number maker. you can pass size parameter. size means integer part size.
$factory_maker->create_factory_method( method => 'create_factory_data', table => 'test_factory', auto_inserted_columns => { num => { type => 'Num', size => 8, }, }, );
random string maker. you can pass size or regexp parameter.
if size parameter is passed, this maker produce strings like [a-zA-Z0-9]{$size}.
if regexp parameter is passed, this maker produce strings according to passed regular regexp.
$factory_maker->create_factory_method( method => 'create_factory_data', table => 'test_factory', auto_inserted_columns => { str => { type => 'Str', regexp => '[a-z]{20}', }, }, );
returning one of specified set in a random manner.
$factory_maker->create_factory_method( method => 'create_factory_data', table => 'test_factory', auto_inserted_columns => { set => { type => 'Set', set => ['test1', 'test2'], }, }, );
To install DBIx::DataFactory, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::DataFactory
CPAN shell
perl -MCPAN -e shell install DBIx::DataFactory
For more information on module installation, please visit the detailed CPAN module installation guide.