Data::Maker::Field - a Moose role that is consumed by all Data::Maker field classes; the ones included with Data::Maker and the ones that you write yourself to extend Data::Maker's capabilities.
use Data::Maker; use Data::Maker::Field::Person::LastName; use MyField; my $maker = Data::Maker->new( record_count => 10_000, delimiter => "\t", fields => [ { name => 'lastname', class => 'Data::Maker::Field::Person::LastName' }, { name => 'ssn', class => 'Data::Maker::Field::Format', args => { format => '\d\d\d-\d\d-\d\d\d\d' } }, { name => 'myfield', class => 'MyField' }, ] );
To write your own Data::Maker field class, create a Moose class that consumes the Data::Maker::Field role.
package MyField; use Moose; with 'Data::Maker::Field'; has some_attribute => ( is => 'rw' ); sub generate_value { my ($this, $maker) = @_; # amazing code here... return $amazing_value; } 1;
You must provide a generate_value method, which is the method that will be called to generate the value of this field for each record.
generate_value
Any Moose attribute that you define (some_flag in the above example) can then be passed in as an argument in your field definition and will be available as an object method inside your generate_value method (or any other class method, for that matter):
some_flag
# define the field in your Data::Maker constructor: my $maker = Data::Maker->new( record_count => 10, fields => [ { name => 'myfield', class => 'MyField', args => { some_attribute => 'blah' } } ] ); # And then later, in generate_value()... sub generate_value { my ($this, $maker) = @_; # $this->some_attribute now return "blah" # amazing code here... return $amazing_value; }
The following public Moose attributes are supported (the data type of each attribute is also listed)
The name of the field. This is used to refer to this field from other fields, and can also be used as a method to the Data::Maker::Record object to retrieve the value for this field.
The name of the class to be used for this field
The hash reference of arguments to be passed to this field
A code reference that will be executed on the value after it is generated, but before it is returned
To install Data::Maker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Maker
CPAN shell
perl -MCPAN -e shell install Data::Maker
For more information on module installation, please visit the detailed CPAN module installation guide.