| 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.08; | ||
| 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__ |