| 1 | # Copyright (c) 2025-2026 Philipp Schafft | ||
| 2 | |||
| 3 | # licensed under Artistic License 2.0 (see LICENSE file) | ||
| 4 | |||
| 5 | # ABSTRACT: module to interact with the famibeib fragments | ||
| 6 | |||
| 7 | |||
| 8 | package Lingua::famibeib::Fragment; | ||
| 9 | |||
| 10 | use v5.16; | ||
| 11 | use strict; | ||
| 12 | use warnings; | ||
| 13 | |||
| 14 | use Carp; | ||
| 15 | |||
| 16 | use Lingua::famibeib::Word; | ||
| 17 | |||
| 18 | our $VERSION = v0.08; | ||
| 19 | |||
| 20 | use parent 'Data::Identifier::Interface::Subobjects'; | ||
| 21 | |||
| 22 | |||
| 23 | sub new { | ||
| 24 | my ($pkg, $type, $value, @opts) = @_; | ||
| 25 | my @words; | ||
| 26 | my $self = bless {words => \@words}, $pkg; | ||
| 27 | |||
| 28 | croak 'Stray options passed' if scalar @opts; | ||
| 29 | croak 'No type given' unless defined $type; | ||
| 30 | croak 'No value given' unless defined $value; | ||
| 31 | |||
| 32 | if ($type eq 'words') { | ||
| 33 | foreach my $word (@{$value}) { | ||
| 34 | push(@words, Lingua::famibeib::Word->new(from => $word)); | ||
| 35 | } | ||
| 36 | } else { | ||
| 37 | croak 'Bad type: '.$type; | ||
| 38 | } | ||
| 39 | |||
| 40 | return $self; | ||
| 41 | } | ||
| 42 | |||
| 43 | |||
| 44 | sub words { | ||
| 45 | my ($self, @opts) = @_; | ||
| 46 | |||
| 47 | croak 'Stray options passed' if scalar @opts; | ||
| 48 | |||
| 49 | return @{$self->{words}}; | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | sub as_string { | ||
| 54 | my ($self, @opts) = @_; | ||
| 55 | |||
| 56 | croak 'Stray options passed' if scalar @opts; | ||
| 57 | |||
| 58 | return $self->{string} //= join(' ', @{$self->{words}}); | ||
| 59 | } | ||
| 60 | |||
| 61 | # ---- Private helpers ---- | ||
| 62 | |||
| 63 | 1; | ||
| 64 | |||
| 65 | __END__ |