Data::Random::Structure - Generate random data structures
version 0.01
use Test::More; use Data::Random::Structure; use JSON::PP; my $g = Data::Random::Structure->new( max_depth => 2, max_elements => 5, ); my $ref = $g->generate(); diag explain $ref; my $json = JSON::PP->new; print $json->pretty->encode($ref); ok(1); done_testing();
This is a library to create random Perl data structures, mostly as a means to create input for benchmarking and testing various serialization libraries.
It uses grotty 'classic' Perl 5 OO mostly because I think having Moo as a dependency for a testing module is pretty gross. On the other hand, original flavor Perl OO is pretty gross.
The maximum depth to embed data structures
The maximum number of elements (array items or hash key/value pairs) per data structure.
Constructor. May optionally pass:
max_depth
max_elements
If not set, these default to 3 and 6 respectively. Throws an exception if the argument list is not a multiple of 2.
Recursively generate a data structure using hashes and arrays. The data structure will not contain more than max_depth nested data structures.
Randomly generates one of the following scalar values:
float
integer (between 0 and 999_999)
string (see Data::Random rand_chars)
rand_chars
bool (value based 50/50 coin toss)
Generate an arrayref and populate it with no more than max_element items. May be empty.
max_element
Generate a hashref and populate it with no more than max_element key/value pairs. May be empty.
Mark Allen <mrallen1@yahoo.com>
This software is copyright (c) 2014 by Mark Allen.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Data::Random::Structure, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Random::Structure
CPAN shell
perl -MCPAN -e shell install Data::Random::Structure
For more information on module installation, please visit the detailed CPAN module installation guide.