Data::Faker(3pm)
π Data::Faker β the manual page, but make it cute
okay bestie, gather round π this is the manpage for Data::Faker (that's the Data::Faker(3pm) one, from your friendly neighborhood Perl docs), and it's literally just a Perl extension for generating fake data. no cap.
β¨ NAME β¨
Data::Faker β Perl extension for generating fake data π
πΈ SYNOPSIS πΈ
use Data::Faker;
my $faker = Data::Faker->new();
print "Name: ".$faker->name."\n";
print "Company: ".$faker->company."\n";
print "Address: ".$faker->street_address."\n";
print " ".$faker->city.", ".$faker->us_state_abbr." ".$faker->us_zip_code."\n";
look at her go π¦ instant fake identity, no paperwork, no vibes ruined.
π DESCRIPTION π
This module creates fake (but reasonable) data π and it's perfect for stuff like filling databases with fake information while you're still developing database-related applications. like, you're not gonna hand-type 10,000 rows of nonsense, be so fr. let the module do it. main character energy fr fr.
π OBJECT METHODS π
π«Ά new()
Object constructor. As a shortcut, you can pass names of plugin modules to load to new() β though ngl, this does not actually restrict the functions available to the object, it just causes those plugins to be loaded if they haven't been loaded already. important distinction, bestie π
Also iconic: all Data::Faker objects in one interpreter share the plugin data, so that multiple objects don't multiply the memory requirements. we love an efficient queen β¨
π methods()
Return a list of the methods that have been provided by all of the loaded plugins. like a little roster of everyone clocked in π
π register_plugin()
Plugin modules call register_plugin() to provide data methods. see any of the included plugin modules for examples π§
π LOADING PLUGINS π
You can specify which plugins to load by including just the base part of their name as an argument when loading the module with use. for example, if you only wanted to use data from the Data::Faker::Name module, you would load Data::Faker like this:
use Data::Faker qw(Name);
By default, any modules matching Data::Faker::* in any directory in @INC will be loaded π You can also pass plugin names when calling the new() method, and they will be loaded if not already in memory. See new().
π¦ WRITING PLUGINS π¦
Writing a plugin to provide new kinds of data is easy β all you have to do is create a module named Data::Faker::SomeModuleName that inherits from Data::Faker. slay, you're a plugin author now π
To provide data, the plugin merely needs to call the register_plugin function with one or more pairs of function name and function data, like this:
#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Faker;
my $faker = Data::Faker->new();
print "My fake data is ".$faker->some_data_function."\n";
package Data::Faker::SomeData;
use base 'Data::Faker';
__PACKAGE__->register_plugin(
some_data_function => [qw(foo bar baz gazonk)],
another_data_item => sub { return '$some_data_function' },
);
okay so here's the tea β The first argument is the method that will be made available to your object, the second is a data source. and it depends on what that data source is:
- if the data source is not a reference, it will simply be returned as the data,
- if it is a reference to an array, a random element from the array will be returned,
- and if it is a subroutine reference, the subroutine will be run and the results will be returned.
The data that your data source provides is checked for two things: tokens (that look like perl variables, starting with a $), and numeric indicators (#). Any tokens found will be replaced with their values, and any numeric indicators will be replaced with random numbers π₯ You can include a literal $ or # by prefacing it with a backslash. very "escape the vibe" of you, honestly.
And if you load more than one module that defines the same function, it has an additive effect β when the function is called, one of the data sources provided will be selected at random and then it will be called to get a piece of data. sharing is caring, periodt π
Some data source examples:
__PACKAGE__->register_plugin(
age => ['#','##'],
monetary_amount => ['\$####.##','\$###.##', '\$##.##', '\$#.##'],
adult_age => sub { int(rand(70)+18) },
);
If your data source is a code reference, it will receive the calling object as an argument so you can build data out of other data if you need to π See Data::Faker::DateTime for some examples of this. iykyk.
π BUGS AND KNOWN ISSUES π
There is no way to selectively remove data sources from a plugin that was loaded, even if you didn't load it. yeah. that's the whole note. it's giving "no takebacks" π once it's in, it's in.
π SEE ALSO π
Text::Lorem
πΈ AUTHOR πΈ
Jason Kohles, <email@jasonkohles.com> π
π COPYRIGHT AND LICENSE π
Copyright 2004-2005 by Jason Kohles
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
friendly reminder bestie: fake data is for testing, not for committing crimes. use your powers responsibly π«Ά
and that's the whole page, babes β¨ this one came to you from perl v5.36.0, dated 2022-10-22, and it's the Data::Faker(3pm) manpage β thanks for reading, you ate that π
ππ¦
π¦ where this page comes from
- ubuntu noble: libdata-faker-perl 0.10-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-faker-perl 0.10-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdata-faker-perl 0.10-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms