NAME
Faker::Plugin - Fake Data Plugin
ABSTRACT
Fake Data Plugin Base
VERSION
1.19
SYNOPSIS
package main;
use Faker::Plugin;
my $plugin = Faker::Plugin->new;
# bless(..., "Faker::Plugin")
# my $result = $plugin->execute;
# ""
DESCRIPTION
This distribution provides a library of fake data generators and a framework for extending the library via plugins.
ATTRIBUTES
This package has the following attributes:
faker
faker(Object $data) (Object)
The faker attribute holds the Faker object.
Since 1.10
- faker example 2
-
# given: synopsis package main; my $faker = $plugin->faker({}); # bless(..., "Faker")
- faker example 3
-
# given: synopsis package main; use Faker; my $faker = $plugin->faker(Faker->new); # bless(..., "Faker")
INTEGRATES
This package integrates behaviors from:
METHODS
This package provides the following methods:
execute
execute(HashRef $data) (Str)
The execute method should be overridden by a plugin subclass, and should generate and return a random string.
Since 1.10
new
new(HashRef $data) (Plugin)
The new method returns a new instance of the class.
Since 1.10
- new example 1
-
package main; use Faker::Plugin; my $plugin = Faker::Plugin->new; # bless(... "Faker::Plugin")
- new example 2
-
package main; use Faker::Plugin; my $plugin = Faker::Plugin->new({faker => ['en-us', 'es-es']}); # bless(... "Faker::Plugin")
- new example 3
-
package main; use Faker::Plugin; my $plugin = Faker::Plugin->new({faker => Faker->new('ja-jp')}); # bless(... "Faker::Plugin")
process
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.
Since 1.10
- process example 1
-
# given: synopsis package main; $plugin->faker->locales(['en-us']); my $process = $plugin->process('@?{{person_last_name}}####'); # "\@ZWilkinson4226"
process_format
process_format(Str $data) (Str)
The process_format method accepts a data template replacing any tokens found with the return value from "resolve".
Since 1.10
- process_format example 1
-
# given: synopsis package main; my $process_format = $plugin->process_format('Version {{software_version}}'); # "Version 0.78"
process_markers
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".
Since 1.10
- process_markers example 1
-
# given: synopsis package main; my $process_markers = $plugin->process_markers('Version %##'); # "Version 342"
- process_markers example 2
-
# given: synopsis package main; my $process_markers = $plugin->process_markers('Version %##', 'numbers'); # "Version 185"
- process_markers example 3
-
# given: synopsis package main; my $process_markers = $plugin->process_markers('Dept. %-??', 'letters', 'numbers'); # "Dept. 6-EL"
- process_markers example 4
-
# given: synopsis package main; my $process_markers = $plugin->process_markers('root\nsecret', 'newlines'); # "root\nsecret"
resolve
resolve(Str $name) (Str)
The resolve method replaces tokens from "process_format" with the return value from their corresponding plugins.
Since 1.10
- resolve example 1
-
# given: synopsis package main; my $color_hex_code = $plugin->resolve('color_hex_code'); # "#adfc4b"
- resolve example 2
-
# given: synopsis package main; my $internet_ip_address = $plugin->resolve('internet_ip_address'); # "edb6:0311:c3e3:fdc1:597d:115c:c179:3998"
- resolve example 3
-
# given: synopsis package main; my $color_name = $plugin->resolve('color_name'); # "MintCream"
FEATURES
This package provides the following features:
- subclass-feature
-
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"
AUTHORS
Awncorp, awncorp@cpan.org
LICENSE
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.