lib/Data/TagDB/WellKnown.pm

filter: Statementstmt 51.9% 27 / 52 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 45.4% 5 / 11 Podpod n/a totaltotal 42.1% 32 / 76 CC 6 SCAR 16.1
CC
6
Cov
43%
_known_provider
12.0
_call
6.0
_info
6.0
CRAP 5.0
« lib/Data/TagDB/Cache.pm ↑ Summary lib/Data/TagDB/Link.pm »
1 # Copyright (c) 2024-2026 Philipp Schafft
2  
3 # licensed under Artistic License 2.0 (see LICENSE file)
4  
5 # ABSTRACT: Work with Tag databases
6  
7 package Data::TagDB::WellKnown;
8  
9 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use parent qw(Data::TagDB::WeakBaseObject Data::Identifier::Interface::Known);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 our $VERSION = v0.16;
18  
19 4 my %wk_ise = (
20 # Hints as taken from tagdb-cgi-import;
21 also_shares_identifier => 'ddd60c5c-2934-404f-8f2d-fcb4da88b633',
22 tagname => 'bfae7574-3dae-425d-89b1-9c087c140c23',
23 uuid => '8be115d2-dc2f-4a98-91e1-a6e3075cbc31',
24 uri => 'a8d1637d-af19-49e9-9ef8-6bc1fbcf6439',
25 oid => 'd08dc905-bbf6-4183-b219-67723c3c8374',
26 wikidata_identifier => 'ce7aae1e-a210-4214-926a-0ebca56d77e3',
27 small_identifier => 'f87a38cb-fd13-4e15-866c-e49901adbec5',
28
29 # Used for additional features of source format:
30 important => 'e6135f02-28c1-4973-986c-ab7a6421c0a0',
31 no_direct => '05648b38-e73c-485c-b536-286ce0918193',
32 has_type => '7f265548-81dc-4280-9550-1bd0aa4bf748',
33 owned_by => '0ad7f760-8ee7-4367-97f2-ada06864325e',
34 implies => 'e48cd5c6-83d7-411e-9640-cb370f3502fc',
35 flagged_as => 'a1c478b5-0a85-4b5b-96da-d250db14a67c',
36 using_namespace => '3c9f40b4-2b98-44ce-b4dc-97649eb528ae',
37 for_type => 'bc2d2e7c-8aa4-420e-ac07-59c422034de9',
38  
39  
40 # Other stuff:
41 default_context => '6ba648c2-3657-47c2-8541-9b73c3a9b2b4',
42 default_type => '87c4892f-ae39-476e-8ed0-d9ed321dafe9',
43 default_encoding => '8440eabd-5d73-4679-8f06-abaa06cf04ac',
44 specialises => '923b43ae-a50e-4db3-8655-ed931d0dd6d4',
45 generalises => 'c8530d1b-d600-47e5-bc06-7b01416c79eb',
46 unicode_string => 'eacbf914-52cf-4192-a42c-8ecd27c85ee1',
47 utf_8_string_encoding => 'ec6cd46a-aef5-495d-830b-acb3347a34ec',
48 string_ise_uuid_encoding => 'b448c181-606e-460a-a8cd-8b60aeefe6bb',
49 string_ise_oid_encoding => '5af917c5-67fd-4019-be38-4093fde9b612',
50 ascii_uri_encoding => '61ae4438-e519-4af2-9286-afe8e03bf932',
51 colour_value => 'c64b5209-b975-4e59-9467-3c3b3f136b4e',
52 hex_rgb_encoding => '66d561ee-c06f-408f-a56c-a009439283bb',
53 ascii_decimal_integer_encoding => '84c0547d-4cce-4ece-8d47-57ca8b3a7763',
54 tagpool_tag_icontext => '922257e5-8fda-405c-aced-44a378acbdcf',
55 tagpool_type_icontext => '962af011-3e8e-4468-9b2e-9d4df93c0d9c',
56 has_colour_value => '4c771f95-9c12-4fc7-9cf6-1d5dee7024f9',
57 displaycolour => 'a7cfbcb0-45e2-46b9-8f60-646ab2c18b0b',
58 also_shares_colour => 'c6e83600-fd96-4b71-b216-21f0c4d73ca6',
59 primary_colour => 'd0421d68-8d37-4f78-b800-cae3e896bea5',
60 tag_links => 'd926eb95-6984-415f-8892-233c13491931',
61 tagpool_title => '361fda18-50ce-4421-b378-881179b0318a',
62 tagpool_description => 'ca33b058-b4ce-4059-9f0b-61ca0fd39c35',
63 tagpool_tagged_as => '703cbb5d-eb4a-4718-9e60-adbef6f71869',
64 subject_type => 'e8c156be-4fe7-4b13-b4fa-e207213caef8',
65 inverse_relation => '1eae4688-f66c-4c77-bc9b-bb38be88240a',
66 final_file_size => '1cd4a6c6-0d7c-48d1-81e7-4e8d41fdb45d',
67 final_file_hash => '79385945-0963-44aa-880a-bca4a42e9002',
68 final_file_encoding => '448c50a8-c847-4bc7-856e-0db5fea8f23b',
69 generator_request => 'ab573786-73bc-4f5c-9b03-24ef8a70ae45',
70 generated_by => '8efbc13b-47e5-4d92-a960-bd9a2efa9ccb',
71 namespace => 'd9bd807e-57cb-4736-9317-bf6bba5db48a',
72 generator => '8a1cb2d6-df2f-46db-89c3-a75168adebf6',
73 icon => 'caf11e36-d401-4521-8f10-f6b36125415c',
74 fetch_file_uri => '96674c6c-cf5e-40cd-af1e-63b86e741f4f',
75 specific_taglist => '03cadc6f-2609-4527-b296-2590d737e99a',
76 also_list_contains_also => '4c9656eb-c130-42b7-9348-a1fee3f42050',
77 encoding_file_name_extension => '3d737a5c-9389-4ae7-80ff-5f64c6b3b7f1',
78 x11_colour_name => '135032f7-cc60-46ee-8f64-1724c2a56fa2',
79 also_has_role => 'd2750351-aed7-4ade-aa80-c32436cc6030',
80 also_has_comment => '11d8962c-0a71-4d00-95ed-fa69182788a8',
81 also_has_description => '30710bdb-6418-42fb-96db-2278f3bfa17f',
82 also_has_proto_title => 'a845bfb7-130f-4f55-8a6d-ea3e5b1c2a09',
83 also_has_title => 'f7fd59e6-6727-4128-a0a7-cbc702dc09b8',
84 also_has_subtitle => 'df70343f-0c5f-4d76-93b6-4376f680f567',
85 gamebook_has_title => '1357f4c9-0419-4493-8d2c-97c6a40a9bc9',
86 ascii_code_point => 'f4b073ff-0b53-4034-b4e4-4affe5caf72c',
87 unicode_code_point => '5f167223-cc9c-4b2f-9928-9fe1b253b560',
88 proto_file => '52a516d0-25d8-47c7-a6ba-80983e576c54',
89 earth => '3c2c155f-a4a0-49f3-bdaf-7f61d25c6b8c',
90 language_tag_identifier => 'd0a4c6e2-ce2f-4d4c-b079-60065ac681f1', # sid=8
91 text_fragment => '6085f87e-4797-4bb2-b23d-85ff7edc1da0', # sid=19
92  
93  
94 # Boolans:
95 false => '6d34d4a1-8fbc-4e22-b3e0-d50f43d97cb1', # sid=45,sni=189
96 true => 'eb50b3dc-28be-4cfc-a9ea-bd7cee73aed5', # sid=46,sni=190
97  
98 # Number related:
99 unsigned_integer => 'dea3782c-6bcb-4ce9-8a39-f8dab399d75d',
100 has_prime_factor => '7f55c943-06a4-42e4-9c02-f8d2d00479a0',
101 zero => 'dd8e13d3-4b0f-5698-9afa-acf037584b20',
102 one => 'bd27669b-201e-51ed-9eb8-774ba7fef7ad',
103 two => '73415b5a-31fb-5b5a-bb82-8ea5eb3b12f7',
104 three => 'be6d8e00-a6c1-5c44-8ffc-f7393e14aa23',
105 four => '79422b2c-b6f6-547f-949f-0cba44fa69b7',
106 hrair => '7cb67873-33bc-4a93-b53f-072ce96c6f1a',
107  
108  
109 # Wikidata:
110 wd_unicode_character => '615351ce-3254-5684-a1ab-93f7c852e626', # P487
111 wd_sRGB_colour_hex_triplet => 'bcff702a-5d22-5e56-abaf-bda489b8438e', # P465
112  
113  
114 # SIRTX:
115 sirtx_logical => '5e80c7b7-215e-4154-b310-a5387045c336', # sni=129
116 sirtx_numerical_identifier => '039e0bb7-5dd3-40ee-a98c-596ff6cce405', # sid=113,sni=10
117 sirtx_function_number => 'd73b6550-5309-46ad-acc9-865c9261065b', # sni=127
118 sirtx_function_name => 'd690772e-de18-4714-aa4e-73fd35e8efc9', # sni=128
119  
120  
121 # Chat 0:
122 chat_0_word_identifier => '2c7e15ed-aa2f-4e2f-9a1d-64df0c85875a', # sid=112,sni=118
123 );
124  
125 4 my %aliases = (
126 taglist => 'specific_taglist',
127 );
128  
129 my %wk_tagname = (
130 # first some simple ones:
131 4 (map {$_ => $_ =~ tr/_/-/r}
132 # Taken from hints:
133 qw(also_shares_identifier tagname uuid uri oid wikidata_identifier small_identifier), # recommend
134 qw(important no_direct has_type owned_by implies flagged_as using_namespace for_type), # friendly
135  
136 # related to generators:
137 qw(generator_request generated_by namespace generator),
138  
139  
140 # Others:
141 qw(default_context),
142 qw(also_has_role),
143 qw(also_has_title),
144 qw(tagpool_title tagpool_description tagpool_tag_icontext tagpool_type_icontext),
145 qw(gamebook_has_title),
146 qw(icon fetch_file_uri),
147 qw(has_colour_value also_shares_colour primary_colour displaycolour),
148 qw(proto_file),
149  
150 # SIRTX:
151 qw(sirtx_numerical_identifier sirtx_logical sirtx_function_number sirtx_function_name),
152  
153 # Chat 0:
154 qw(chat_0_word_identifier),
155 )
156 );
157  
158 4 my %wk_sid = (
159 # Entries marked as "unassigned" are unassigned as of 2024-05-12Z.
160 also_shares_identifier => 1,
161 uuid => 2,
162 tagname => 3,
163 has_type => 4,
164 uri => 5,
165 oid => 6,
166 #unassigned 7
167 language_tag_identifier => 8,
168 wikidata_identifier => 9,
169 specialises => 10,
170 unicode_string => 11,
171 # integer 12
172 unsigned_integer => 13,
173 #unassigned 14
174 #unassigned 15
175 default_context => 16,
176 proto_file => 17,
177 final_file_size => 18,
178 text_fragment => 19,
179 also_list_contains_also => 20,
180 # proto-message 21
181 # proto-entity 22
182 # proxy-type 23
183 flagged_as => 24,
184 # marked_as 25
185 # roaraudio-error-number 26
186 small_identifier => 27,
187 also_has_role => 28,
188 # also-has-comment 29
189 # also-has-description 30
190 #unassigned 31
191 final_file_encoding => 32,
192 final_file_hash => 33,
193 # ...
194 false => 45,
195 true => 46,
196 # ...
197 chat_0_word_identifier => 112,
198 sirtx_numerical_identifier => 113,
199 );
200  
201 4 my %wk_logical = (
202 uuid => 'uuid',
203 tagname => 'tagname',
204 uri => 'uri',
205 oid => 'oid',
206 wikidata_identifier => 'wd',
207 small_identifier => 'sid',
208 sirtx_numerical_identifier => 'sni',
209 chat_0_word_identifier => 'chat0w',
210 sirtx_logical => 'logical',
211 true => 'true',
212 false => 'false',
213 );
214  
215 my %wk_default_type = (
216 24 (map {$_ => 'unicode_string'}
217 qw(also_has_title),
218 qw(tagpool_title tagpool_description tagpool_tag_icontext tagpool_type_icontext),
219 qw(gamebook_has_title),
220 ),
221 8 (map {$_ => 'uri'}
222 qw(icon fetch_file_uri),
223 ),
224 4 (map {$_ => 'colour_value'}
225 qw(has_colour_value also_shares_colour primary_colour displaycolour),
226 ),
227 );
228  
229 4 my %wk_default_encoding = (
230 uuid => 'string_ise_uuid_encoding',
231 oid => 'string_ise_oid_encoding',
232 uri => 'ascii_uri_encoding',
233 tagname => 'utf_8_string_encoding',
234 x11_colour_name => 'utf_8_string_encoding',
235 wikidata_identifier => 'utf_8_string_encoding',
236 small_identifier => 'ascii_decimal_integer_encoding',
237 unicode_string => 'utf_8_string_encoding',
238 colour_value => 'hex_rgb_encoding',
239 );
240  
241  
242 # ---- Implementation for Data::Identifier::Interface::Known ----
243  
244 0 ▶sub _known_provider {
Subroutine _known_provider: not called CC=3 SCAR=24.8
245 0 my ($pkg, $class, %opts) = @_;
246 0 ▶ croak 'Unsupported options passed' if scalar(keys %opts);
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 0 0
247 0 ▶ return ([values %wk_ise], rawtype => 'ise') if $class eq ':all';
Branch: 1 branch
BranchTrueFalseTotal
if $class eq ":all" 0 0 0
248 0 croak 'Unsupported class';
249 }
250  
251 # ---- Private helpers ----
252  
253 0 ▶sub DESTROY {} # So it's not autoloaded.
Subroutine DESTROY: not called CC=1 SCAR=0.0
254  
255 0 ▶sub _call {
Subroutine _call: not called CC=2 SCAR=17.9
256 0 my ($self, $name, $autocreate) = @_;
257  
258 0 ▶ if (defined $wk_ise{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wk_ise{$name}) { } 0 0 0
259 0 return $self->{db}->_tag_by_ise_cached($wk_ise{$name}, $autocreate)
260 } else {
261 0 confess 'Unknown well known: '.$name;
262 }
263 }
264  
265 0 ▶sub _list {
Subroutine _list: not called CC=1 SCAR=6.9
266 0 my ($self) = @_;
267 0 return keys %wk_ise;
268 }
269  
270 0 ▶sub _info {
Subroutine _info: not called CC=2 SCAR=17.9
271 0 my ($self, $name) = @_;
272 0 my %info;
273  
274 0 ▶ croak 'No such well known: '.$name unless defined $wk_ise{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wk_ise{$name} 0 0 0
275  
276 0 $info{ise} = $wk_ise{$name};
277 0 $info{tagname} = $wk_tagname{$name};
278 0 $info{sid} = $wk_sid{$name};
279 0 $info{logical} = $wk_logical{$name};
280 0 $info{default_type} = $wk_default_type{$name};
281 0 $info{default_encoding} = $wk_default_encoding{$name};
282  
283 0 return \%info;
284 }
285  
286 # ---- AUTOLOAD ----
287  
288 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
289 0 my ($self, @args) = @_;
290 0 our $AUTOLOAD;
291 0 my $name = $AUTOLOAD =~ s/^.*:://r;
292  
293 0 ▶ $name = $aliases{$name} // $name;
Condition0%0/3
$aliases{$name} // $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$aliases{$name} // $name
$aliases{$name} $name
Truth table0%0/3
A // B
A= $aliases{$name}B= $name
ABresult
1X1
011
000
294  
295 0 $self->_call($name, @args);
296 }
297  
298 4 1;
299  
300 __END__
« lib/Data/TagDB/Cache.pm ↑ Summary lib/Data/TagDB/Link.pm »