NAME

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.

SYNOPSIS

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'
    },
  ]
);

DESCRIPTION

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.

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):

# 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 C<generate_value>...

sub generate_value {
  my ($this, $maker) = @_;
  # $this->some_attribute now return "blah"
  # amazing code here...
  return $amazing_value;
}