lib/Data/TagDB/Plugin/Person.pm

filter: Statementstmt 27.1% 75 / 276 Branchbran 0.0% 0 / 78 Conditioncond 0.0% 0 / 26 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 34.2% 13 / 38 Podpod 100% 1 / 1 totaltotal 20.5% 89 / 434 CC 64 SCAR 42.1
CC
64
Cov
20%
_displayspecies_like
210.0
_relatives
210.0
__ANON__
42.0
CRAP 67.5
↑ Summary
1 # Copyright (c) 2026 Philipp Schafft
2  
3 # licensed under Artistic License 2.0 (see LICENSE file)
4  
5 # ABSTRACT: Work with person data in TagDBs
6  
7 package Data::TagDB::Plugin::Person;
8  
9 1 ▶use v5.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Data::TagDB::Interface::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Data::TagDB::Relation;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Data::TagDB::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Data::TagDB::Tag;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Identifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Data::Identifier::Generate;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use parent 'Data::Identifier::Interface::Known';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 our $VERSION = v0.01.01;
25  
26 1 my @_wk;
27  
28 1 my %_normalised_sex_icons = (
29 1 ▶ male => "\N{MALE SIGN}",
Subroutine BEGIN: called CC=1 SCAR=0.0
30 female => "\N{FEMALE SIGN}",
31 hermaphrodite => "\N{MALE AND FEMALE SIGN}",
32 );
33  
34 {
35 1 my %sexes = (
36 # gender sex gender-or-sex
37 male => [
38 qw(3694d8ca-c969-5705-beca-01f17b1487e8 ae1072ef-0865-5104-b257-0d45441fa5e5 d642eff3-bee6-5d09-aea9-7c47b181dd83), # utag
39 Data::Identifier->new(wd => 'Q6581097'),
40 Data::Identifier->new(fc => 'Q18'),
41 ],
42 female => [
43 qw(25dfeb8e-ef9a-52a1-b5f1-073387734988 3c4b6cdf-f5a8-50d6-8a3a-b0c0975f7e69 db9b0db1-a451-59e8-aa3b-9994e683ded3), # utag
44 Data::Identifier->new(wd => 'Q6581072'),
45 Data::Identifier->new(fc => 'Q17'),
46 ],
47 gynomorph => [
48 qw(bb3c1e47-b251-51c8-9014-d66aa6df6139 a804402b-9ce8-55e4-b05c-9fec29d602a5 bd13b902-1506-537e-b1dd-15ef5fba70b2), # utag
49 ],
50 andromorph => [
51 qw(814f4fe5-74cd-57a7-9c28-4a912d639497 f334601b-0074-5e9c-8bad-3f4b9d2156a4 a41e15d5-a23c-5b2f-9268-294eb14d6573), # utag
52 ],
53 hermaphrodite => [
54 qw(310f2b49-73a8-5f27-aeaf-5f34bc8e583f 036c0fe8-5189-5134-99ec-0b1b05c7bbf4 643a9df0-c635-57f5-84f6-68c160899829), # utag
55 ],
56 );
57 1 foreach my $sex (keys %sexes) {
58 5 foreach my $ise (@{$sexes{$sex}}) {
59 19 my $tag = Data::Identifier->new(from => $ise)->register;
60 19 push(@_wk, $tag);
61  
62 19 $tag->userdata(__PACKAGE__, sex => $sex);
63 }
64 }
65 }
66  
67 {
68 1 my @humans = map {$_->register} (
69 Data::Identifier->new(uuid => 'dcf8f4f0-c15e-44bd-ad76-0d483079db16', tagname => 'human'),
70 Data::Identifier->new(wd => 'Q5'),
71 Data::Identifier->new(fc => 'Q7'),
72 );
73 1 push(@_wk, @humans);
74 1 $_->userdata(__PACKAGE__, is_human => 1) foreach @humans;
75 }
76  
77 {
78 1 my $wd_Q5 = Data::Identifier->new(wd => 'Q5');
79 1 my $fc_Q7 = Data::Identifier->new(fc => 'Q7');
80 1 my %extra_is = (
81 is_body => [qw(5501e545-f39a-4d62-9f65-792af6b0ccba), $wd_Q5, $fc_Q7],
82 is_character => [qw(a331f2c5-20e5-4aa2-b277-8e63fd03438d), $wd_Q5, $fc_Q7],
83 is_account => [qw(b72508ba-7fb9-42ae-b4cf-b850b53a16c2)],
84 is_legal_entity => [qw(f57f5e00-1d08-4731-b49b-c8316e23f06a)],
85 is_person => [qw(f6249973-59a9-47e2-8314-f7cf9a5f77bf), $wd_Q5, $fc_Q7],
86 );
87 1 my %ids;
88  
89 1 foreach my $is (keys %extra_is) {
90 5 foreach my $ise (@{$extra_is{$is}}) {
91 11 my $tag = Data::Identifier->new(from => $ise)->register;
92 11 $ids{$tag->ise} = $tag;
93 11 $tag->userdata(__PACKAGE__, $is => 1);
94 }
95 }
96  
97 1 push(@_wk, map {$_->register} values %ids);
98 }
99  
100 my %_wk = (
101 16 (map {$_->tagname =~ tr/-/_/r => $_} (
102 Data::Identifier->new(uuid => '7f265548-81dc-4280-9550-1bd0aa4bf748', tagname => 'has-type'),
103 Data::Identifier->new(uuid => 'd2750351-aed7-4ade-aa80-c32436cc6030', tagname => 'also-has-role'),
104 Data::Identifier->new(uuid => 'a942ba41-20e6-475e-a2c1-ce891f4ac920', tagname => 'also-identifies-as'),
105 Data::Identifier->new(uuid => 'ac14b422-e7eb-4e5b-bccd-ad5a65aeab96', tagname => 'also-is-identified-as'),
106 Data::Identifier->new(uuid => 'e48cd5c6-83d7-411e-9640-cb370f3502fc', tagname => 'implies'),
107 Data::Identifier->new(uuid => 'd926eb95-6984-415f-8892-233c13491931', tagname => 'tag-links'),
108 Data::Identifier->new(uuid => '115c1bcf-02cd-4a57-bd02-1d9f1ea8dd01', tagname => 'any-taxon'),
109 Data::Identifier->new(uuid => '69c01148-aab1-4c72-b857-6e53a301c96f', tagname => 'species'),
110 Data::Identifier->new(uuid => '63644280-affc-44fd-9911-bf36048a69e9', tagname => 'bodytype'),
111 Data::Identifier->new(uuid => 'bdf10f25-46ef-42fa-b588-dba84e6de9ef', tagname => 'anthro'),
112 Data::Identifier->new(uuid => 'ab573786-73bc-4f5c-9b03-24ef8a70ae45', tagname => 'generator_request'),
113 Data::Identifier->new(uuid => '806d6eec-ce92-464b-93f2-b83cfb73df03', tagname => 'relative-of'),
114 Data::Identifier->new(uuid => '5ecb4562-dad7-431d-94a6-d301dcea8d37', tagname => 'parent'),
115 Data::Identifier->new(uuid => '80034bca-2b6a-47b7-b7ec-a280103316bb', tagname => 'father'),
116 Data::Identifier->new(uuid => '9828fdbb-6c15-4fe9-86bc-11df79f692ed', tagname => 'mother'),
117 Data::Identifier->new(uuid => '1a9215b2-ad06-4f4f-a1e7-4cbb908f7c7c', tagname => 'child'),
118 #Data::Identifier->new(uuid => '', tagname => ''),
119 )),
120 9 (map {'wd_'.$_ => Data::Identifier->new(wd => $_)}
121 qw(Q729),
122 qw(P21 P31 P22 P25 P40 P1038 P3373 P3448),
123 ),
124 1 (map {'fc_'.$_ => Data::Identifier->new(fc => $_)}
125 qw(Q421315),
126 qw(P141 P142 P150 P154),
127 ),
128 );
129 1 push(@_wk, map {$_->register} values %_wk);
130  
131 1 my %_relatives_relations = (
132 relative => [[qw(relative_of wd_P22 wd_P25 wd_P40 wd_P1038 wd_P3373 wd_P3448)]],
133 father => [[qw(father wd_P22 fc_P141)]],
134 mother => [[qw(mother wd_P25 fc_P142)]],
135 parent => [[qw(parent wd_P22 wd_P25 wd_P3448 fc_P141 fc_P142)]],
136 child => [[qw(child wd_P40 fc_P150)], [qw(parent)]],
137 );
138  
139  
140 # Person attributes from SimCat:
141 # displaysex, displaysexicon, displayspecies, displaybodytype, relatives
142 # Also related:
143 # subtags, supertags
144 # Not included:
145 # dateing relevant for date of birth and date of death calculation
146  
147 # Helpers to be considered:
148 # is_male, is_female, is_human, is_animal
149  
150 # Notes on gender matching:
151 # FOAF: male, female
152 # vCard: M stands for "male", F stands for "female", O stands for "other", N stands for "none or not applicable", U stands for "unknown".
153 # GTE: .0: male, .1: female, .2: gynomorph, .3: andromorph, .4: herm, .12: other, .13: genderless, .14: undefined, .15: invalid
154 # SGTE: MFHCSmfhcs
155  
156 # Notes on body type:
157 # SGTE: FAfa
158  
159 # ---- Private helpers ----
160  
161 0 ▶sub plugin_attach {
Subroutine plugin_attach: not called CC=1 SCAR=6.9
Pod documented
162 0 my ($pkg, $db, $conf, %opts) = @_;
163  
164 return {
165 tag_attributes => {
166 displaysex => {
167 0 ▶ get => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
168 0 my ($tag) = @_;
169 0 my $sub = __SUB__;
170 0 my $db = $tag->db;
171 0 my $v;
172  
173 # New style:
174 0 ▶ $db->relation(tag => $tag, relation => [map {$db->tag_by_id($_)} @_wk{qw(also_identifies_as also_is_identified_as wd_P21 fc_P154)}])->foreach(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
175 0 my Data::TagDB::Relation $link = $_[0];
176 0 my Data::TagDB::Tag $related = $link->related;
177 0 my Data::Identifier $di = $related->as('Data::Identifier');
178 0 ▶ $v = $related if defined $di->userdata(__PACKAGE__, 'sex');
Branch: 1 branch
BranchTrueFalseTotal
if defined $di->userdata(__PACKAGE__, "sex") 0 0 0
179 0 });
180  
181 0 ▶ unless (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 0 0 0
182 # Old style, linked:
183 0 ▶ $db->relation(tag => $tag, relation => [map {$db->tag_by_id($_)} @_wk{qw(implies tag_links)}])->foreach(sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
184 0 my Data::TagDB::Relation $link = $_[0];
185 0 my Data::TagDB::Tag $related = $link->related;
186 0 my Data::Identifier $di = $related->as('Data::Identifier');
187 0 ▶ if ($di->userdata(__PACKAGE__, 'sex')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($di->userdata(__PACKAGE__, 'sex')) { } 0 0 0
elsif (not defined $v) { } 0 0 0
188 0 $v = $related;
189 } elsif (!defined $v) {
190 0 eval {$v = ($sub->($related))[0]->[0]};
191 }
192 0 });
193 }
194  
195 0 ▶ unless (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 0 0 0
196 0 foreach my $key (qw(body character)) {
197 0 ▶ my $subtag = $tag->get('Data::TagDB::Plugin::Person#'.$key, default => undef) // next;
Condition0%0/2
$tag->get('Data::TagDB::Plugin::Person#' . $key, "default", undef) // (next)
l!l
00
MC/DC0%0/1
$tag->get('Data::TagDB::Plugin::Person#' . $key, "default", undef) // (next)
$tag->get('Data::TagDB::Plugin::Person#' . $key, "default", undef)
Truth table0%0/2
A
A= $tag->get('Data::TagDB::Plugin::Person#' . $key, "default", undef)
Aresult
11
00
198 0 ▶ $v = $subtag->get('Data::TagDB::Plugin::Person#displaysex', default => undef) // next;
Condition0%0/2
$subtag->get("Data::TagDB::Plugin::Person#displaysex", "default", undef) // (next)
l!l
00
MC/DC0%0/1
$subtag->get("Data::TagDB::Plugin::Person#displaysex", "default", undef) // (next)
$subtag->get("Data::TagDB::Plugin::Person#displaysex", "default", undef)
Truth table0%0/2
A
A= $subtag->get("Data::TagDB::Plugin::Person#displaysex", "default", undef)
Aresult
11
00
199 0 last;
200 }
201 }
202  
203 0 return [$v], no_value => !defined($v);
204 },
205 },
206 displaysex_icon => {
207 0 ▶ get => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
208 0 my ($tag) = @_;
209 0 my $displaysex = $tag->get('Data::TagDB::Plugin::Person#displaysex', default => undef);
210 0 my $v;
211  
212 0 ▶ if (defined $displaysex) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $displaysex) 0 0 0
213 0 ▶ my $sex = $displaysex->as('Data::Identifier')->userdata(__PACKAGE__, 'sex') // '__UNKNOWN__';
Condition0%0/2
$displaysex->as("Data::Identifier")->userdata(__PACKAGE__, "sex") // "__UNKNOWN__"
l!l
00
MC/DC0%0/1
$displaysex->as("Data::Identifier")->userdata(__PACKAGE__, "sex") // "__UNKNOWN__"
$displaysex->as("Data::Identifier")->userdata(__PACKAGE__, "sex")
Truth table0%0/2
A
A= $displaysex->as("Data::Identifier")->userdata(__PACKAGE__, "sex")
Aresult
11
00
214  
215 0 ▶ if (defined($v = $_normalised_sex_icons{$sex})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($v = $_normalised_sex_icons{$sex})) { } 0 0 0
216 } else {
217 0 $v = $displaysex->icontext(default => undef);
218 }
219 }
220  
221 0 return [$v], no_value => !defined($v);
222 },
223 },
224 displayspecies => {
225 0 ▶ get => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
226 0 my ($tag) = @_;
227 0 return _displayspecies_like($tag, [@_wk{qw(any_taxon species wd_Q729 fc_Q421315)}], 'displayspecies');
228 },
229 },
230 is_human => {
231 0 ▶ get => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
232 0 my ($tag) = @_;
233 0 my $species = $tag->get('Data::TagDB::Plugin::Person#displayspecies', as => 'Data::Identifier', default => undef);
234  
235 0 ▶ return [undef], no_value => 1 unless defined $species;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $species 0 0 0
236  
237 0 return [!!$species->userdata(__PACKAGE__, 'is_human')];
238 },
239 },
240 displaybodytype => {
241 0 ▶ get => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
242 0 my ($tag) = @_;
243 0 my ($v, %extra) = _displayspecies_like($tag, [@_wk{qw(bodytype)}], 'displaybodytype');
244  
245 0 ▶ return $v, %extra unless $extra{no_value};
Branch: 1 branch
BranchTrueFalseTotal
unless $extra{"no_value"} 0 0 0
246  
247 0 ▶ if ($tag->get('Data::TagDB::Plugin::Person#is_human', default => undef)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->get("Data::TagDB::Plugin::Person#is_human", "default", undef)) 0 0 0
248 0 return [$tag->db->tag_by_id($_wk{anthro})];
249 }
250  
251 0 return [undef], no_value => 1;
252 },
253 },
254 entity => {
255 0 ▶ get => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
256 0 my ($tag) = @_;
257  
258 0 ▶ if ($tag->get('Data::TagDB::Plugin::Person#is_legal_entity') || $tag->get('Data::TagDB::Plugin::Person#is_person')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->get('Data::TagDB::Plugin::Person#is_legal_entity') or $tag->get('Data::TagDB::Plugin::Person#is_person')) { } 0 0 0
Condition0%0/3
$tag->get("Data::TagDB::Plugin::Person#is_legal_entity") or $tag->get("Data::TagDB::Plugin::Person#is_person")
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag->get("Data::TagDB::Plugin::Person#is_legal_entity") or $tag->get("Data::TagDB::Plugin::Person#is_person")
$tag->get("Data::TagDB::Plugin::Person#is_legal_entity") $tag->get("Data::TagDB::Plugin::Person#is_person")
Truth table0%0/3
A or B
A= $tag->get("Data::TagDB::Plugin::Person#is_legal_entity")B= $tag->get("Data::TagDB::Plugin::Person#is_person")
ABresult
1X1
011
000
259 0 return [$tag];
260 } else {
261 0 my $db = $tag->db;
262 0 my $v;
263  
264 0 ▶ $db->metadata(tag => $tag, relation => [map {$db->tag_by_id($_)} @_wk{qw(generator_request)}])->foreach(sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
265 0 my Data::TagDB::Metadata $link = $_[0];
266 0 ▶ my $parent = eval {$db->tag_by_id(uuid => $link->data_raw) } // return;
Condition0%0/2
eval { do { $db->tag_by_id("uuid", $link->data_raw) } } // (return)
l!l
00
MC/DC0%0/1
eval { do { $db->tag_by_id("uuid", $link->data_raw) } } // (return)
eval { do { $db->tag_by_id("uuid", $link->data_raw) } }
Truth table0%0/2
A
A= eval { do { $db->tag_by_id("uuid", $link->data_raw) } }
Aresult
11
00
267 0 ▶ $v = $parent if $parent->get('Data::TagDB::Plugin::Person#is_legal_entity') || $parent->get('Data::TagDB::Plugin::Person#is_person');
Branch: 1 branch
BranchTrueFalseTotal
if $parent->get("Data::TagDB::Plugin::Person#is_legal_entity") or $parent->get("Data::TagDB::Plugin::Person#is_person") 0 0 0
Condition0%0/3
$parent->get("Data::TagDB::Plugin::Person#is_legal_entity") or $parent->get("Data::TagDB::Plugin::Person#is_person")
l!l&&r!l&&!r
000
MC/DC0%0/2
$parent->get("Data::TagDB::Plugin::Person#is_legal_entity") or $parent->get("Data::TagDB::Plugin::Person#is_person")
$parent->get("Data::TagDB::Plugin::Person#is_legal_entity") $parent->get("Data::TagDB::Plugin::Person#is_person")
Truth table0%0/3
A or B
A= $parent->get("Data::TagDB::Plugin::Person#is_legal_entity")B= $parent->get("Data::TagDB::Plugin::Person#is_person")
ABresult
1X1
011
000
268 0 });
269  
270 0 ▶ unless (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 0 0 0
271 # Old style and links:
272 0 ▶ $db->relation(tag => $tag, relation => [map {$db->tag_by_id($_)} @_wk{qw(implies tag_links)}])->foreach(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
273 0 my Data::TagDB::Relation $link = $_[0];
274 0 my Data::TagDB::Tag $related = $link->related;
275 0 ▶ if (!defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $v) 0 0 0
276 0 eval {$v = $related->get('Data::TagDB::Plugin::Person#entity')};
277 }
278 0 });
279 }
280  
281 0 return [$v], no_value => !defined($v);
282 }
283 },
284 },
285 body => {
286 0 ▶ get => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
287 0 my ($tag) = @_;
288  
289 0 ▶ if ($tag->get('Data::TagDB::Plugin::Person#is_body')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->get('Data::TagDB::Plugin::Person#is_body')) { } 0 0 0
290 0 return [$tag];
291 } else {
292 0 my $v;
293  
294 0 eval {
295 0 my $entity = $tag->get('Data::TagDB::Plugin::Person#entity');
296 0 my $di = Data::Identifier::Generate->generic(
297 request => $entity,
298 style => 'tag-based',
299 namespace => '02513f26-d6ff-4107-98a8-2c9cb492115b',
300 generator => 'd511f370-0e49-42d5-ad18-bf280dc97e08',
301 );
302 0 $v = $tag->db->tag_by_id($di);
303 };
304  
305 0 ▶ return [$v] if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 0 0 0
306 }
307  
308 0 return [undef], no_value => 1;
309 },
310 },
311 character => {
312 0 ▶ get => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
313 0 my ($tag) = @_;
314  
315 0 ▶ if ($tag->get('Data::TagDB::Plugin::Person#is_character')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->get('Data::TagDB::Plugin::Person#is_character')) { } 0 0 0
316 0 return [$tag];
317 } else {
318 0 my $v;
319 0 eval {
320 0 my $entity = $tag->get('Data::TagDB::Plugin::Person#entity');
321 0 my $di = Data::Identifier::Generate->generic(
322 request => $entity,
323 style => 'tag-based',
324 namespace => 'bd3136b7-56f2-48a3-b206-fd2bd96551d5',
325 generator => 'bd1a1966-2e71-43cc-a7ce-f7a4547df450',
326 );
327 0 $v = $tag->db->tag_by_id($di);
328 };
329  
330 0 ▶ return [$v] if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 0 0 0
331 }
332  
333 0 return [undef], no_value => 1;
334 },
335 },
336 is_non_binary => {
337 0 ▶ get => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
338 0 my ($tag) = @_;
339 0 my $displaysex = $tag->get('Data::TagDB::Plugin::Person#displaysex', default => undef);
340  
341 0 ▶ if (defined $displaysex) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $displaysex) 0 0 0
342 0 my $sex = $displaysex->as('Data::Identifier')->userdata(__PACKAGE__, 'sex');
343 0 ▶ if (defined $sex) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sex) 0 0 0
344 0 ▶ return [$sex ne 'male' && $sex ne 'female'];
Condition0%0/3
$sex ne 'male' && $sex ne 'female'
!ll&&!rl&&r
000
MC/DC0%0/2
$sex ne 'male' && $sex ne 'female'
$sex ne 'male' $sex ne 'female'
Truth table0%0/3
A && B
A= $sex ne 'male'B= $sex ne 'female'
ABresult
0X0
100
111
345 }
346 }
347  
348 0 return [undef], no_value => 1;
349 },
350 },
351 0 ▶ (map {my $x = $_relatives_relations{$_}; $_ => {get => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
352 0 return _relatives($_[0], @{$x});
353 0 }}} keys %_relatives_relations),
354 0 ▶ (map {my $x = $_; 'is_'.$_ => {get => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
355 0 my ($tag) = @_;
356 0 my $displaysex = $tag->get('Data::TagDB::Plugin::Person#displaysex', default => undef);
357  
358 0 ▶ if (defined $displaysex) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $displaysex) 0 0 0
359 0 my $sex = $displaysex->as('Data::Identifier')->userdata(__PACKAGE__, 'sex');
360 0 ▶ if (defined $sex) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sex) 0 0 0
361 0 return [$sex eq $x];
362 }
363 }
364  
365 0 return [undef], no_value => 1;
366 0 }}} qw(male female gynomorph andromorph hermaphrodite)),
367 0 ▶ (map {my $x = $_; $_ => {get => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
368 0 my ($tag) = @_;
369 0 my $cl = $tag->cloudlet('roles');
370  
371 0 foreach my $role ($cl->entries) {
372 0 ▶ return [1] if $role->as('Data::Identifier')->userdata(__PACKAGE__, $x);
Branch: 1 branch
BranchTrueFalseTotal
if $role->as("Data::Identifier")->userdata(__PACKAGE__, $x) 0 0 0
373 }
374 0 return [0];
375 0 }}} qw(is_body is_character is_account is_legal_entity is_person)),
376 },
377 };
378 }
379  
380 0 ▶sub _known_provider {
Subroutine _known_provider: not called CC=3 SCAR=24.8
381 0 my ($pkg, $class, %opts) = @_;
382 0 ▶ croak 'Unsupported options passed' if scalar(keys %opts);
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 0 0
383 0 ▶ return (\@_wk) if $class eq ':all';
Branch: 1 branch
BranchTrueFalseTotal
if $class eq ":all" 0 0 0
384 0 croak 'Unsupported class';
385 }
386  
387 0 ▶sub _displayspecies_like {
Subroutine _displayspecies_like: not called CC=14 SCAR=53.5
388 0 my ($tag, $roles, $reqkey, $done) = @_;
389 0 my $db = $tag->db;
390 0 my $v;
391  
392 0 ▶ $done //= {};
Condition0%0/2
$done //= {}
l!l
00
MC/DC0%0/1
$done //= {}
$done
Truth table0%0/2
A
A= $done
Aresult
11
00
393 0 ▶ return [undef], no_value => 1 if $done->{$tag->dbid};
Branch: 1 branch
BranchTrueFalseTotal
if $$done{$tag->dbid} 0 0 0
394 0 $done->{$tag->dbid} = 1;
395  
396 0 $roles = [map {$_->as('Data::TagDB::Tag', db => $db)} @{$roles}];
397  
398 # New style:
399 0 ▶ $db->relation(tag => $tag, relation => [map {$db->tag_by_id($_)} @_wk{qw(also_identifies_as also_is_identified_as)}])->foreach(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
400 0 my Data::TagDB::Relation $link = $_[0];
401 0 my Data::TagDB::Tag $related = $link->related;
402 0 ▶ if ($related->has_role(any => $roles)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($related->has_role("any", $roles)) 0 0 0
403 0 $v = $related;
404 }
405 0 });
406  
407 0 ▶ unless (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 0 0 0
408 # Old style, linked:
409 0 ▶ $db->relation(tag => $tag, relation => [map {$db->tag_by_id($_)} @_wk{qw(implies tag_links)}])->foreach(sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
410 0 my Data::TagDB::Relation $link = $_[0];
411 0 my Data::TagDB::Tag $related = $link->related;
412 0 ▶ if ($related->has_role(any => $roles)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($related->has_role('any', $roles)) { } 0 0 0
elsif (not defined $v) { } 0 0 0
413 0 $v = $related
414 } elsif (!defined $v) {
415 0 eval {$v = (_displayspecies_like($related, $roles, $reqkey, $done))[0]->[0]};
416 }
417 0 });
418 }
419  
420 0 ▶ unless (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 0 0 0
421 # Wikidata style:
422 0 my $cl = $tag->cloudlet('roles');
423 outer:
424 0 foreach my $role ($cl->roots, $cl->entries) {
425 0 foreach my $req (@{$roles}) {
426 0 ▶ if (any {$req->dbid == $_->dbid} $role, $role->cloudlet('specialises')->entries) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $req->dbid == $_->dbid; } , $role, $role->cloudlet("specialises")->entries)) 0 0 0
427 0 $v = $role;
428 0 last outer;
429 }
430 }
431 }
432 }
433  
434 0 ▶ if (!defined($v) && defined($reqkey)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $v and defined $reqkey) 0 0 0
Condition0%0/3
not defined $v and defined $reqkey
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $v and defined $reqkey
not defined $v defined $reqkey
Truth table0%0/3
not(A) and B
A= not defined $vB= defined $reqkey
ABresult
0X0
100
111
435 0 foreach my $key (qw(body character)) {
436 0 ▶ my $subtag = $tag->get('Data::TagDB::Plugin::Person#'.$key, default => undef) // next;
Condition0%0/2
$tag->get('Data::TagDB::Plugin::Person#' . $key, "default", undef) // (next)
l!l
00
MC/DC0%0/1
$tag->get('Data::TagDB::Plugin::Person#' . $key, "default", undef) // (next)
$tag->get('Data::TagDB::Plugin::Person#' . $key, "default", undef)
Truth table0%0/2
A
A= $tag->get('Data::TagDB::Plugin::Person#' . $key, "default", undef)
Aresult
11
00
437 0 ▶ next if $subtag->dbid == $tag->dbid;
Branch: 1 branch
BranchTrueFalseTotal
if $subtag->dbid == $tag->dbid 0 0 0
438 0 ▶ $v = $subtag->get('Data::TagDB::Plugin::Person#'.$reqkey, default => undef) // next;
Condition0%0/2
$subtag->get('Data::TagDB::Plugin::Person#' . $reqkey, "default", undef) // (next)
l!l
00
MC/DC0%0/1
$subtag->get('Data::TagDB::Plugin::Person#' . $reqkey, "default", undef) // (next)
$subtag->get('Data::TagDB::Plugin::Person#' . $reqkey, "default", undef)
Truth table0%0/2
A
A= $subtag->get('Data::TagDB::Plugin::Person#' . $reqkey, "default", undef)
Aresult
11
00
439 0 last;
440 }
441 }
442  
443 0 return [$v], no_value => !defined($v);
444 }
445  
446 0 ▶sub _relatives {
Subroutine _relatives: not called CC=14 SCAR=53.5
447 0 my ($tag, $wk, $extra_inverse) = @_;
448 0 my $db = $tag->db;
449 0 my $inverse_relation = $db->wk->inverse_relation;
450 0 my @relations;
451 my @relations_inverse;
452 0 my %v;
453 0 my %self;
454  
455 {
456 0 my %relations;
457 0 foreach my $toplevel_di (@_wk{@{$wk}}) {
458 0 my $toplevel = $db->tag_by_id($toplevel_di);
459 0 foreach my $subtag ($toplevel, $toplevel->cloudlet('generalises')->entries) {
460 0 $relations{$subtag->dbid} = $subtag;
461 }
462 }
463 0 @relations = values %relations;
464 }
465  
466 {
467 0 my %relations_inverse;
468  
469 0 foreach my $relation (@relations) {
470 0 $relations_inverse{$_->dbid} = $_ foreach $db->relation(tag => $relation, relation => $inverse_relation)->collect('related');
471 }
472  
473 0 ▶ if (defined $extra_inverse) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extra_inverse) 0 0 0
474 0 foreach my $toplevel_di (@_wk{@{$extra_inverse}}) {
475 0 my $toplevel = $db->tag_by_id($toplevel_di);
476 0 foreach my $subtag ($toplevel, $toplevel->cloudlet('generalises')->entries) {
477 0 $relations_inverse{$subtag->dbid} = $subtag;
478 }
479 }
480 }
481  
482 0 @relations_inverse = values %relations_inverse;
483 }
484  
485 0 foreach my $superbasetag ($tag, $db->relation(tag => $tag, relation => [map {$db->tag_by_id($_)} @_wk{qw(implies tag_links)}])->collect('tag')) {
486 0 foreach my $basetag (
487 $superbasetag,
488 0 eval {$superbasetag->get('Data::TagDB::Plugin::Person#body', default => undef)},
489 0 eval {$superbasetag->get('Data::TagDB::Plugin::Person#character', default => undef)},
490 ) {
491 0 ▶ next unless defined $basetag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $basetag 0 0 0
492 0 ▶ next if $self{$basetag->dbid};
Branch: 1 branch
BranchTrueFalseTotal
if $self{$basetag->dbid} 0 0 0
493 0 $self{$basetag->dbid} = 1;
494 0 ▶ $db->relation(tag => $basetag, relation => \@relations)->foreach(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
495 0 my Data::TagDB::Relation $link = $_[0];
496 0 my Data::TagDB::Tag $related = $link->related;
497 0 $v{$related->dbid} = $related;
498 0 ▶ }) if scalar @relations;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @relations 0 0 0
499 0 ▶ $db->relation(related => $basetag, relation => \@relations_inverse)->foreach(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
500 0 my Data::TagDB::Relation $link = $_[0];
501 0 my Data::TagDB::Tag $related = $link->tag;
502 0 $v{$related->dbid} = $related;
503 0 ▶ }) if scalar @relations_inverse;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @relations_inverse 0 0 0
504 }
505 }
506  
507 0 return [values %v];
508 }
509  
510 1 1;
511  
512 __END__
↑ Summary