NAME

Mock::Populate - Mock data creation

VERSION

version 0.1702

SYNOPSIS

use Mock::Populate;
# * Call each function below with Mock::Populate::foo(...
my $n      = 5;
my $offset = 11;
my $ids    = number_ranger(start => 1, end => $n, prec => 0, random => 0);
my $money  = number_ranger(start => 1000, end => 5000, prec => 2, N => $n);
my $create = date_ranger(start => '1900-01-01', end => '2020-12-31', N => $n);
my $modify = date_modifier($offset, @$create);
my $times  = time_ranger(start => '01:02:03', end =>'23:59:59', stamp => 1, N => $n);
my $people = name_ranger(gender => 'f', N => $n);
my $email  = email_ranger(@$people);
my $stats  = distributor(type => 'u', prec => 4, dof => 2, N => $n);
my $string = string_ranger(length => 32, type => 'base64', N => $n);
my $imgs   = image_ranger(N => $n);
my $coll   = collate($ids, $people, $email, $create, $times);

DESCRIPTION

This is a set of functions for mock data creation.

No functions are exported, so use the entire Mock::Populate::* namespace when calling each.

Each function produces a list of elements that can be used as database columns. The handy collate() function takes these columns and returns a list of (arrayref) rows. This can then be processed into CSV, JSON, etc. It can also be directly inserted into your favorite database.

FUNCTIONS

date_ranger()

$results = date_ranger(start => $start, end => $end, N => $n);

Return a list of N random dates within a range. The start and end dates, and desired number of data-points are all optional. The defaults are:

start: 1970-01-01
end:   today (computed if not given)
N:     10

The dates must be given as YYYY-MM-DD strings.

date_modifier()

$results = date_modifier($offset, @$dates);

Return a new list of random dates, based on the offset.

time_ranger()

$results = time_ranger(
  stamp => $stamp,
  start => $start,
  end   => $end,
  N     => $n,
);

Return a list of N random times within a range. The stamp, start and end times, and desired number of data-points are all optional. The defaults are:

stamp: 1 (boolean)
start: 00:00:00
end:   now (computed if not given)
N:     10

The times must be given as HH:MM:SS strings. The stamp argument determines if a time-stamp or the number of seconds should be returned.

number_ranger()

$results = number_ranger(
  start  => $start,
  end    => $end,
  prec   => $prec,
  random => $random,
  N      => $n,
);

Return a list of numbers within the range defined by start and end. The start, end, precision, N, and whether we want random or sequential numbers are all optional. The defaults are:

start:     1
end:       10
precision: 2
random:    1 (boolean)
N:         10

name_ranger()

$results = name_ranger(
  gender  => $gender,
  names   => $names,
  country => $country,
  N       => $n,
);

Return a list of N random person names. The gender, names, country and desired number of data-points are all optional. The defaults are:

gender:  b (options: both, female, male)
names:   2 (first, last)
country: us
N:       10

This routine uses Mock::Person which currently, only supports us and ru countries.

email_modifier()

$results = email_modifier(@people)
# first.last@example.{com,net,org,edu}

Return a list of email addresses based on a list of given people names. Any names with unicode are run through Text::Unidecode.

distributor()

$results = distributor(
  type => $type,
  prec => $prec,
  dof  => $dof,
  N    => $n,
);

Return a list of N distribution values. The type, precision, degrees-of-freedom (dof), and desired number of data-points are optional. The defaults are:

type:      u (normal)
precision: 2
dof:       2
N:         10

This routine uses Statistics::Distributions.

Types

This function uses single letter identifiers:

u: Normal distribution (default)
c: Chi-squared distribution
s: Student's T distribution
f: F distribution

string_ranger()

$results = string_ranger(
  type   => $type,
  length => $length,
  N      => $n,
);

Return a list of N strings. The type, length, and number of data-points are optional. The defaults are:

type:   default
length: 8
N:      10

Types

Types     Output sample     Character set
___________________________________________________
default   0xaVbi3O2Lz8E69s  0..9 a..z A..Z
ascii     n:.T<Gr!,e*[k=eu  visible ascii
base64    PC2gb5/8+fBDuw+d  0..9 a..z A..Z / +
path      PC2gb5/8.fBDuw.d  0..9 a..z A..Z / .
simple    xek4imbjcmctsxd3  0..9 a..z
hex       89504e470d0a1a0a  0..9 a..f
alpha     femvifzscyvvlwvn  a..z
pron      werbucedicaremoz  a..z but pronounceable!
digit     7563919623282657  0..9
binary    1001011110000101  01
morse     -.--...-.--.-..-  .-

image_ranger()

$results = image_ranger(size => $size, N => $n)

Return a list of N 1x1 pixel images of varying byte sizes (not image dimension). The byte size and number of data-points are both optional.

The defaults are:

size: 8
N:    10

This routine uses Image::Dot.

collate()

$rows = collate(@columns)

Return a list of lists representing a 2D table of rows, given the lists provided, with each member added to a row, respectively.

SEE ALSO

Data::SimplePassword

Date::Range

Date::Simple

Image::Dot

Mock::Person

Statistics::Distributions

Text::Password::Pronounceable

Text::Unidecode

Time::Local

Data::Random does nearly the exact same thing. Whoops!

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2022 by Gene Boggs.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.