NAME

Lingua::Awkwords::OneOf - random choice from a list of items

SYNOPSIS

This module is not typically used directly, as it will be created and called as part of the pattern parse and then render phases of other code.

DESCRIPTION

Container object for a list of items; upon render one of these items will be picked at random and have render called on it. Whatever that returns will be returned, minus whatever any filters may remove.

ATTRIBUTES

filters

List of filters, if any. Use add_filters to set these.

filter_with

String to replaced filtered values with, the empty string by default.

picker

Where the Math::Random::Discrete object to provide weighted random choices is stored.

terms

Choices are stored here as an array reference.

weights

List of weights for each of the choices.

METHODS

add_choice value weight

Adds the given value and its weight to the choices.

add_filters filter ..

Adds one or more strings as a filter for the render phase. These limit what a unit can generate, e.g. [x/y/z]^x would replace a result of x with the empty string.

clear_picker

This is used by the add method to invalidate the picker object; call this method if you have manually fiddled with the alts or weights after making a render call.

new

Constructor.

render

Picks a random choice and in turn calls render on that, then applies any filters present on that result.

walk callback

Calls the callback function with itself as the argument, then calls walk on all of the available choices.

BUGS

Reporting Bugs

Please report any bugs or feature requests to bug-lingua-awkwords at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Lingua-Awkwords.

Patches might best be applied towards:

https://github.com/thrig/Lingua-Awkwords

Known Issues

None at this time.

SEE ALSO

Lingua::Awkwords, Lingua::Awkwords::Parser

Math::Random::Discrete

AUTHOR

thrig - Jeremy Mates (cpan:JMATES) <jmates at cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2017 by Jeremy Mates

This program is distributed under the (Revised) BSD License: http://www.opensource.org/licenses/BSD-3-Clause