NAME
Lingua::TokiPona::Word - module to interact with the words of Toki Pona
VERSION
version v0.02
SYNOPSIS
use Lingua::TokiPona::Word;
my Lingua::TokiPona::Word $word = Lingua::TokiPona::Word->new(string => 'mi');
say $word->as_string;
This module inherits from Data::Identifier::Interface::Known, Data::Identifier::Interface::Simple, and Data::Identifier::Interface::Subobjects.
OVERVIEW
Toki Pona is a constructed language that features a specifically small set of vocables. This module abstracts those words. It aims to contain all known words (as of v0.02: which is currently not yet fully true).
As the vocabulary is so limited, this module does hold all the words in memory at all times. This means that there are never two different object instances for the same words. (Note that this may limit the usefulness of Data::Identifier::Interface::Subobjects).
That said, synonyms are consider different words. So this is round-trip safe (you always get the word you asked for, not one of it's synonyms).
To get a list of all known words use "known".
METHODS
new
my Lingua::TokiPona::Word $word = Lingua::TokiPona::Word->new($type => $value);
# e.g.:
my Lingua::TokiPona::Word $word = Lingua::TokiPona::Word->new(string => 'mi');
(since v0.01)
Constructs a new word. The word is normalised as part of this. This method deduplicate instances.
Currently the following types ($type) are supported:
from-
(since v0.01)
Constructs a word from an object.
$valueshould be a reference.Currently references to the following types are supported: Lingua::TokiPona::Word, or anything "new" in Data::Identifier accepts via
from. More types might be supported.If
$valueis not a reference the value is parsed as perstringif it looks like a word string (experimental since v0.01). ise-
(since v0.02)
Constructs a word from a ISE (such as returned by "ise" in Data::Identifier::Interface::Simple).
string-
(since v0.01)
Constructs a word from it's (latin) string representation.
ucsur-
(since v0.02)
Constructs a word from the UCSUR code point.
See "ucsur" for details.
Accepts the numerical code point or standard Unicode notation (
U+xxxx).
as_string
my $str = $word->as_string;
(since v0.01)
Returns the string representation of the word.
ucsur
my $ucsur = $word->ucsur( [ %opts ] );
(since v0.02)
Returns the Under-ConScript Unicode Registry (UCSUR) code point of the word or dies if there is none.
Returns the numerical Unicode code point unless as is given.
The following options are supported:
as-
Returns the value as the passed type. All types supported by "as" in Data::Identifier are supported.
default-
The default value to return if no other value is available. This can be set to
undefto let this method returnundef(notdie). no_defaults-
This option is accepted but ignored.
eq
my $bool = $word->eq($other); # $word must be non-undef
# or:
my $bool = Lingua::TokiPona::Word::eq($word, $other); # $word can be undef
(since v0.01)
Compares two words to be equal.
If both words are undef they are considered equal.
If $word or $other is not an instance of Lingua::TokiPona::Word or undef "new" with the type from is used.
The operators "eq" in perlop and "ne" in perlop are overloaded to this method.
cmp
my $val = $word->cmp($other); # $word must be non-undef
# or:
my $val = Lingua::TokiPona::Word::cmp($word, $other); # $word can be undef
(experimental since v0.01)
Compares the words similar to cmp. This method can be used to order words. To check for them to be equal see "eq".
The parameters are parsed the same way as "eq".
The operator "cmp" in perlop is overloaded to this method.
If this method is used for sorting the exact resulting order is not defined. However:
The order is stable
The order is the same for
$a->cmp($b)as for- $b->cmp($a).
has_type
my $type = $word->has_type( [ %opts ] );
(since v0.02)
Returns the type of the word which will always be the same for all words: a Toki Pona word.
Note: If you want to know about other roles (e.g. particle vs. noun) this is the wrong method for you.
The following options are accepted:
as-
Returns the value as the passed type. All types supported by "as" in Data::Identifier are supported.
default-
This option is accepted but ignored.
no_defaults-
This option is accepted but ignored.
known
my @list = Lingua::TokiPona::Word->known($class [, %opts ] );
(since v0.01)
Returns the known items for the given class.
For details and supported options see "known" in Data::Identifier::Interface::Known.
The following classes are supported:
:all-
(since v0.01)
Returns all known things.
words-
(since v0.02)
Returns all known words.
stopword-
(since v0.02)
Returns all known stopwords.
AUTHOR
Philipp Schafft <lion@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2026 by Philipp Schafft <lion@cpan.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)