NAME
Mock::Populate - Mock data creation
VERSION
version 0.0701
SYNOPSIS
use Mock::Populate;
$ids = Mock::Populate::number_ranger(1, 1001, 0, 0, $n);
$dates = Mock::Populate::date_ranger('1900-01-01', '2020-12-31', $n);
$times = Mock::Populate::time_ranger(1, '01:02:03' '23:59:59', $n);
$nums = Mock::Populate::number_ranger(1000, 5000, 2, 1, $n);
$people = Mock::Populate::personify('b', 2, 'us', 0, $n);
$email = Mock::Populate::emailify(@$people);
$stats = Mock::Populate::stats_distrib('u', 4, 2, $n);
$shuff = Mock::Populate::shuffler($n, qw(foo bar baz goo ber buz));
$string = Mock::Populate::stringer(32, 'base64', $n);
$imgs = Mock::Populate::imager(10, $n);
$collated = Mock::Populate::collate($people, $email, $dates, $times);
DESCRIPTION
This is a set of functions for mock data creation.
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, with your favorite perl ORM.
NAME
Mock::Populate - Mock data creation
FUNCTIONS
date_ranger()
@results = date_ranger($start, $end, $n);
Return a list of $n random dates within a range. The start and end dates and desired number of data-points arguments are all optional. The defaults are:
start: 2000-01-01
end: today (computed if not given)
n: 10
The dates must be given as YYYY-MM-DD strings.
time_ranger()
@results = time_ranger($stamp, $start, $end, $n);
Return a list of $n random times within a range. The start and end times and desired number of data-points arguments 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.
number_ranger()
@results = number_ranger($start, $end, $prec, $random, $n)
Return a list of $n random numbers within a range. The start, end, precision, whether we want random or sequential numbers and desired number of data-points arguments are all optional. The defaults are:
start: 0
end: 9
precision: 2
random: 0
n: 10
personify()
@results = personify($gender, $names, $country, $n)
Return a list of $n random names. The gender, number of names and desired number of data-points arguments are all optional. The defaults are:
gender: both
names: 2
country: us
n: 10
emailify()
$results = emailify(@people)
Return a list of $n email addresses based on a list of given names.
stats_distrib()
@results = stats_distrib($type, $prec, $dof, $n)
Return a list of $n distribution values. The type, precision, degrees-of-freedom and desired number of data-points arguments are optional. The defaults are:
type: u (normal)
precision: 2
degrees-of-freedom: 2
n: 10
Types
This function uses single letter identifiers:
u: Normal distribution (default)
c: Chi-squared distribution
s: Student's T distribution
f: F distribution
Degrees of freedom
Given the type, this function accepts the following:
c: A single integer
s: A single integer
f: A fraction string of the form 'N/D' (default 2/1)
shuffler()
@results = shuffler($n, @items)
Return a shuffled list of $n items. The items and number of data-points arguments are optional. The defaults are:
n: 10
items: a b c d e f g h i j
stringer()
@results = stringer($n, @items)
Return a shuffled list of $n items. The items and number of data-points arguments are optional. The defaults are:
type: default
length: 8
n: 10
* This function is nearly identical to the Data::SimplePassword rndpassword
program, but allows you to generate a finite number of results.
Types
Types output sample
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 / +
simple xek4imbjcmctsxd3 # 0..9 a..z
hex 89504e470d0a1a0a # 0..9 a..f
alpha femvifzscyvvlwvn # a..z
digit 7563919623282657 # 0..9
binary 1001011110000101
morse -.--...-.--.-..-
imager()
@results = imager($size, $n)
Return a list of 1x1 pixel images of varying byte sizes (not image dimension). The size and number of data-points are both optional.
The defaults are:
n: 10
size: 8
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::Random does nearly the exact same thing. Whoops!
AUTHOR
Gene Boggs <gene@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 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.