| Data-Maker documentation | Contained in the Data-Maker distribution. |
Data::Maker::Field::MultiSet - A Data::Maker field class that generates its data based on a set of lists of potential values.
use Data::Maker;
use Data::Maker::Field::MultiSet;
my $maker = Data::Maker->new(
record_count => 10,
fields => [
{
name => 'character',
class => 'Data::Maker::Field::MultiSet',
args => {
sets => [
[ 'Dasher', 'Dancer', 'Prancer', 'Vixen', 'Comet', 'Cupid', 'Donner', 'Blitzen' ]
[ 'Dopey', 'Sleepy', 'Grumpy', 'Doc', 'Happy', 'Bashful', 'Sneezy' ]
]
}
}
]
);
Data::Maker::Field::MultiSet takes a single argument, sets, whose value must be an array reference consisting of array references of potential values.
John Ingram (john@funnycow.com)
Copyright 2010 by John Ingram. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Data-Maker documentation | Contained in the Data-Maker distribution. |
package Data::Maker::Field::MultiSet; use Moose; with 'Data::Maker::Field'; our $VERSION = '0.16'; has sets => ( is => 'rw', isa => 'ArrayRef[ArrayRef]' ); has delimiter => ( is => 'rw', isa => 'Str', default => ' ' ); sub generate_value { my $this = shift; if ($this->sets) { my @out; for my $set(@{$this->sets}) { push(@out, $set->[ rand @{$set} ]); } return join($this->delimiter, @out); } } 1; __END__