NAME

Faker::Maker

ABSTRACT

Abstract Base Class for Faker

SYNOPSIS

package Example;

use Data::Object::Class;

with 'Faker::Maker';

package main;

my $example = Example->new;

DESCRIPTION

This package provides provides methods for generating and selecting random data.

LIBRARIES

This package uses type constraints from:

Types::Standard

METHODS

This package implements the following methods:

format_lex_markers

format_lex_markers(Str $string) : Str

The format_lex_markers method replaces each ? character in the string with a random letter.

format_lex_markers example #1
# given: synopsis

$example->format_lex_markers('???')

format_line_markers

format_line_markers(Str $string) : Str

The format_line_markers method replaces each escaped \n (newline) character in the string with a proper newline character.

format_line_markers example #1
# given: synopsis

$example->format_line_markers('foo\nbar')

format_number_markers

format_number_markers(Str $string) : Str

The format_number_markers method replaces each # in the string with a random digit, and each % with a random non-zero digit.

format_number_markers example #1
# given: synopsis

$example->format_number_markers('#-%-#')

parse_format

parse_format(Str $string) : Str

The parse_format method replaces each {{plugin.name}} in the string with the result of the evaluation of the plugin specified in the token, e.g. {{person.name}} is replaced with the result of executing the Faker::Plugin::PersonName plugin.

parse_format example #1
# given: synopsis

$example->parse_format('{{person.name}}')

process

process(Tuple[Str, Str] $lookup, Maybe[HashRef[Int]] $options) : Str

The process method performs a lookup and replacement in the lookup results based on the options specified. Valid options are all_markers, lex_markers, line_markers, and number_markers.

process example #1
# given: synopsis

$example->process(['person', 'username'], {
  all_markers => 1
})

process_format

process_format(Str $format) : Str

The process_format method dispatches to a plugin or performs a lookup and returns the result.

process_format example #1
# given: synopsis

$example->process_format('person.username')

process_lookup

process_lookup(Tuple[Str, Str] $lookup) : Str

The process_lookup method performs a lookup and returns the result.

process_lookup example #1
# given: synopsis

$example->process(['person', 'username'])

process_markers

process_markers(Str $string) : Str

The process_markers method replaces all markers, e.g. ?, #, %, with their random character counterparts.

process_markers example #1
# given: synopsis

$example->process_markers('#.%.#.?%?')

random_array_item

random_array_item(ArrayRef $items) : Any

The random_array_item method returns a random element from the arrayref provided.

random_array_item example #1
# given: synopsis

$example->random_item(['a', 'b', 'c'])

random_between

random_between(Maybe[Int] $from, Maybe[Int] $to) : Int

The random_between method returns a random number between the integers provided, or between 0 and 2147483647.

random_between example #1
# given: synopsis

$example->random_between

random_digit

random_digit() : Int

The random_digit method returns a random digit betwee 0 and 10.

random_digit example #1
# given: synopsis

$example->random_digit

random_digit_not_zero

random_digit_not_zero() : Int

The random_digit_not_zero method returns a random digit betwee 1 and 10.

random_digit_not_zero example #1
# given: synopsis

$example->random_digit_not_zero

random_float

random_float(Maybe[Int] $place, Maybe[Int] $min, Maybe[Int] $max) : Num

The random_float method returns a random floating-point number between the integers provided.

random_float example #1
# given: synopsis

$example->random_float
random_float example #2
# given: synopsis

$example->random_float(1, 10, 200)
random_float example #3
# given: synopsis

$example->random_float(2, 10, 200)

random_hash_item

random_hash_item(HashRef $items) : Any

The random_hash_item method returns a random element from the hashref provided.

random_hash_item example #1
# given: synopsis

$example->random_item({'a' => 1, 'b' => 2, 'c' => 3})

random_item

random_item(ArrayRef | HashRef $items) : Any

The random_item method returns a random element from the arrayref or hashref provided.

random_item example #1
# given: synopsis

$example->random_item(['a', 'b', 'c'])
random_item example #2
# given: synopsis

$example->random_item({'a' => 1, 'b' => 2, 'c' => 3})

random_letter

random_letter() : Str

The random_letter method returns a random alphabetic character.

random_letter example #1
# given: synopsis

$example->random_letter

random_number

random_number() : Num

The random_number method returns a random number.

random_number example #1
# given: synopsis

$example->random_number

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".

ACKNOWLEDGEMENTS

Parts of this library were inspired by the following implementations:

PHP Faker

Ruby Faker

Python Faker

JS Faker

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues