Debian Codegraph @

README

raw
1 NAME
2 Data::Faker - Perl extension for generating fake data
3
4 SYNOPSIS
5 use Data::Faker;
6
7 my $faker = Data::Faker->new();
8
9 print "Name: ".$faker->name."\n";
10 print "Company: ".$faker->company."\n";
11 print "Address: ".$faker->street_address."\n";
12 print " ".$faker->city.", ".$faker->us_state_abbr." ".$faker->us_zip_code."\n";
13
14 DESCRIPTION
15 This module creates fake (but reasonable) data that can be used for
16 things such as filling databases with fake information during
17 development of database related applications.
18
19 OBJECT METHODS
20 new()
21 Object constructor. As a shortcut, you can pass names of plugin
22 modules to load to new(), although this does not actually restrict
23 the functions available to the object, it just causes those plugins
24 to be loaded if they haven't been loaded already. All Data::Faker
25 objects in one interpreter share the plugin data, so that multiple
26 objects don't multiply the memory requirements.
27
28 methods();
29 Return a list of the methods that have been provided by all of the
30 loaded plugins.
31
32 register_plugin();
33 Plugin modules call register_plugin() to provide data methods. See
34 any of the included plugin modules for examples.
35
36 LOADING PLUGINS
37 You can specify which plugins to load by including just the base part of
38 their name as an argument when loading the module with 'use'. For
39 example if you only wanted to use data from the Data::Faker::Name
40 module, you would load Data::Faker like this:
41
42 use Data::Faker qw(Name);
43
44 By default any modules matching Data::Faker::* in any directory in @INC
45 will be loaded. You can also pass plugin names when calling the new()
46 method, and they will be loaded if not already in memory. See new().
47
48 WRITING PLUGINS
49 Writing a plugin to provide new kinds of data is easy, all you have to
50 do is create a module named Data::Faker::SomeModuleName that inherits
51 from Data::Faker.
52
53 To provide data, the plugin merely needs to call the register_plugin
54 function with one or more pairs of function name and function data, like
55 this:
56
57 #!/usr/bin/perl -w
58 use strict;
59 use warnings;
60 use Data::Faker;
61
62 my $faker = Data::Faker->new();
63 print "My fake data is ".$faker->some_data_function."\n";
64
65 package Data::Faker::SomeData;
66 use base 'Data::Faker';
67
68 __PACKAGE__->register_plugin(
69 some_data_function => [qw(foo bar baz gazonk)],
70 another_data_item => sub { return '$some_data_function' },
71 );
72
73 The first argument is the method that will be made available to your
74 object, the second is a data source. If the data source is not a
75 reference, it will simply be returned as the data, if it is a reference
76 to an array, a random element from the array will be returned, and if it
77 is a subroutine reference, the subroutine will be run and the results
78 will be returned. The data that your data source provides is checked for
79 two things, tokens (that look like perl variables, starting with a $),
80 and numeric indicators (#). Any tokens found will be replaced with their
81 values, and any numeric indicators will be replaced with random numbers.
82 You can include a literal $ or # by prefacing it with a backslash. If
83 you load more than one module that defines the same function, it has an
84 additive effect, when the function is called one of the data sources
85 provided will be selected at random and then it will be called to get a
86 piece of data.
87
88 Some data source examples:
89
90 __PACKAGE__->register_plugin(
91 age => ['#','##'],
92 monetary_amount => ['\$####.##','\$###.##', '\$##.##', '\$#.##'],
93 adult_age => sub { int(rand(70)+18) },
94 );
95
96 If your data source is a code reference, it will receive the calling
97 object as an argument so you can build data out of other data if you
98 need to. See Data::Faker::DateTime for some examples of this.
99
100 BUGS AND KNOWN ISSUES
101 There is no way to selectively remove data sources from a plugin that
102 was loaded, even if you didn't load it.
103
104 SEE ALSO
105 Text::Lorem
106
107 AUTHOR
108 Jason Kohles, <[email protected]>
109
110 COPYRIGHT AND LICENSE
111 Copyright 2004-2005 by Jason Kohles
112
113 This library is free software; you can redistribute it and/or modify it
114 under the same terms as Perl itself.
115