CINXE.COM
Data::Fake - Declaratively generate fake structured data for testing - metacpan.org
<!DOCTYPE html> <html lang="en-US"> <head> <title>Data::Fake - Declaratively generate fake structured data for testing - metacpan.org</title> <link rel="preload" as="fetch" href="/account/login_status" crossorigin="anonymous" /> <link href="/assets/style-XFEQ536G.css" rel="stylesheet" type="text/css"> <script src="/assets/main-WXBSEDQJ.js" type="module"></script> <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Data-Fake - MetaCPAN" href="/dist/Data-Fake/releases.rss" /> <link rel="canonical" href="https://metacpan.org/pod/Data::Fake" /> <meta name="description" content="Declaratively generate fake structured data for testing" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5"> <link rel="shortcut icon" href="/static/icons/favicon.ico"> <link rel="apple-touch-icon" sizes="152x152" href="/static/icons/apple-touch-icon.png"> <link rel="search" href="/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN"> <script async src="https://perl-ads.perlhacks.com/perl-ads.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=G-E82Q2V8LVD"></script> <meta property="og:site_name" content="MetaCPAN" /> <meta name="twitter:site" content="@metacpan" /> <meta property="og:type" content="article" /> <meta name="twitter:card" content="summary" /> <meta property="og:url" content="https://metacpan.org/pod/Data::Fake" /> <meta property="og:title" content="Data::Fake" /> <meta property="og:description" content="Declaratively generate fake structured data for testing" /> <meta property="og:image" content="https://metacpan.org/static/images/dots.png" /> </head> <body> <nav class="navbar navbar-default" role="navigation"> <div class="header-logo-large hidden-xs"> <a href="/" tabindex="0"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#logo" /> </svg> </a> </div> <div class="header-logo-icon visible-xs"> <a href="/"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#dots" /> </svg> </a> </div> <ul class="nav navbar-nav menu-items hidden-xs hidden-sm"> <li><a href="/about">About</a></li> <li><a href="/about/sponsors">Sponsor</a></li> <li><a href="https://grep.metacpan.org/">grep::cpan</a></li> <li><a href="/recent">Recent</a></li> <li><a href="/about/faq">FAQ</a></li> <li><a href="/tools">Tools</a></li> <li><a href="https://fastapi.metacpan.org/">API</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <button type="button" class="searchbar-btn visible-xs visible-sm"> <i class="fa fa-search button-fa-icon"></i> </button> <form action="/search" class="searchbar-form visible-md visible-lg search-form form-horizontal"> <input type="hidden" name="size" id="metacpan_search-size" value="20"> <div class="form-group"> <div class="search-group"> <i class="fa fa-search"></i> <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value=""> </div> </div> </form> <li class="icon-slidepanel visible-xs visible-sm"> <button data-toggle="slidepanel" data-target=".slidepanel"> <span class="button-fa-icon"> <i class="fa fa-bars slidepanel-open"></i> <i class="fa fa-times slidepanel-close"></i> </span> </button> </li> <li class="dropdown login-dropdown show-logged-in"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li><a href="/account/identities">Identities</a></li> <li><a href="/account/profile">Profile</a></li> <li><a href="/account/favorite/list">Favorites</a></li> <li> <a href="#" type="button" class="logout-button"> Logout </a> </li> </ul> </li> <li class="dropdown login-dropdown show-logged-out"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon avatar-placeholder" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li> <a href="/login/github"> <i class="fab fa-github fa-fw"></i> GitHub </a> </li> <li> <a href="/login/twitter"> <i class="fab fa-twitter fa-fw"></i> Twitter </a> </li> <li> <a href="/login/google"> <i class="fab fa-google fa-fw"></i> Google </a> </li> </ul> </li> <li class="dropdown login-dropdown hide-logged-in hide-logged-out"> <button> <i class="fa fa-user button-fa-icon" aria-hidden="true"></i> </button> </li> </ul> </nav> <div class="page-content "> <div id="perl-ad-target" class="top-notify-banner perl-ad-target"> </div> <nav class="sidebar"> <div class="slidepanel"> <ul class="nav-list "> <li class="nav-header no-margin-top"> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Data-Fake was released."> <span class="relatize">26 Feb 2021 01:40:58 UTC</span> </div> </li> <li> Distribution: <a href="/dist/Data-Fake">Data-Fake</a> </li> <li> Module version: 0.006 </li> <li> <a data-keyboard-shortcut="g s" href="/dist/Data-Fake/source/lib/Data/Fake.pm">Source</a> (<a href="/dist/Data-Fake/source/lib/Data/Fake.pm?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/Data-Fake/source/lib/Data">Browse</a> (<a href="/dist/Data-Fake/source/lib/Data?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/Data-Fake/changes">Changes</a> </li> <li> <a rel="noopener nofollow" class="nopopup" href="https://github.com/dagolden/Data-Fake">Homepage</a> </li> <li> <a class="nopopup" href="/dist/Data-Fake/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/dagolden/Data-Fake">Repository</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://github.com/dagolden/Data-Fake/issues">Issues</a> (4) </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Data-Fake+0.006" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Data-Fake.html?oncpan=1&distmat=1&version=0.006&grade=2" style="color: #090">1010</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Data-Fake.html?oncpan=1&distmat=1&version=0.006&grade=3" style="color: #900">459</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Data-Fake.html?oncpan=1&distmat=1&version=0.006&grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/DAGOLDEN/Data-Fake-0.006">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Data-Fake who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)"> Bus factor: 1 </div> </li> <li> <a rel="noopener nofollow" href="http://cpancover.com/latest/Data-Fake-0.006/index.html">92.07% Coverage </a> </li> <li> License: apache_2_0 </li> <li> Perl: v5.8.1 </li> <li class="nav-header">Activity</li> <li> <div class="activity-graph"> <img src="/dist/Data-Fake/activity.svg?res=month" /> <div class="comment">24 month</div> </div> </li> <li class="nav-header">Tools</li> <li> <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/D/DA/DAGOLDEN/Data-Fake-0.006.tar.gz"> Download (<span itemprop="fileSize">37.89KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FDAGOLDEN%2FData-Fake-0.006%2Flib%2FData%2FFake.pm"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/Data-Fake/permissions"> Permissions </a> </li> <li> <a href="/dist/Data-Fake/releases.rss"> Subscribe to distribution </a> </li> <li> <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog"> Install Instructions </button> </li> <li> <form action="/search"> <input type="hidden" name="q" value="dist:Data-Fake"> <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li> <form action="https://grep.metacpan.org/search"> <input type="hidden" name="qd" value="Data-Fake"> <input type="hidden" name="source" value="metacpan"> <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li class="version-jump"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Jump to version</option> <option disabled value="/release/DAGOLDEN/Data-Fake-0.006/view/lib/Data/Fake.pm" >0.006 (DAGOLDEN on 2021-02-26)</option> <option value="/release/DAGOLDEN/Data-Fake-0.005/view/lib/Data/Fake.pm" >0.005 (DAGOLDEN on 2020-10-01)</option> <option value="/release/DAGOLDEN/Data-Fake-0.004/view/lib/Data/Fake.pm" >0.004 (DAGOLDEN on 2018-06-20)</option> <option value="/release/DAGOLDEN/Data-Fake-0.003/view/lib/Data/Fake.pm" >0.003 (DAGOLDEN on 2016-08-21)</option> <option value="/release/DAGOLDEN/Data-Fake-0.002/view/lib/Data/Fake.pm" >0.002 (DAGOLDEN on 2015-02-05)</option> <option value="/release/DAGOLDEN/Data-Fake-0.001/view/lib/Data/Fake.pm" >0.001 (DAGOLDEN on 2015-01-21)</option> </select> </li> <li class="version-diff"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Diff with version</option> <option disabled value="/release/DAGOLDEN/Data-Fake-0.006/diff/DAGOLDEN/Data-Fake-0.006/lib/Data/Fake.pm" >0.006 (DAGOLDEN on 2021-02-26)</option> <option value="/release/DAGOLDEN/Data-Fake-0.006/diff/DAGOLDEN/Data-Fake-0.005/lib/Data/Fake.pm" >0.005 (DAGOLDEN on 2020-10-01)</option> <option value="/release/DAGOLDEN/Data-Fake-0.006/diff/DAGOLDEN/Data-Fake-0.004/lib/Data/Fake.pm" >0.004 (DAGOLDEN on 2018-06-20)</option> <option value="/release/DAGOLDEN/Data-Fake-0.006/diff/DAGOLDEN/Data-Fake-0.003/lib/Data/Fake.pm" >0.003 (DAGOLDEN on 2016-08-21)</option> <option value="/release/DAGOLDEN/Data-Fake-0.006/diff/DAGOLDEN/Data-Fake-0.002/lib/Data/Fake.pm" >0.002 (DAGOLDEN on 2015-02-05)</option> <option value="/release/DAGOLDEN/Data-Fake-0.006/diff/DAGOLDEN/Data-Fake-0.001/lib/Data/Fake.pm" >0.001 (DAGOLDEN on 2015-01-21)</option> </select> </li> <li> <ul class="dependencies"> <li class="nav-header">Dependencies</li> <li><a href="/pod/Carp" title="Carp" class="ellipsis">Carp</a></li> <li><a href="/pod/Exporter" title="Exporter" class="ellipsis">Exporter</a></li> <li><a href="/pod/Import::Into" title="Import::Into" class="ellipsis">Import::Into</a></li> <li><a href="/pod/List::Util" title="List::Util" class="ellipsis">List::Util</a></li> <li><a href="/pod/Text::Lorem" title="Text::Lorem" class="ellipsis">Text::Lorem</a></li> <li><a href="/pod/Time::Piece" title="Time::Piece" class="ellipsis">Time::Piece</a></li> <li><a href="/pod/strict" title="strict" class="ellipsis">strict</a></li> <li><a href="/pod/warnings" title="warnings" class="ellipsis">warnings</a></li> <li> <hr> </li> <li> <a href="/module/Data::Fake/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=Data%3A%3AFake">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=Data-Fake">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/DAGOLDEN/Data-Fake-0.006/view/lib/Data/Fake.pm">This version</a> </li> <li> <a href="/pod/Data::Fake">Latest version</a> </li> <li> <div class="plussers"> <div class="nav-header">++ed by:</div> <div> <a class="display-all" href="/author/MARSENI"><img src="https://www.gravatar.com/avatar/9b0819943a0746dac5a17a5781759a7a?d=identicon&s=20" title="MARSENI" alt="MARSENI"></a> <a class="display-all" href="/author/STAUGAARD"><img src="https://www.gravatar.com/avatar/9169da8c1866e822c7f0937db3ead721?d=identicon&s=20" title="STAUGAARD" alt="STAUGAARD"></a> <a class="display-all" href="/author/KES"><img src="https://www.gravatar.com/avatar/e8530f00b43b4f6a056f8ad4ee52ea47?d=identicon&s=20" title="KES" alt="KES"></a> <a class="display-all" href="/author/SKAUFMAN"><img src="https://www.gravatar.com/avatar/2caf2787e235f58a65576632f93ef6c3?d=identicon&s=20" title="SKAUFMAN" alt="SKAUFMAN"></a> <a class="display-all" href="/author/JETEVE"><img src="https://www.gravatar.com/avatar/c4e14b12510fe0f58bbec64d47ed5816?d=identicon&s=20" title="JETEVE" alt="JETEVE"></a> </div> <!-- Display counts of plussers--> <div> <a href="/dist/Data-Fake/plussers">10 PAUSE users</a> </div> <div> 6 non-PAUSE users </div> </div> </li> <li> <div> <button class="contributors-show-button btn-link">and 4 contributors</button> <div id="metacpan_contributors" class="slide-out slide-out-hidden"> <div> <ul> <li class="contributor" data-contrib-email="50083900+chloekek@users.noreply.github.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&s=20" /> Chloé Kekoa </li> <li class="contributor" data-contrib-email="jjatria@gmail.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&s=20" /> José Joaquín Atria </li> <li class="contributor" data-contrib-email="rjbs@users.noreply.github.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&s=20" /> Ricardo Signes </li> <li class="contributor" data-contrib-email="stuarts@broadbean.com" > <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&s=20" /> Stuart Skelton </li> </ul> </div> </div> </div> </li> </ul> </div> </nav> <div class="content-navigation"> <div class="breadcrumbs"> <span> <a data-keyboard-shortcut="g a" rel="author" href="/author/DAGOLDEN" class="author-name">David Golden</a> </span> <span> / </span> <div class="release dist-release status-latest maturity-released"> <span class="dropdown"><b class="caret"></b></span> <select class="select-navigator "> <option selected value="/release/DAGOLDEN/Data-Fake-0.006/view/lib/Data/Fake.pm" >0.006 (DAGOLDEN on 2021-02-26)</option> <option value="/release/DAGOLDEN/Data-Fake-0.005/view/lib/Data/Fake.pm" >0.005 (DAGOLDEN on 2020-10-01)</option> <option value="/release/DAGOLDEN/Data-Fake-0.004/view/lib/Data/Fake.pm" >0.004 (DAGOLDEN on 2018-06-20)</option> <option value="/release/DAGOLDEN/Data-Fake-0.003/view/lib/Data/Fake.pm" >0.003 (DAGOLDEN on 2016-08-21)</option> <option value="/release/DAGOLDEN/Data-Fake-0.002/view/lib/Data/Fake.pm" >0.002 (DAGOLDEN on 2015-02-05)</option> <option value="/release/DAGOLDEN/Data-Fake-0.001/view/lib/Data/Fake.pm" >0.001 (DAGOLDEN on 2015-01-21)</option> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/Data-Fake">Data-Fake-0.006</a> </div> <span class="river-gauge-gauge"> <svg width="24px" height="15px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g> <title> River stage one • 3 direct dependents • 6 total dependents </title> <rect x="0" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="5" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="10" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="15" y="0" width="4" height="15" fill="#e4e2e2" /> <rect x="20" y="0" width="4" height="15" fill="#e4e2e2" /> </g> </svg> </span> <div id="Data-Fake-fav" class="show-logged-in"> <form action="/account/favorite/add" style="display: inline" method="POST"> <input type="hidden" name="remove" value="0"> <input type="hidden" name="release" value="Data-Fake-0.006"> <input type="hidden" name="author" value="DAGOLDEN"> <input type="hidden" name="distribution" value="Data-Fake"> <button type="submit" class="favorite highlight"><span>16</span> ++</button> </form> </div> <div class="show-logged-out"> <button class="fav-not-logged-in favorite highlight"><span>16</span> ++</button> </div> / <span>Data::Fake</span> </div> </div> <main class="content"> <nav class="toc"> <div class="toc-header"><strong>Contents</strong></div> <ul> <li><a href="#NAME">NAME</a></li> <li><a href="#VERSION">VERSION</a></li> <li><a href="#SYNOPSIS">SYNOPSIS</a></li> <li><a href="#DESCRIPTION">DESCRIPTION</a></li> <li><a href="#USAGE">USAGE</a> <ul> <li><a href="#Loading-the-right-submodules">Loading the right submodules</a></li> <li><a href="#Constructing-the-desired-output">Constructing the desired output</a></li> <li><a href="#Using-custom-generators">Using custom generators</a></li> <li><a href="#Caveats-and-special-cases">Caveats and special cases</a></li> </ul> </li> <li><a href="#CONTRIBUTING">CONTRIBUTING</a></li> <li><a href="#SEE-ALSO">SEE ALSO</a></li> <li><a href="#AUTHOR">AUTHOR</a></li> <li><a href="#CONTRIBUTORS">CONTRIBUTORS</a></li> <li><a href="#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p>Data::Fake - Declaratively generate fake structured data for testing</p> <h1 id="VERSION">VERSION</h1> <p>version 0.006</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <pre><code>use Data::Fake qw/Core Names Text Dates/; my $hero_generator = fake_hash( { name => fake_name(), battlecry => fake_sentences(1), birthday => fake_past_datetime("%Y-%m-%d"), friends => fake_array( fake_int(2,4), fake_name() ), gender => fake_pick(qw/Male Female Other/), } ); my $hero = $hero_generator->(); ### example output ### # { # 'name' => 'Antonio Nicholas Preston' # 'battlecry' => 'Est ipsum corrupti quia voluptatibus.', # 'birthday' => '2004-04-21', # 'friends' => [ # 'Jaylin Lillianna Morgan', # 'Colin Noel Estes', # 'Justice Aron Hale', # 'Franco Zane Oneil' # ], # 'gender' => 'Male', # };</code></pre> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p>This module generates randomized, fake structured data using declarative syntax.</p> <p><code>Data::Fake</code> is built on higher-order programming principles. It provides users with "factory" functions, which create "generator" functions for specific pieces of data.</p> <p>Wherever randomized, fake data is desired, a generator code reference is used as a placeholder for the desired output. Each time the top-level generator is run, nested generators are recursively run to turn placeholders into the desired randomized data.</p> <p>For example, the SYNOPSIS declares the desired form of a "hero" using the <code>fake_hash</code> factory function. The input is a hash-reference, with nested generators created as placeholders by the <code>fake_name</code>, <code>fake_sentences</code>, etc. factory functions:</p> <pre><code>my $hero_generator = fake_hash( { name => fake_name(), battlecry => fake_sentences(1), birthday => fake_past_datetime("%Y-%m-%d"), friends => fake_array( fake_int(2,4), fake_name() ), gender => fake_pick(qw/Male Female Other/), } );</code></pre> <p>Every time <code>$hero_generator</code> is run, a new hash is generated based on the template and nested generators.</p> <h1 id="USAGE">USAGE</h1> <h2 id="Loading-the-right-submodules"><a id="Loading"></a>Loading the right submodules</h2> <p>Factory functions are exported by submodules, loosely grouped by topic:</p> <ul> <li><p><a href="/pod/Data::Fake::Core">Data::Fake::Core</a> – general purpose generators: hashes, arrays, numeric values, string templates</p> </li> <li><p><a href="/pod/Data::Fake::Company">Data::Fake::Company</a> – company name, job title</p> </li> <li><p><a href="/pod/Data::Fake::Dates">Data::Fake::Dates</a> – past and future dates</p> </li> <li><p><a href="/pod/Data::Fake::Internet">Data::Fake::Internet</a> – domain names, email addresses</p> </li> <li><p><a href="/pod/Data::Fake::Names">Data::Fake::Names</a> – first and last names</p> </li> <li><p><a href="/pod/Data::Fake::Text">Data::Fake::Text</a> – characters, words, sentences, paragraphs</p> </li> </ul> <p>Submodules can be loaded directly, to control exactly which functions are exported, or they can be loaded by the <code>Data::Fake</code> import function like so:</p> <pre><code>use Data::Fake qw/Core Company Dates Names/;</code></pre> <p>In this case, the listed submodules are loaded and all their functions are imported.</p> <h2 id="Constructing-the-desired-output"><a id="Constructing"></a>Constructing the desired output</h2> <p>Use the factory functions to construct a generator for your data. Start with the highest level structure using <a href="/pod/Data::Fake::Core#fake_hash">fake_hash</a> or <a href="/pod/Data::Fake::Core#fake_array">fake_array</a>. Use other factory functions to create placeholders with specific data types.</p> <p>For example, a hash generator with placeholders for phone numbers:</p> <pre><code>$hash_generator = fake_hash( { home => fake_digits("###-###-####"), work => fake_digits("###-###-####"), cell => fake_digits("###-###-####"), } );</code></pre> <p>Or build them up piece by piece. For example, an array of 100 of the previous hash references:</p> <pre><code>$array_generator = fake_array( 100, $hash_generator );</code></pre> <p>Then generate the hundred instances, each with three fake phone numbers:</p> <pre><code>$aoh = $array_generator->();</code></pre> <p>See <a href="/pod/distribution/Data-Fake/lib/Data/Fake/Examples.pod">Data::Fake::Examples</a> for ideas for how to use and combine generators.</p> <h2 id="Using-custom-generators"><a id="Using"></a>Using custom generators</h2> <p>Generators are just code references. You can use your own anywhere a Data::Fake generator could be used:</p> <pre><code>$generator = fake_hash( favorite_color => \&my_favorite_color_picker, number_squared => sub { ( int(rand(10)) + 1 ) ** 2 }, );</code></pre> <p>You can (and probably should) write your own factory functions for anything complex or that you'll use more than once. You can use Data::Fake generators as part of these functions.</p> <pre><code>use Data::Fake qw/Core/; sub fake_squared_int { my $max_int = shift; my $prng = fake_int( 1, $max_int ); return sub { $prng->() ** 2 }; } $generator = fake_hash( number_squared => fake_squared_int(10), );</code></pre> <h2 id="Caveats-and-special-cases"><a id="Caveats"></a>Caveats and special cases</h2> <p>Because many data structures are walked recursively looking for code-references to replace, circular references will cause an infinite loop.</p> <p>If you need a code references as part of your output data structure, you need to wrap it in a code reference.</p> <pre><code>$generator = fake_hash( a_function => sub { \&some_function }, );</code></pre> <h1 id="CONTRIBUTING">CONTRIBUTING</h1> <p>If you have ideas for additional generator functions and think they would be sensible additions to the main distribution, please open a support ticket to discuss it. To be included in the main distribution, additional generator functions should add few, if any, additional dependencies.</p> <p>If you would like to release your own distributions in the <code>Data::Fake::*</code> namespace, please follow the conventions of the existing modules:</p> <ul> <li><p>factory function names start with "fake_"</p> </li> <li><p>export all factory functions by default</p> </li> <li><p>allow code-references where you would allow a sizing constant</p> </li> </ul> <h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1> <ul> <li><p><a href="/pod/Data::Faker">Data::Faker</a> – similar but object oriented; doesn't do structured data; always loads all plugins</p> </li> <li><p><a href="/pod/Data::Random">Data::Random</a> – generate several random types of data</p> </li> <li><p><a href="/pod/Test::Sims">Test::Sims</a> – generator for libraries generating random data</p> </li> <li><p><a href="/pod/Text::Lorem">Text::Lorem</a> – just fake text</p> </li> </ul> <h1 id="AUTHOR">AUTHOR</h1> <p>David Golden <dagolden@cpan.org></p> <h1 id="CONTRIBUTORS">CONTRIBUTORS</h1> <ul> <li><p>Chloé Kekoa <50083900+chloekek@users.noreply.github.com></p> </li> <li><p>José Joaquín Atria <jjatria@gmail.com></p> </li> <li><p>Ricardo Signes <rjbs@users.noreply.github.com></p> </li> <li><p>Stuart Skelton <stuarts@broadbean.com></p> </li> </ul> <h1 id="COPYRIGHT-AND-LICENSE"><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1> <p>This software is Copyright (c) 2015 by David Golden.</p> <p>This is free software, licensed under:</p> <pre><code>The Apache License, Version 2.0, January 2004</code></pre></div> <div id="metacpan_install-instructions-dialog" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Module Install Instructions</h4> </div> <div class="modal-body"> <p>To install Data::Fake, copy and paste the appropriate command in to your terminal.</p> <p><a href="/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p> <pre><code>cpanm Data::Fake</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install Data::Fake</code></pre> <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p> </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> </div> </div> </div> </div> </main> <div class="content-pagination"> </div> </div> <footer class="footer"> <div class="footer-container"> <div class="footer-social"> <div class="footer-link footer-logo"> <a href="/"> <img src="/static/images/metacpan-logo.svg" alt="MetaCPAN" /> </a> </div> <a class="footer-social-link" href="https://github.com/metacpan"> <i class="fab fa-github-square"></i> </a> <a class="footer-social-link" href="https://fosstodon.org/@metacpan"> <i class="fab fa-mastodon"></i> </a> </div> <div class="footer-links"> <div class="footer-link"> <a href="/about">About</a> </div> <div class="footer-link"> <a href="/about/sponsors">Sponsor</a> </div> <div class="footer-link"> <a href="https://grep.metacpan.org">grep::cpan</a> </div> <div class="footer-link"> <a href="/recent">Recent</a> </div> <div class="footer-link"> <a href="/about/faq">FAQ</a> </div> <div class="footer-link"> <a href="/tools">Tools</a> </div> <div class="footer-link"> <a href="https://fastapi.metacpan.org/">API</a> </div> <div class="footer-link"> <a href="https://www.perl.org/">Perl.org</a> </div> </div> <div class="footer-sponsors"> <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener"> <img class="footer-sponsor-bytemark" src="/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener"> <img class="footer-sponsor-liquidweb" src="/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener"> <img class="footer-sponsor-deriv" src="/static/images/sponsors/deriv.svg" alt="Deriv logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener"> <img class="footer-sponsor-geocode" src="/static/images/sponsors/geocodelogo.svg" alt="Geocode logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener"> <img class="footer-sponsor-fastly" src="/static/images/sponsors/fastly_logo.svg" alt="Fastly logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener"> <img class="footer-sponsor-opencage" src="/static/images/sponsors/open-cage.svg" alt="OpenCage logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://www.elastic.co/" rel="noopener"> <img class="footer-sponsor-elastic" src="/static/images/sponsors/elastic.svg" alt="Elastic logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://route4me.com/" rel="noopener"> <img class="footer-sponsor-route4me" src="/static/images/sponsors/route4me.png" alt="Route4Me logo"> </a> </div> </div> </footer> <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Keyboard Shortcuts</h4> </div> <div class="modal-body row"> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Global</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>s</kbd> </td> <td>Focus search bar</td> </tr> <tr> <td class="keys"> <kbd>?</kbd> </td> <td>Bring up this help dialog</td> </tr> </tbody> </table> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>GitHub</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>p</kbd> </td> <td>Go to pull requests</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>go to github issues (only if github is preferred repository)</td> </tr> </tbody> </table> </div> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>POD</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>a</kbd> </td> <td>Go to author</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>c</kbd> </td> <td>Go to changes</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>Go to issues</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>d</kbd> </td> <td>Go to dist</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>r</kbd> </td> <td>Go to repository/SCM</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>s</kbd> </td> <td>Go to source</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>b</kbd> </td> <td>Go to file browse</td> </tr> </tbody> </table> </div> <div class="col-md-12"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Search terms</th> </tr> </thead> <tbody> <tr> <td><em>module:</em> (e.g. <a href="/search?q=module%3APlugin">module:Plugin</a>)</td> </tr> <tr> <td><em>distribution:</em> (e.g. <a href="/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td> </tr> <tr> <td><em>author:</em> (e.g. <a href="/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td> </tr> <tr> <td><em>version:</em> (e.g. <a href="/search?q=version%3A1.00">version:1.00</a>)</td> </tr> </tbody> </table> </div> </div> <div class="modal-footer"></div> </div> </div> </div> </body> </html>