Data::Maker::Field::Set - A L<Data::Maker> field class that generates its data based on a list of potential values.


Data-Maker documentation Contained in the Data-Maker distribution.

Index


Code Index:

NAME

Top

Data::Maker::Field::Set - A Data::Maker field class that generates its data based on a list of potential values.

SYNOPSIS

Top

  use Data::Maker;
  use Data::Maker::Field::Set;

  my $maker = Data::Maker->new(
    record_count => 10,
    fields => [
      {
        name => 'reindeer',
        class => 'Data::Maker::Field::Set',
        args => {
          set => [ 'Dasher', 'Dancer', 'Prancer', 'Vixen', 'Comet', 'Cupid', 'Donner', 'Blitzen' ]
        }
      }
    ]
  );

DESCRIPTION

Top

Data::Maker::Field::Set takes a single argument, set, whose value must be an array reference of potential values.

AUTHOR

Top

John Ingram (john@funnycow.com)

LICENSE

Top

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::Set;
use Moose;
with 'Data::Maker::Field';

our $VERSION = '0.10';

has set => ( is => 'rw', isa => 'ArrayRef' );

sub generate_value {
  my $this = shift;
  if ($this->set) {
    return $this->set->[ rand @{$this->set} ];
  }
}
1;

__END__