| 1 | # Copyright (c) 2026 Philipp Schafft | ||
| 2 | |||
| 3 | # licensed under Artistic License 2.0 (see LICENSE file) | ||
| 4 | |||
| 5 | # ABSTRACT: module to interact with words foreign to famibeib | ||
| 6 | |||
| 7 | |||
| 8 | package Lingua::famibeib::ForeignWord; | ||
| 9 | |||
| 10 | use v5.16; | ||
| 11 | use strict; | ||
| 12 | use warnings; | ||
| 13 | |||
| 14 | use Carp; | ||
| 15 | |||
| 16 | our $VERSION = v0.07; | ||
| 17 | |||
| 18 | use parent qw(Lingua::famibeib::Word); | ||
| 19 | |||
| 20 | |||
| 21 | sub new { | ||
| 22 | my ($pkg, $type, $value, @opts) = @_; | ||
| 23 | my $self = bless {}, $pkg; | ||
| 24 | |||
| 25 | croak 'Stray options passed' if scalar @opts; | ||
| 26 | croak 'No type given' unless defined $type; | ||
| 27 | croak 'No value given' unless defined $value; | ||
| 28 | |||
| 29 | if ($type eq 'string') { | ||
| 30 | if ($value =~ /^to./i) { | ||
| 31 | $value =~ s/^[Tt][Oo]/to/; # enforce lower case | ||
| 32 | $self->{stem} = ':self'; | ||
| 33 | $self->{modifiers} = {}; | ||
| 34 | $self->{string} = $value; | ||
| 35 | } else { | ||
| 36 | croak 'Bad word, did you mean to call Lingua::famibeib::Word->new()?'; | ||
| 37 | } | ||
| 38 | } else { | ||
| 39 | croak 'Bad type: '.$type; | ||
| 40 | } | ||
| 41 | |||
| 42 | return $self; | ||
| 43 | } | ||
| 44 | |||
| 45 | |||
| 46 | sub combine { | ||
| 47 | croak 'Combining foreign words is not supported'; | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 51 | sub as { | ||
| 52 | my ($self, $as, @opts) = @_; | ||
| 53 | if (scalar(@opts) == 0) { | ||
| 54 | if ($self->isa($as)) { | ||
| 55 | return $self; | ||
| 56 | } elsif ($as eq 'Lingua::TokiPona::Word') { | ||
| 57 | require Lingua::TokiPona::Word; | ||
| 58 | return Lingua::TokiPona::Word->new(string => substr($self->as_string, 2)); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | confess 'Not supported'; | ||
| 62 | } | ||
| 63 | |||
| 64 | # ---- Private helpers ---- | ||
| 65 | |||
| 66 | 1; | ||
| 67 | |||
| 68 | __END__ | ||
| 69 | |||
| 70 | =pod | ||
| 71 | |||
| 72 | =encoding UTF-8 | ||
| 73 | |||
| 74 | =head1 NAME | ||
| 75 | |||
| 76 | Lingua::famibeib::ForeignWord - module to interact with words foreign to famibeib | ||
| 77 | |||
| 78 | =head1 VERSION | ||
| 79 | |||
| 80 | version v0.07 | ||
| 81 | |||
| 82 | =head1 SYNOPSIS | ||
| 83 | |||
| 84 | use Lingua::famibeib::Word; | ||
| 85 | |||
| 86 | my Lingua::famibeib::Word $word = Lingua::famibeib::Word->new(string => 'toXyz'); | ||
| 87 | |||
| 88 | my $str = $word->as_string; | ||
| 89 | |||
| 90 | (since v0.06) | ||
| 91 | |||
| 92 | This package is used to store individual foreign words and query them about their properties. | ||
| 93 | |||
| 94 | This module inherits from L<Lingua::famibeib::Word>. | ||
| 95 | Most of it's methods do work on this type of words, however not all of them. | ||
| 96 | |||
| 97 | =head1 METHODS | ||
| 98 | |||
| 99 | =head2 new | ||
| 100 | |||
| 101 | my Lingua::famibeib::Word $word = Lingua::famibeib::Word->new(...); | ||
| 102 | |||
| 103 | To construct a foreign word the normal word constructor should be used. | ||
| 104 | |||
| 105 | =head2 combine | ||
| 106 | |||
| 107 | ... $word->combine(...); | ||
| 108 | |||
| 109 | This method is not supported for foreign words as such words cannot be combined. | ||
| 110 | |||
| 111 | =head2 as | ||
| 112 | |||
| 113 | my $obj = $word->as($as); | ||
| 114 | |||
| 115 | This method is much more limited on foreign words as it cannot create a L<Data::Identifier>. | ||
| 116 | |||
| 117 | =head1 AUTHOR | ||
| 118 | |||
| 119 | Philipp Schafft <lion@cpan.org> | ||
| 120 | |||
| 121 | =head1 COPYRIGHT AND LICENSE | ||
| 122 | |||
| 123 | This software is Copyright (c) 2025-2026 by Philipp Schafft <lion@cpan.org>. | ||
| 124 | |||
| 125 | This is free software, licensed under: | ||
| 126 | |||
| 127 | The Artistic License 2.0 (GPL Compatible) | ||
| 128 | |||
| 129 | =cut |