Faker::Plugin - Fake Data Plugin
Fake Data Plugin Base
1.19
package main; use Faker::Plugin; my $plugin = Faker::Plugin->new; # bless(..., "Faker::Plugin") # my $result = $plugin->execute; # ""
This distribution provides a library of fake data generators and a framework for extending the library via plugins.
This package has the following attributes:
faker(Object $data) (Object)
The faker attribute holds the Faker object.
Since 1.10
1.10
# given: synopsis package main; my $faker = $plugin->faker; # bless(..., "Faker")
# given: synopsis package main; my $faker = $plugin->faker({}); # bless(..., "Faker")
# given: synopsis package main; use Faker; my $faker = $plugin->faker(Faker->new); # bless(..., "Faker")
This package integrates behaviors from:
Venus::Role::Buildable
Venus::Role::Optional
This package provides the following methods:
execute(HashRef $data) (Str)
The execute method should be overridden by a plugin subclass, and should generate and return a random string.
# given: synopsis package main; my $data = $plugin->execute; # ""
new(HashRef $data) (Plugin)
The new method returns a new instance of the class.
package main; use Faker::Plugin; my $plugin = Faker::Plugin->new; # bless(... "Faker::Plugin")
package main; use Faker::Plugin; my $plugin = Faker::Plugin->new({faker => ['en-us', 'es-es']}); # bless(... "Faker::Plugin")
package main; use Faker::Plugin; my $plugin = Faker::Plugin->new({faker => Faker->new('ja-jp')}); # bless(... "Faker::Plugin")
process(Str $data) (Str)
The process method accepts a data template and calls "process_format" and "process_markers" with the arguments provided and returns the result.
# given: synopsis package main; $plugin->faker->locales(['en-us']); my $process = $plugin->process('@?{{person_last_name}}####'); # "\@ZWilkinson4226"
process_format(Str $data) (Str)
The process_format method accepts a data template replacing any tokens found with the return value from "resolve".
# given: synopsis package main; my $process_format = $plugin->process_format('Version {{software_version}}'); # "Version 0.78"
process_markers(Str $data, Str @types) (Str)
The process_markers method accepts a string with markers, replaces the markers (i.e. special symbols) and returns the result. This method also, optionally, accepts a list of the types of replacements to be performed. The markers are: # (see "digit" in Venus::Random), % (see "nonzero" in Venus::Random), ? (see "letter" in Venus::Random), and \n. The replacement types are: "letters", "numbers", and "newlines".
#
%
?
\n
# given: synopsis package main; my $process_markers = $plugin->process_markers('Version %##'); # "Version 342"
# given: synopsis package main; my $process_markers = $plugin->process_markers('Version %##', 'numbers'); # "Version 185"
# given: synopsis package main; my $process_markers = $plugin->process_markers('Dept. %-??', 'letters', 'numbers'); # "Dept. 6-EL"
# given: synopsis package main; my $process_markers = $plugin->process_markers('root\nsecret', 'newlines'); # "root\nsecret"
resolve(Str $name) (Str)
The resolve method replaces tokens from "process_format" with the return value from their corresponding plugins.
# given: synopsis package main; my $color_hex_code = $plugin->resolve('color_hex_code'); # "#adfc4b"
# given: synopsis package main; my $internet_ip_address = $plugin->resolve('internet_ip_address'); # "edb6:0311:c3e3:fdc1:597d:115c:c179:3998"
# given: synopsis package main; my $color_name = $plugin->resolve('color_name'); # "MintCream"
This package provides the following features:
This package is meant to be subclassed.
example 1
package Faker::Plugin::UserId; use base 'Faker::Plugin'; sub execute { my ($self) = @_; return $self->process('####-####'); } package main; use Faker; my $faker = Faker->new; # bless(..., "Faker") my $result = $faker->user_id; # "8359-6325"
Awncorp, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2000, Al Newkirk.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.
To install Faker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Faker
CPAN shell
perl -MCPAN -e shell install Faker
For more information on module installation, please visit the detailed CPAN module installation guide.