NAME

Lingua::Awkwords::Subpattern - implements named subpatterns

SYNOPSIS

This module is typically automagically used via Lingua::Awkwords.

DESCRIPTION

Subpatterns are named (with the ASCII letters A-Z) elements of an awkwords pattern that expand out to some list of choices equally weighted. That is,

V

can be a shorthand notation for

[a/e/i/o/u]

See the source code for what patterns are defined by default, or use set_patterns or update_pattern first to change the values.

ATTRIBUTES

pattern

The pattern this object represents. Mandatory. Typically should be an ASCII letter in the A-Z range and typically should be set via the new method.

METHODS

is_pattern pattern

Returns a boolean indicating whether pattern is an existing pattern or not.

new

Constructor. A pattern should ideally be supplied. Will blow up if the pattern does not exist in the global patterns list.

Lingua::Awkwords::Subpattern->new( pattern => 'V' )
render

Returns a random item from the list of choices for the pattern that was hopefully set by some previous call. Blows up if pattern was not set.

set_patterns list-of-patterns-and-choices

Allows the choices for multiple patterns to be set in a single call. These changes are global to a process. For example for the Toki Pona language one might set C for consonants and V for vowels via

Lingua::Awkwords::Subpattern->set_patterns(
    C => [qw/j k l m n p s t w/],
    V => [qw/a e i o u/],
);
update_pattern pattern choices

Updates the choices for the given pattern. This happens globally in a process; all instances will see the change in future render calls.

Note that array references are treated differently than lists of values;

my $nnmm = [qw/n m/];
Lingua::Awkwords::Subpattern->update_pattern( N => $nnmm );

allows the array reference $nnmm to be changed by the caller (thus affecting future render calls for that pattern), while

Lingua::Awkwords::Subpattern->update_pattern( N => @$nnmm );

does not allow the caller to then change anything as instead a copy of the list of choices has been made.

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

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