lib/Lingua/Generic/Interface/Word.pm

filter: Statementstmt 28.2% 22 / 78 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 41.1% 7 / 17 Podpod 100% 7 / 7 totaltotal 21.0% 36 / 171 CC 28 SCAR 40.4
CC
28
Cov
16%
new
90.0
eq
90.0
cmp
90.0
CRAP 56.7
↑ Summary blib/lib/Lingua/Generic/Interface/Word.pm »
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.02;
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
BranchTrueFalseTotal
unless defined $type 0 0 0
34 0 ▶ croak 'No value given' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
35 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
36  
37 0 ▶ if ($type eq 'from') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'from') { } 0 0 0
elsif ($type eq 'ise') { } 0 0 0
38 0 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 0 0 0
39 0 ▶ if ($value->isa(__PACKAGE__)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->isa(__PACKAGE__)) { } 0 0 0
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
BranchTrueFalseTotal
if ($type eq 'string') { } 0 0 0
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")
l!l&&r!l&&!r
000
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")
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if scalar @opts 0 0 0
71  
72 0 ▶ return 1 if !defined($self) && !defined($other);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self or defined $other 0 0 0
Condition0%0/3
defined $self or defined $other
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
73 0 ▶ return undef unless defined($self) && defined($other);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self and defined $other 0 0 0
Condition0%0/3
defined $self and defined $other
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
74  
75 0 ▶ $self = __PACKAGE__->new(from => $self) unless eval {$self->isa(__PACKAGE__)};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $self->isa(__PACKAGE__) } } 0 0 0
76 0 ▶ $other = __PACKAGE__->new(from => $other) unless eval {$other->isa(__PACKAGE__)};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $other->isa(__PACKAGE__) } } 0 0 0
77  
78 0 ▶ return undef unless ref($self) eq ref($other);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq ref $other 0 0 0
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
BranchTrueFalseTotal
if scalar @opts 0 0 0
88  
89 0 ▶ return 1 if !defined($self) && !defined($other);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self or defined $other 0 0 0
Condition0%0/3
defined $self or defined $other
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
90 0 ▶ return undef unless defined($self) && defined($other);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self and defined $other 0 0 0
Condition0%0/3
defined $self and defined $other
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
91  
92 0 ▶ $self = __PACKAGE__->new(from => $self) unless eval {$self->isa(__PACKAGE__)};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $self->isa(__PACKAGE__) } } 0 0 0
93 0 ▶ $other = __PACKAGE__->new(from => $other) unless eval {$other->isa(__PACKAGE__)};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $other->isa(__PACKAGE__) } } 0 0 0
94  
95 {
96 0 my $v = ref($self) cmp ref($other);
97 0 ▶ return $v if $v != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $v != 0 0 0 0
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
BranchTrueFalseTotal
if scalar @opts == 0 0 0 0
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
BranchTrueFalseTotal
if scalar keys %x == 0 0 0 0
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  
136  
137 # ---- Private helpers ----
138  
139 1 1;
140  
141 __END__
↑ Summary blib/lib/Lingua/Generic/Interface/Word.pm »