| 1 | # Copyright (c) 2026 Philipp Schafft | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # licensed under Artistic License 2.0 (see LICENSE file) | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # ABSTRACT: module to interact with the words of any language | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | package Lingua::Generic::Interface::Word; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use v5.20; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Data::Identifier v0.34; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | our $VERSION = v0.01; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use parent qw(Data::Identifier::Interface::Subobjects Data::Identifier::Interface::Simple); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | use overload ( | ||||||||||||||||||||||||||||
| 22 | '""' => \&as_string, | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | 'eq' => sub { $_[0]->eq($_[1]) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | 'ne' => sub { !$_[0]->eq($_[1]) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | 'cmp' => sub { $_[0]->cmp($_[1]) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub new { | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my ($pkg, $type, $value, @opts) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | croak 'No type given' unless defined $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | croak 'No value given' unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | croak 'Stray options passed' if scalar @opts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($type eq 'from') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if (ref $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($value->isa(__PACKAGE__)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | return $value; | |||||||||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||||||||||
| 42 | ... | ||||||||||||||||||||||||||||
| 43 | 0 | } | |||||||||||||||||||||||||||
| 44 | } else { | ||||||||||||||||||||||||||||
| 45 | 0 | $type = 'string'; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } elsif ($type eq 'ise') { | ||||||||||||||||||||||||||||
| 48 | ... | ||||||||||||||||||||||||||||
| 49 | 0 | } | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($type eq 'string') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | return bless { | |||||||||||||||||||||||||||
| 53 | string => $value, | ||||||||||||||||||||||||||||
| 54 | }, $pkg; | ||||||||||||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||||||||||
| 56 | 0 | croak 'Bad type: '.$type; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub as_string { | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my ($self, @opts) = @_; | ||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return $self->{string} // confess 'BUG: No valid string'; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"string"} // confess("BUG: No valid string")
MC/DC0%0/2
$self->{"string"} // confess("BUG: No valid string")
$self->{"string"}
confess("BUG: No valid string")
Truth table0%0/3
A // B
A= $self->{"string"}B= confess("BUG: No valid string")
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub eq { | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my ($self, $other, @opts) = @_; | ||||||||||||||||||||||||||
|
Subroutine
eq: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | croak 'Stray options passed' if scalar @opts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return 1 if !defined($self) && !defined($other); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self or defined $other
MC/DC0%0/2
defined $self or defined $other
defined $self
defined $other
Truth table0%0/3
A or B
A= defined $selfB= defined $other
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return undef unless defined($self) && defined($other); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self and defined $other
MC/DC0%0/2
defined $self and defined $other
defined $self
defined $other
Truth table0%0/3
A and B
A= defined $selfB= defined $other
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $self = __PACKAGE__->new(from => $self) unless eval {$self->isa(__PACKAGE__)}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $other = __PACKAGE__->new(from => $other) unless eval {$other->isa(__PACKAGE__)}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return undef unless ref($self) eq ref($other); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | return $self->as_string eq $other->as_string; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub cmp { | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my ($self, $other, @opts) = @_; | ||||||||||||||||||||||||||
|
Subroutine
cmp: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | croak 'Stray options passed' if scalar @opts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return 1 if !defined($self) && !defined($other); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self or defined $other
MC/DC0%0/2
defined $self or defined $other
defined $self
defined $other
Truth table0%0/3
A or B
A= defined $selfB= defined $other
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return undef unless defined($self) && defined($other); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self and defined $other
MC/DC0%0/2
defined $self and defined $other
defined $self
defined $other
Truth table0%0/3
A and B
A= defined $selfB= defined $other
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | $self = __PACKAGE__->new(from => $self) unless eval {$self->isa(__PACKAGE__)}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $other = __PACKAGE__->new(from => $other) unless eval {$other->isa(__PACKAGE__)}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||
| 96 | 0 | my $v = ref($self) cmp ref($other); | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | return $v if $v != 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||
| 101 | 0 | my $str_self = $self->as_string; | |||||||||||||||||||||||||||
| 102 | 0 | my $str_other = $other->as_string; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | return $str_self cmp $str_other; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | croak 'BUG!'; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | sub natural_language { | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
natural_language: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | ... | ||||||||||||||||||||||||||||
| 114 | 0 | } | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | sub displayname { | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my ($self, @opts) = @_; | ||||||||||||||||||||||||||
|
Subroutine
displayname: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return $self->as_string if scalar(@opts) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | { # work around the case we have no working $self->as(). | ||||||||||||||||||||||||||||
| 121 | 0 | my %x = @opts; | |||||||||||||||||||||||||||
| 122 | 0 | delete $x{default}; | |||||||||||||||||||||||||||
| 123 | 0 | delete $x{no_defaults}; | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | return $self->as_string if scalar(keys %x) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 0 | return $self->as('Data::Identifier')->displayname(@opts); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | sub ise { | ||||||||||||||||||||||||||||
| 131 | ... | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
ise: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # ---- Private helpers ---- | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | 1; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||