Identifier.pm

filter: Statementstmt 54.9% 326 / 593 Branchbran 37.5% 148 / 394 Conditioncond 32.7% 104 / 318 MC/DCmcdc 14.0% 26 / 185 Subroutinesub 65.8% 27 / 41 Podpod 100% 23 / 23 totaltotal 42.0% 654 / 1554 CC 307 SCAR 70.6
CC
307
Cov
44%
new
2327.6
as
2276.5
cmp
182.0
CRAP 1167.1
↑ Summary Identifier/Generate.pm »
1 #!/usr/bin/perl -w
2  
3 # Copyright (c) 2023-2026 Philipp Schafft
4  
5 # licensed under Artistic License 2.0 (see LICENSE file)
6  
7 # ABSTRACT: format independent identifier object
8  
9  
10 package Data::Identifier;
11  
12 8 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 8 ▶use parent qw(Data::Identifier::Interface::Known Data::Identifier::Interface::Userdata Data::Identifier::Interface::Simple);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶use Math::BigInt lib => 'GMP';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 8 our $VERSION = v0.38;
23  
24 8 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
25 8 RE_UUID => qr/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}\z/,
26 RE_OID => qr/^[0-2](?:\.(?:0|[1-9][0-9]*))+\z/,
27 RE_URI => qr/^[a-zA-Z][a-zA-Z0-9\+\.\-]+:/,
28 RE_UINT => qr/^(?:0|[1-9][0-9]*)\z/,
29 RE_SINT => qr/^(?:0|-?[1-9][0-9]*)\z/,
30 RE_QID => qr/^[QPL][1-9][0-9]*\z/,
31 RE_DOI => qr/^10\.[1-9][0-9]+(?:\.[0-9]+)*\/./,
32 RE_GTIN => qr/^[0-9]{8}(?:[0-9]{4,6})?\z/,
33 RE_UNICODE => qr/^U\+([0-9A-F]{4,7})\z/,
34 RE_SIMPLE_TAG => qr/^[^\p{upper case}\s:]+\z/,
35 8 };
36  
37 8 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
38 8 WK_NULL => '00000000-0000-0000-0000-000000000000', # NULL, undef, ...
39 WK_UUID => '8be115d2-dc2f-4a98-91e1-a6e3075cbc31', # uuid
40 WK_OID => 'd08dc905-bbf6-4183-b219-67723c3c8374', # oid
41 WK_URI => 'a8d1637d-af19-49e9-9ef8-6bc1fbcf6439', # uri
42 WK_SID => 'f87a38cb-fd13-4e15-866c-e49901adbec5', # small-identifier
43 WK_WD => 'ce7aae1e-a210-4214-926a-0ebca56d77e3', # wikidata-identifier
44 WK_GTIN => '82d529be-0f00-4b4f-a43f-4a22de5f5312', # gtin
45 WK_IBAN => 'b1418262-6bc9-459c-b4b0-a054d77db0ea', # iban
46 WK_BIC => 'c8a3a132-f160-473c-b5f3-26a748f37e62', # bic
47 WK_DOI => '931f155e-5a24-499b-9fbb-ed4efefe27fe', # doi
48 WK_FC => 'd576b9d1-47d4-43ae-b7ec-bbea1fe009ba', # factgrid-identifier
49 WK_UNICODE_CP => '5f167223-cc9c-4b2f-9928-9fe1b253b560', # unicode-code-point
50 WK_SNI => '039e0bb7-5dd3-40ee-a98c-596ff6cce405', # sirtx-numerical-identifier
51 WK_HDI => 'f8eb04ef-3b8a-402c-ad7c-1e6814cb1998', # host-defined-identifier
52 WK_UDI => '05af99f9-4578-4b79-aabe-946d8e6f5888', # user-defined-identifier
53 WK_CHAT0W => '2c7e15ed-aa2f-4e2f-9a1d-64df0c85875a', # chat-0-word-identifier
54  
55 NS_WD => '9e10aca7-4a99-43ac-9368-6cbfa43636df', # Wikidata-namespace
56 NS_FC => '6491f7a9-0b29-4ef1-992c-3681cea18182', # factgrid-namespace
57 NS_INT => '5dd8ddbb-13a8-4d6c-9264-36e6dd6f9c99', # integer-namespace
58 NS_DATE => 'fc43fbba-b959-4882-b4c8-90a288b7d416', # gregorian-date-namespace
59 NS_GTIN => 'd95d8b1f-5091-4642-a6b0-a585313915f1', # gtin-namespace
60 NS_UNICODE_CP => '132aa723-a373-48bf-a88d-69f1e00f00cf', # unicode-character-namespace
61 8 };
62  
63 # Features:
64 8 my $enabled_oid = 1;
65  
66 8 my %uuid_to_uriid_org = (
67 WK_UUID() => 'uuid',
68 WK_OID() => 'oid',
69 WK_URI() => 'uri',
70 WK_SID() => 'sid',
71 WK_GTIN() => 'gtin',
72 WK_WD() => 'wikidata-identifier',
73 );
74  
75 8 my %uuid_org_to_uuid = map {$uuid_to_uriid_org{$_} => $_} keys %uuid_to_uriid_org;
76  
77 8 my $well_known_uuid = __PACKAGE__->new(ise => WK_UUID, validate => RE_UUID);
78  
79 8 my %well_known = (
80 uuid => $well_known_uuid,
81 oid => __PACKAGE__->new($well_known_uuid => WK_OID, validate => RE_OID),
82 uri => __PACKAGE__->new($well_known_uuid => WK_URI, validate => RE_URI),
83 sid => __PACKAGE__->new($well_known_uuid => WK_SID, validate => RE_UINT),
84 sni => __PACKAGE__->new($well_known_uuid => WK_SNI, validate => RE_UINT),
85 wd => __PACKAGE__->new($well_known_uuid => WK_WD, validate => RE_QID, generate => 'id-based'),
86 fc => __PACKAGE__->new($well_known_uuid => WK_FC, validate => RE_QID, generate => 'id-based'),
87 gtin => __PACKAGE__->new($well_known_uuid => WK_GTIN, validate => RE_GTIN, generate => 'id-based'),
88 iban => __PACKAGE__->new($well_known_uuid => WK_IBAN),
89 bic => __PACKAGE__->new($well_known_uuid => WK_BIC),
90 doi => __PACKAGE__->new($well_known_uuid => WK_DOI, validate => RE_DOI),
91  
92 # Unofficial, not part of public API:
93 # Also used by Data::Identifier::Util!
94 unicodecp => __PACKAGE__->new($well_known_uuid => WK_UNICODE_CP, validate => RE_UNICODE, generate => 'id-based'),
95 chat0w => __PACKAGE__->new($well_known_uuid => WK_CHAT0W, validate => RE_UINT),
96  
97 hdi => __PACKAGE__->new($well_known_uuid => WK_HDI, validate => RE_UINT),
98 udi => __PACKAGE__->new($well_known_uuid => WK_UDI, validate => RE_UINT),
99 null => __PACKAGE__->new($well_known_uuid => WK_NULL),
100 );
101  
102 8 my %registered;
103  
104 8 $_->register foreach values %well_known;
105  
106 # Refill with namespaces:
107 {
108 8 my %ns = (
109 wd => NS_WD,
110 fc => NS_FC,
111 gtin => NS_GTIN,
112 unicodecp => NS_UNICODE_CP,
113 );
114  
115 8 foreach my $wk (keys %ns) {
116 32 ▶ $well_known{$wk}->{namespace} //= Data::Identifier->new(ise => $ns{$wk})->register;
Condition33%1/3
$well_known{$wk}{"namespace"} //= "Data::Identifier"->new("ise", $ns{$wk})->register
l!l&&r!l&&!r
0320
MC/DC0%0/2
$well_known{$wk}{"namespace"} //= "Data::Identifier"->new("ise", $ns{$wk})->register
$well_known{$wk}{"namespace"} "Data::Identifier"->new("ise", $ns{$wk})->register
Truth table33%1/3
A //= B
A= $well_known{$wk}{"namespace"}B= "Data::Identifier"->new("ise", $ns{$wk})->register
ABresult
1X1
011
000
117 }
118 }
119  
120 # Refill with sids:
121 {
122 8 my %wk_sids = (
123 WK_NULL() => 0, # NULL
124 'ddd60c5c-2934-404f-8f2d-fcb4da88b633' => 1, # also-shares-identifier
125 WK_UUID() => 2,
126 'bfae7574-3dae-425d-89b1-9c087c140c23' => 3, # tagname
127 '7f265548-81dc-4280-9550-1bd0aa4bf748' => 4, # has-type
128 WK_URI() => 5,
129 WK_OID() => 6,
130 # Unassigned: 7
131 'd0a4c6e2-ce2f-4d4c-b079-60065ac681f1' => 8, # language-tag-identifier
132 WK_WD() => 9,
133 '923b43ae-a50e-4db3-8655-ed931d0dd6d4' => 10, # specialises
134 'eacbf914-52cf-4192-a42c-8ecd27c85ee1' => 11, # unicode-string
135 '928d02b0-7143-4ec9-b5ac-9554f02d3fb1' => 12, # integer
136 'dea3782c-6bcb-4ce9-8a39-f8dab399d75d' => 13, # unsigned-integer
137 # Unassigned: 14, 15
138 '6ba648c2-3657-47c2-8541-9b73c3a9b2b4' => 16, # default-context
139 '52a516d0-25d8-47c7-a6ba-80983e576c54' => 17, # proto-file
140 '1cd4a6c6-0d7c-48d1-81e7-4e8d41fdb45d' => 18, # final-file-size
141 '6085f87e-4797-4bb2-b23d-85ff7edc1da0' => 19, # text-fragment
142 '4c9656eb-c130-42b7-9348-a1fee3f42050' => 20, # also-list-contains-also
143 '298ef373-9731-491d-824d-b2836250e865' => 21, # proto-message
144 '7be4d8c7-6a75-44cc-94f7-c87433307b26' => 22, # proto-entity
145 '65bb36f2-b558-48af-8512-bca9150cca85' => 23, # proxy-type
146 'a1c478b5-0a85-4b5b-96da-d250db14a67c' => 24, # flagged-as
147 '59cfe520-ba32-48cc-b654-74f7a05779db' => 25, # marked-as
148 '2bffc55d-7380-454e-bd53-c5acd525d692' => 26, # roaraudio-error-number
149 WK_SID() => 27,
150 'd2750351-aed7-4ade-aa80-c32436cc6030' => 28, # also-has-role
151 '11d8962c-0a71-4d00-95ed-fa69182788a8' => 29, # also-has-comment
152 '30710bdb-6418-42fb-96db-2278f3bfa17f' => 30, # also-has-description
153 # Unassigned: 31
154 '448c50a8-c847-4bc7-856e-0db5fea8f23b' => 32, # final-file-encoding
155 '79385945-0963-44aa-880a-bca4a42e9002' => 33, # final-file-hash
156 '3fde5688-6e34-45e9-8f33-68f079b152c8' => 34, # SEEK_SET
157 'bc598c52-642e-465b-b079-e9253cd6f190' => 35, # SEEK_CUR
158 '06aff30f-70e8-48b4-8b20-9194d22fc460' => 36, # SEEK_END
159 '59a5691a-6a19-4051-bc26-8db82c019df3' => 37, # inode
160 WK_CHAT0W() => 112, # chat-0-word-identifier
161 WK_SNI() => 113, # sirtx-numerical-identifier
162 WK_GTIN() => 160,
163 );
164  
165 8 foreach my $ise (keys %wk_sids) {
166 296 my $identifier = __PACKAGE__->new(ise => $ise);
167 296 ▶ $identifier->{id_cache} //= {};
Condition100%2/2
$identifier->{"id_cache"} //= {}
l!l
72224
MC/DC100%1/1
$identifier->{"id_cache"} //= {}
$identifier->{"id_cache"}
Truth table100%2/2
A
A= $identifier->{"id_cache"}
Aresult
11
00
168 296 ▶ $identifier->{id_cache}->{WK_SID()} //= $wk_sids{$ise};
Condition33%1/3
$identifier->{"id_cache"}{"f87a38cb-fd13-4e15-866c-e49901adbec5"} //= $wk_sids{$ise}
l!l&&r!l&&!r
02960
MC/DC0%0/2
$identifier->{"id_cache"}{"f87a38cb-fd13-4e15-866c-e49901adbec5"} //= $wk_sids{$ise}
$identifier->{"id_cache"}{"f87a38cb-fd13-4e15-866c-e49901adbec5"} $wk_sids{$ise}
Truth table33%1/3
A //= B
A= $identifier->{"id_cache"}{"f87a38cb-fd13-4e15-866c-e49901adbec5"}B= $wk_sids{$ise}
ABresult
1X1
011
000
169 296 $identifier->register; # re-register
170 }
171 }
172  
173 # Refill with snis:
174 {
175 8 my %wk_snis = (
176 WK_NULL() => 0, # NULL
177 '039e0bb7-5dd3-40ee-a98c-596ff6cce405' => 10, # sirtx-numerical-identifier
178 'f87a38cb-fd13-4e15-866c-e49901adbec5' => 115, # small-identifier
179 '2bffc55d-7380-454e-bd53-c5acd525d692' => 116, # roaraudio-error-number
180 WK_CHAT0W() => 118, # chat-0-word-identifier
181 WK_UUID() => 119,
182 WK_OID() => 120,
183 WK_URI() => 121,
184 WK_WD() => 123,
185 );
186  
187 8 foreach my $ise (keys %wk_snis) {
188 72 my $identifier = __PACKAGE__->new(ise => $ise);
189 72 ▶ $identifier->{id_cache} //= {};
Condition50%1/2
$identifier->{"id_cache"} //= {}
l!l
720
MC/DC0%0/1
$identifier->{"id_cache"} //= {}
$identifier->{"id_cache"}
Truth table50%1/2
A
A= $identifier->{"id_cache"}
Aresult
11
00
190 72 ▶ $identifier->{id_cache}->{WK_SNI()} //= $wk_snis{$ise};
Condition33%1/3
$identifier->{"id_cache"}{"039e0bb7-5dd3-40ee-a98c-596ff6cce405"} //= $wk_snis{$ise}
l!l&&r!l&&!r
0720
MC/DC0%0/2
$identifier->{"id_cache"}{"039e0bb7-5dd3-40ee-a98c-596ff6cce405"} //= $wk_snis{$ise}
$identifier->{"id_cache"}{"039e0bb7-5dd3-40ee-a98c-596ff6cce405"} $wk_snis{$ise}
Truth table33%1/3
A //= B
A= $identifier->{"id_cache"}{"039e0bb7-5dd3-40ee-a98c-596ff6cce405"}B= $wk_snis{$ise}
ABresult
1X1
011
000
191 72 $identifier->register; # re-register
192 }
193 }
194  
195 # Update NULL:
196 {
197 8 my $identifier = __PACKAGE__->new(uuid => WK_NULL);
198 8 ▶ $identifier->{id_cache} //= {};
Condition50%1/2
$identifier->{"id_cache"} //= {}
l!l
80
MC/DC0%0/1
$identifier->{"id_cache"} //= {}
$identifier->{"id_cache"}
Truth table50%1/2
A
A= $identifier->{"id_cache"}
Aresult
11
00
199 8 foreach my $type (WK_HDI, WK_CHAT0W) {
200 16 ▶ $identifier->{id_cache}->{$type} //= 0;
Condition50%1/2
$identifier->{"id_cache"}{$type} //= 0
l!l
016
MC/DC0%0/1
$identifier->{"id_cache"}{$type} //= 0
$identifier->{"id_cache"}{$type}
Truth table50%1/2
A
A= $identifier->{"id_cache"}{$type}
Aresult
11
00
201 }
202 8 $identifier->register;
203 }
204  
205 # Some extra tags such as namespaces:
206 8 foreach my $ise (NS_WD, NS_INT, NS_DATE) {
207 24 my $identifier = __PACKAGE__->new(ise => $ise);
208 24 $identifier->register; # re-register
209 }
210  
211 # Refill with tagnames
212 {
213 8 my %tagnames = (
214 WK_NULL() => 'null',
215 WK_UUID() => 'uuid',
216 WK_OID() => 'oid',
217 WK_URI() => 'uri',
218 WK_SID() => 'small-identifier',
219 WK_WD() => 'wikidata-identifier',
220 WK_GTIN() => 'gtin',
221 WK_IBAN() => 'iban',
222 WK_BIC() => 'bic',
223 WK_DOI() => 'doi',
224 WK_FC() => 'factgrid-identifier',
225 WK_UNICODE_CP() => 'unicode-code-point',
226 WK_SNI() => 'sirtx-numerical-identifier',
227 WK_HDI() => 'host-defined-identifier',
228 WK_UDI() => 'user-defined-identifier',
229 WK_CHAT0W() => 'chat-0-word-identifier',
230 NS_WD() => 'Wikidata-namespace',
231 NS_FC() => 'factgrid-namespace',
232 NS_INT() => 'integer-namespace',
233 NS_DATE() => 'gregorian-date-namespace',
234 NS_UNICODE_CP() => 'unicode-character-namespace',
235  
236 'ddd60c5c-2934-404f-8f2d-fcb4da88b633' => 'also-shares-identifier',
237 'bfae7574-3dae-425d-89b1-9c087c140c23' => 'tagname',
238 '7f265548-81dc-4280-9550-1bd0aa4bf748' => 'has-type',
239 'd0a4c6e2-ce2f-4d4c-b079-60065ac681f1' => 'language-tag-identifier',
240 '923b43ae-a50e-4db3-8655-ed931d0dd6d4' => 'specialises',
241 'eacbf914-52cf-4192-a42c-8ecd27c85ee1' => 'unicode-string',
242 '928d02b0-7143-4ec9-b5ac-9554f02d3fb1' => 'integer',
243 'dea3782c-6bcb-4ce9-8a39-f8dab399d75d' => 'unsigned-integer',
244 '6ba648c2-3657-47c2-8541-9b73c3a9b2b4' => 'default-context',
245 '52a516d0-25d8-47c7-a6ba-80983e576c54' => 'proto-file',
246 '1cd4a6c6-0d7c-48d1-81e7-4e8d41fdb45d' => 'final-file-size',
247 '6085f87e-4797-4bb2-b23d-85ff7edc1da0' => 'text-fragment',
248 '4c9656eb-c130-42b7-9348-a1fee3f42050' => 'also-list-contains-also',
249 '298ef373-9731-491d-824d-b2836250e865' => 'proto-message',
250 '7be4d8c7-6a75-44cc-94f7-c87433307b26' => 'proto-entity',
251 '65bb36f2-b558-48af-8512-bca9150cca85' => 'proxy-type',
252 'a1c478b5-0a85-4b5b-96da-d250db14a67c' => 'flagged-as',
253 '59cfe520-ba32-48cc-b654-74f7a05779db' => 'marked-as',
254 '2bffc55d-7380-454e-bd53-c5acd525d692' => 'roaraudio-error-number',
255 'd2750351-aed7-4ade-aa80-c32436cc6030' => 'also-has-role',
256 '11d8962c-0a71-4d00-95ed-fa69182788a8' => 'also-has-comment',
257 '30710bdb-6418-42fb-96db-2278f3bfa17f' => 'also-has-description',
258 '448c50a8-c847-4bc7-856e-0db5fea8f23b' => 'final-file-encoding',
259 '79385945-0963-44aa-880a-bca4a42e9002' => 'final-file-hash',
260 '3fde5688-6e34-45e9-8f33-68f079b152c8' => 'SEEK_SET',
261 'bc598c52-642e-465b-b079-e9253cd6f190' => 'SEEK_CUR',
262 '06aff30f-70e8-48b4-8b20-9194d22fc460' => 'SEEK_END',
263 '59a5691a-6a19-4051-bc26-8db82c019df3' => 'inode',
264 '53863a15-68d4-448d-bd69-a9b19289a191' => 'unsigned-integer-generator',
265 'e8aa9e01-8d37-4b4b-8899-42ca0a2a906f' => 'signed-integer-generator',
266 'd74f8c35-bcb8-465c-9a77-01010e8ed25c' => 'unicode-character-generator',
267 '55febcc4-6655-4397-ae3d-2353b5856b34' => 'rgb-colour-generator',
268 '97b7f241-e1c5-4f02-ae3c-8e31e501e1dc' => 'date-generator',
269 '19659233-0a22-412c-bdf1-8ee9f8fc4086' => 'multiplicity-generator',
270 '5ec197c3-1406-467c-96c7-4b1a6ec2c5c9' => 'minimum-multiplicity-generator',
271 );
272  
273 8 foreach my $ise (keys %tagnames) {
274 448 my $identifier = __PACKAGE__->new(ise => $ise);
275 448 ▶ $identifier->{tagname} //= [$tagnames{$ise}];
Condition50%1/2
$identifier->{"tagname"} //= [$tagnames{$ise}]
l!l
0448
MC/DC0%0/1
$identifier->{"tagname"} //= [$tagnames{$ise}]
$identifier->{"tagname"}
Truth table50%1/2
A
A= $identifier->{"tagname"}
Aresult
11
00
276 448 $identifier->register; # re-register
277 }
278 }
279  
280 {
281 # ISE -> namespace
282 8 my %namespaces_uint = (
283 '4a7fc2e2-854b-42ec-b24f-c7fece371865' => 'ac59062c-6ba2-44de-9f54-09e28f2c0b5c', # e621-post-identifier: e621-post-namespace
284 'a0a4fae2-be6f-4a51-8326-6110ba845a16' => '69b7ff38-ca78-43a8-b9ea-66cb02312eef', # e621-pool-identifier: e621-pool-namespace
285 '6e3590b6-2a0c-4850-a71f-8ba196a52280' => 'b96e5d94-0767-40fa-9864-5977eb507ae0', # danbooru2chanjp-post-identifier: danbooru2chanjp-post-namespace
286 );
287 8 my %namespaces_sint = (
288 '2bffc55d-7380-454e-bd53-c5acd525d692' => '744eaf4e-ae93-44d8-9ab5-744105222da6', # roaraudio-error-number: roaraudio-error-namespace
289 );
290 8 my %namespaces_simple_tag = (
291 '6fe0dbf0-624b-48b3-b558-0394c14bad6a' => '3623de4d-0dd4-4236-946a-2613467d50f1', # e621tag: e621tag-namespace
292 'c5632c60-5da2-41af-8b60-75810b622756' => '93f2c36b-8cb6-4f2c-924b-98188f224235', # danbooru2chanjp-tag: danbooru2chanjp-tag-namespace
293 );
294  
295 8 foreach my $ise (keys %namespaces_uint) {
296 24 my $identifier = __PACKAGE__->new(ise => $ise);
297 24 ▶ $identifier->{namespace} //= __PACKAGE__->new(ise => $namespaces_uint{$ise});
Condition33%1/3
$identifier->{"namespace"} //= __PACKAGE__->new("ise", $namespaces_uint{$ise})
l!l&&r!l&&!r
0240
MC/DC0%0/2
$identifier->{"namespace"} //= __PACKAGE__->new("ise", $namespaces_uint{$ise})
$identifier->{"namespace"} __PACKAGE__->new("ise", $namespaces_uint{$ise})
Truth table33%1/3
A //= B
A= $identifier->{"namespace"}B= __PACKAGE__->new("ise", $namespaces_uint{$ise})
ABresult
1X1
011
000
298 24 ▶ $identifier->{validate} //= RE_UINT;
Condition50%1/2
$identifier->{"validate"} //= qr/^(?:0|[1-9][0-9]*)\z/u
l!l
024
MC/DC0%0/1
$identifier->{"validate"} //= qr/^(?:0|[1-9][0-9]*)\z/u
$identifier->{"validate"}
Truth table50%1/2
A
A= $identifier->{"validate"}
Aresult
11
00
299 24 ▶ $identifier->{generate} //= 'id-based';
Condition50%1/2
$identifier->{"generate"} //= "id-based"
l!l
024
MC/DC0%0/1
$identifier->{"generate"} //= "id-based"
$identifier->{"generate"}
Truth table50%1/2
A
A= $identifier->{"generate"}
Aresult
11
00
300 24 $identifier->register; # re-register
301 }
302  
303 8 foreach my $ise (keys %namespaces_sint) {
304 8 my $identifier = __PACKAGE__->new(ise => $ise);
305 8 ▶ $identifier->{namespace} //= __PACKAGE__->new(ise => $namespaces_sint{$ise});
Condition33%1/3
$identifier->{"namespace"} //= __PACKAGE__->new("ise", $namespaces_sint{$ise})
l!l&&r!l&&!r
080
MC/DC0%0/2
$identifier->{"namespace"} //= __PACKAGE__->new("ise", $namespaces_sint{$ise})
$identifier->{"namespace"} __PACKAGE__->new("ise", $namespaces_sint{$ise})
Truth table33%1/3
A //= B
A= $identifier->{"namespace"}B= __PACKAGE__->new("ise", $namespaces_sint{$ise})
ABresult
1X1
011
000
306 8 ▶ $identifier->{validate} //= RE_SINT;
Condition50%1/2
$identifier->{"validate"} //= qr/^(?:0|-?[1-9][0-9]*)\z/u
l!l
08
MC/DC0%0/1
$identifier->{"validate"} //= qr/^(?:0|-?[1-9][0-9]*)\z/u
$identifier->{"validate"}
Truth table50%1/2
A
A= $identifier->{"validate"}
Aresult
11
00
307 8 ▶ $identifier->{generate} //= 'id-based';
Condition50%1/2
$identifier->{"generate"} //= "id-based"
l!l
08
MC/DC0%0/1
$identifier->{"generate"} //= "id-based"
$identifier->{"generate"}
Truth table50%1/2
A
A= $identifier->{"generate"}
Aresult
11
00
308 8 $identifier->register; # re-register
309 }
310  
311 8 foreach my $ise (keys %namespaces_simple_tag) {
312 16 my $identifier = __PACKAGE__->new(ise => $ise);
313 16 ▶ $identifier->{namespace} //= __PACKAGE__->new(ise => $namespaces_simple_tag{$ise});
Condition33%1/3
$identifier->{"namespace"} //= __PACKAGE__->new("ise", $namespaces_simple_tag{$ise})
l!l&&r!l&&!r
0160
MC/DC0%0/2
$identifier->{"namespace"} //= __PACKAGE__->new("ise", $namespaces_simple_tag{$ise})
$identifier->{"namespace"} __PACKAGE__->new("ise", $namespaces_simple_tag{$ise})
Truth table33%1/3
A //= B
A= $identifier->{"namespace"}B= __PACKAGE__->new("ise", $namespaces_simple_tag{$ise})
ABresult
1X1
011
000
314 16 ▶ $identifier->{validate} //= RE_SIMPLE_TAG;
Condition50%1/2
$identifier->{"validate"} //= qr/^[^\p{upper case}\s:]+\z/u
l!l
016
MC/DC0%0/1
$identifier->{"validate"} //= qr/^[^\p{upper case}\s:]+\z/u
$identifier->{"validate"}
Truth table50%1/2
A
A= $identifier->{"validate"}
Aresult
11
00
315 16 ▶ $identifier->{generate} //= 'id-based';
Condition50%1/2
$identifier->{"generate"} //= "id-based"
l!l
016
MC/DC0%0/1
$identifier->{"generate"} //= "id-based"
$identifier->{"generate"}
Truth table50%1/2
A
A= $identifier->{"generate"}
Aresult
11
00
316 16 $identifier->register; # re-register
317 }
318  
319 # validate => RE_QID, namespace => NS_FC, generate => 'id-based'
320 }
321  
322 # Call this after after we loaded all our stuff and before anyone else will register stuff:
323 8 __PACKAGE__->_known_provider('wellknown');
324  
325  
326 2459 ▶sub new {
Subroutine new: called CC=101 SCAR=77.5
Pod documented
327 2459 my ($pkg, $type, $id, %opts) = @_;
328 2459 my $self = bless {};
329  
330 2459 ▶ croak 'No type given' unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 2459 2459
331 2459 ▶ croak 'No id given' unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 2459 2459
332  
333 2459 ▶ if (!ref($type) && $type eq 'from') {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $type and $type eq "from") 140 2319 2459
Condition100%3/3
not ref $type and $type eq "from"
!ll&&!rl&&r
9491370140
MC/DC100%2/2
not ref $type and $type eq "from"
not ref $type $type eq "from"
Truth table100%3/3
not(A) and B
A= not ref $typeB= $type eq "from"
ABresult
0X0
100
111
334 140 ▶ if (ref($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $id) { } 14 126 140
335 14 my $from = $id;
336  
337 14 ▶ if ($from->isa('Convert::Color')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from->isa("Convert::Color")) 0 14 14
338 0 ▶ if ($from->isa('Convert::Color::RGB16')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($from->isa('Convert::Color::RGB16')) { } 0 0 0
elsif ($from->isa('Convert::Color::X11')) { } 0 0 0
339 0 require Data::Identifier::Generate;
340  
341 # For now Data::URIID::Colour doesn't support this space.
342 0 ▶ if (exists &Data::URIID::Colour::new) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists &Data::URIID::Colour::new) 0 0 0
343 0 require Convert::Color::RGB8;
344 0 ▶ eval { $opts{displaycolour} //= Data::URIID::Colour->new(from => $from->as_rgb8) };
Condition0%0/3
$opts{"displaycolour"} //= "Data::URIID::Colour"->new("from", $from->as_rgb8)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"displaycolour"} //= "Data::URIID::Colour"->new("from", $from->as_rgb8)
$opts{"displaycolour"} "Data::URIID::Colour"->new("from", $from->as_rgb8)
Truth table0%0/3
A //= B
A= $opts{"displaycolour"}B= "Data::URIID::Colour"->new("from", $from->as_rgb8)
ABresult
1X1
011
000
345 }
346  
347 0 $from = Data::Identifier::Generate->colour('#'.$from->hex);
348 } elsif ($from->isa('Convert::Color::X11')) {
349 0 require Data::Identifier::Generate;
350 0 my $name = $from->name;
351  
352 # For now Data::URIID::Colour doesn't support this space.
353 0 ▶ if (exists &Data::URIID::Colour::new) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists &Data::URIID::Colour::new) 0 0 0
354 0 require Convert::Color::RGB8;
355 0 ▶ eval { $opts{displaycolour} //= Data::URIID::Colour->new(from => $from->as_rgb8) };
Condition0%0/3
$opts{"displaycolour"} //= "Data::URIID::Colour"->new("from", $from->as_rgb8)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"displaycolour"} //= "Data::URIID::Colour"->new("from", $from->as_rgb8)
$opts{"displaycolour"} "Data::URIID::Colour"->new("from", $from->as_rgb8)
Truth table0%0/3
A //= B
A= $opts{"displaycolour"}B= "Data::URIID::Colour"->new("from", $from->as_rgb8)
ABresult
1X1
011
000
356 }
357  
358 0 $from = Data::Identifier::Generate->colour('#'.$from->hex, displayname => $name);
359 0 ▶ $from->{id_cache} //= {};
Condition0%0/2
$from->{"id_cache"} //= {}
l!l
00
MC/DC0%0/1
$from->{"id_cache"} //= {}
$from->{"id_cache"}
Truth table0%0/2
A
A= $from->{"id_cache"}
Aresult
11
00
360 0 ▶ $from->{id_cache}{'135032f7-cc60-46ee-8f64-1724c2a56fa2'} //= $name;
Condition0%0/3
$from->{"id_cache"}{"135032f7-cc60-46ee-8f64-1724c2a56fa2"} //= $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$from->{"id_cache"}{"135032f7-cc60-46ee-8f64-1724c2a56fa2"} //= $name
$from->{"id_cache"}{"135032f7-cc60-46ee-8f64-1724c2a56fa2"} $name
Truth table0%0/3
A //= B
A= $from->{"id_cache"}{"135032f7-cc60-46ee-8f64-1724c2a56fa2"}B= $name
ABresult
1X1
011
000
361 } else {
362 0 require Data::URIID::Colour;
363 0 $from = Data::URIID::Colour->new(from => $from);
364 }
365 }
366  
367 14 ▶ if ($from->isa('Data::Identifier')) {
Branch: 12 branches
BranchTrueFalseTotal
if ($from->isa('Data::Identifier')) { } 14 0 14
elsif ($from->isa('URI')) { } 0 0 0
elsif ($from->isa('Mojo::URL')) { } 0 0 0
elsif ($from->isa('Data::URIID::Result')) { } 0 0 0
elsif ($from->isa('Data::URIID::Base') or $from->isa('Data::URIID::Colour') or $from->isa('Data::URIID::Service')) { } 0 0 0
elsif ($from->isa('Data::TagDB::Tag')) { } 0 0 0
elsif ($from->isa('File::FStore::File') or $from->isa('File::FStore::Adder') or $from->isa('File::FStore::Base')) { } 0 0 0
elsif ($from->isa('SIRTX::Datecode')) { } 0 0 0
elsif ($from->isa('Business::ISBN')) { } 0 0 0
elsif ($from->isa('Data::Identifier::Interface::Simple')) { } 0 0 0
elsif ($from->isa('JSON::PP::Boolean') or $from->isa('JSON::XS::Boolean')) { } 0 0 0
elsif ($from->isa('Math::BigInt') || $from->isa('Math::BigRat') || $from->isa('Math::BigFloat') and $from->is_int) { } 0 0 0
368 14 ▶ if (scalar(keys %opts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %opts) { } 0 14 14
369 0 $type = $from->type;
370 0 $id = $from->id;
371 } else {
372 14 return $from;
373 }
374 } elsif ($from->isa('URI')) {
375 0 $type = 'uri';
376 } elsif ($from->isa('Mojo::URL')) {
377 0 $type = 'uri';
378 0 $id = $from->to_string;
379 } elsif ($from->isa('Data::URIID::Result')) {
380 0 ▶ $opts{displayname} //= sub { return $from->attribute('displayname', default => undef) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$opts{"displayname"} //= sub { return $from->attribute("displayname", "default", undef); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"displayname"} //= sub { return $from->attribute("displayname", "default", undef); }
$opts{"displayname"} sub { return $from->attribute("displayname", "default", undef); }
Truth table0%0/3
A //= B
A= $opts{"displayname"}B= sub { return $from->attribute("displayname", "default", undef); }
ABresult
1X1
011
000
381 0 ▶ $opts{description} //= sub { return $from->attribute('description', default => undef) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$opts{"description"} //= sub { return $from->attribute("description", "default", undef); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"description"} //= sub { return $from->attribute("description", "default", undef); }
$opts{"description"} sub { return $from->attribute("description", "default", undef); }
Truth table0%0/3
A //= B
A= $opts{"description"}B= sub { return $from->attribute("description", "default", undef); }
ABresult
1X1
011
000
382 0 ▶ $opts{displaycolour} //= sub { return $from->attribute('displaycolour', default => undef) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$opts{"displaycolour"} //= sub { return $from->attribute("displaycolour", "default", undef); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"displaycolour"} //= sub { return $from->attribute("displaycolour", "default", undef); }
$opts{"displaycolour"} sub { return $from->attribute("displaycolour", "default", undef); }
Truth table0%0/3
A //= B
A= $opts{"displaycolour"}B= sub { return $from->attribute("displaycolour", "default", undef); }
ABresult
1X1
011
000
383 0 ▶ $opts{icontext} //= sub { return $from->attribute('icon_text', default => undef) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$opts{"icontext"} //= sub { return $from->attribute("icon_text", "default", undef); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"icontext"} //= sub { return $from->attribute("icon_text", "default", undef); }
$opts{"icontext"} sub { return $from->attribute("icon_text", "default", undef); }
Truth table0%0/3
A //= B
A= $opts{"icontext"}B= sub { return $from->attribute("icon_text", "default", undef); }
ABresult
1X1
011
000
384 0 $type = $from->id_type;
385 0 $id = $from->id;
386 ▶ } elsif ($from->isa('Data::URIID::Base') || $from->isa('Data::URIID::Colour') || $from->isa('Data::URIID::Service')) {
Condition0%0/6
$from->isa("Data::URIID::Base") or $from->isa("Data::URIID::Colour") or $from->isa("Data::URIID::Service")
l!l&&r!l&&!r
000
$from->isa("Data::URIID::Base") or $from->isa("Data::URIID::Colour")
l!l&&r!l&&!r
000
MC/DC0%0/3
$from->isa("Data::URIID::Base") or $from->isa("Data::URIID::Colour") or $from->isa("Data::URIID::Service")
$from->isa("Data::URIID::Base") $from->isa("Data::URIID::Colour") $from->isa("Data::URIID::Service")
Truth table0%0/4
A or B or C
A= $from->isa("Data::URIID::Base")B= $from->isa("Data::URIID::Colour")C= $from->isa("Data::URIID::Service")
ABCresult
1XX1
01X1
0011
0000
387 0 ▶ $opts{displayname} //= $from->displayname(default => undef, no_defaults => 1);
Condition0%0/3
$opts{"displayname"} //= $from->displayname("default", undef, "no_defaults", 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"displayname"} //= $from->displayname("default", undef, "no_defaults", 1)
$opts{"displayname"} $from->displayname("default", undef, "no_defaults", 1)
Truth table0%0/3
A //= B
A= $opts{"displayname"}B= $from->displayname("default", undef, "no_defaults", 1)
ABresult
1X1
011
000
388 0 ▶ if ($from->isa('Data::URIID::Colour')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from->isa("Data::URIID::Colour")) 0 0 0
389 0 ▶ $opts{displaycolour} //= $from;
Condition0%0/3
$opts{"displaycolour"} //= $from
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"displaycolour"} //= $from
$opts{"displaycolour"} $from
Truth table0%0/3
A //= B
A= $opts{"displaycolour"}B= $from
ABresult
1X1
011
000
390 0 ▶ $opts{request} //= $from->rgb;
Condition0%0/3
$opts{"request"} //= $from->rgb
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"request"} //= $from->rgb
$opts{"request"} $from->rgb
Truth table0%0/3
A //= B
A= $opts{"request"}B= $from->rgb
ABresult
1X1
011
000
391 0 ▶ $opts{generator} //= state $generator = Data::Identifier->new(uuid => '55febcc4-6655-4397-ae3d-2353b5856b34')->register;
Condition0%0/3
$opts{"generator"} //= (state $generator = "Data::Identifier"->new("uuid", "55febcc4-6655-4397-ae3d-2353b5856b34")->register)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"generator"} //= (state $generator = "Data::Identifier"->new("uuid", "55febcc4-6655-4397-ae3d-2353b5856b34")->register)
$opts{"generator"} (state $generator = "Data::Identifier"->new("uuid", "55febcc4-6655-4397-ae3d-2353b5856b34")->register)
Truth table0%0/3
A //= B
A= $opts{"generator"}B= (state $generator = "Data::Identifier"->new("uuid", "55febcc4-6655-4397-ae3d-2353b5856b34")->register)
ABresult
1X1
011
000
392 }
393 0 $type = 'ise';
394 0 $id = $from->ise;
395 } elsif ($from->isa('Data::TagDB::Tag')) {
396 0 ▶ $opts{displayname} //= sub { $from->displayname(default => undef, no_defaults => 1) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$opts{"displayname"} //= sub { $from->displayname("default", undef, "no_defaults", 1); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"displayname"} //= sub { $from->displayname("default", undef, "no_defaults", 1); }
$opts{"displayname"} sub { $from->displayname("default", undef, "no_defaults", 1); }
Truth table0%0/3
A //= B
A= $opts{"displayname"}B= sub { $from->displayname("default", undef, "no_defaults", 1); }
ABresult
1X1
011
000
397 0 $type = 'ise';
398 0 $id = $from->ise;
399 ▶ } elsif ($from->isa('File::FStore::File') || $from->isa('File::FStore::Adder') || $from->isa('File::FStore::Base')) {
Condition0%0/6
$from->isa("File::FStore::File") or $from->isa("File::FStore::Adder") or $from->isa("File::FStore::Base")
l!l&&r!l&&!r
000
$from->isa("File::FStore::File") or $from->isa("File::FStore::Adder")
l!l&&r!l&&!r
000
MC/DC0%0/3
$from->isa("File::FStore::File") or $from->isa("File::FStore::Adder") or $from->isa("File::FStore::Base")
$from->isa("File::FStore::File") $from->isa("File::FStore::Adder") $from->isa("File::FStore::Base")
Truth table0%0/4
A or B or C
A= $from->isa("File::FStore::File")B= $from->isa("File::FStore::Adder")C= $from->isa("File::FStore::Base")
ABCresult
1XX1
01X1
0011
0000
400 0 $type = 'ise';
401 0 $id = $from->contentise;
402 } elsif ($from->isa('SIRTX::Datecode')) {
403 0 $id = $from->as('Data::Identifier');
404 0 ▶ unless (scalar(keys %opts)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar keys %opts) 0 0 0
405 0 return $from;
406 }
407 0 $type = $from->type;
408 0 $id = $from->id;
409 } elsif ($from->isa('Business::ISBN')) {
410 0 $type = $well_known{gtin};
411 0 $id = $from->as_isbn13->as_string([]);
412 } elsif ($from->isa('Data::Identifier::Interface::Simple')) {
413 # TODO: We cannot call $from->as('Data::Identifier') here as much as that would be fun,
414 # as this might in turn call exactly this code again resulting in a deep recursion.
415 # A future version might come up with some trick here.
416 0 $type = 'ise';
417 0 $id = $from->ise;
418 ▶ } elsif ($from->isa('JSON::PP::Boolean') || $from->isa('JSON::XS::Boolean')) {
Condition0%0/3
$from->isa("JSON::PP::Boolean") or $from->isa("JSON::XS::Boolean")
l!l&&r!l&&!r
000
MC/DC0%0/2
$from->isa("JSON::PP::Boolean") or $from->isa("JSON::XS::Boolean")
$from->isa("JSON::PP::Boolean") $from->isa("JSON::XS::Boolean")
Truth table0%0/3
A or B
A= $from->isa("JSON::PP::Boolean")B= $from->isa("JSON::XS::Boolean")
ABresult
1X1
011
000
419 0 require Data::Identifier::Util;
420 0 return Data::Identifier::Util->from_bool($from);
421 ▶ } elsif (($from->isa('Math::BigInt') || $from->isa('Math::BigRat') || $from->isa('Math::BigFloat')) && $from->is_int) {
Condition0%0/9
$from->isa("Math::BigInt") || $from->isa("Math::BigRat") || $from->isa("Math::BigFloat") and $from->is_int
!ll&&!rl&&r
000
$from->isa("Math::BigInt") or $from->isa("Math::BigRat") or $from->isa("Math::BigFloat")
l!l&&r!l&&!r
000
$from->isa("Math::BigInt") or $from->isa("Math::BigRat")
l!l&&r!l&&!r
000
MC/DC0%0/4
$from->isa("Math::BigInt") || $from->isa("Math::BigRat") || $from->isa("Math::BigFloat") and $from->is_int
$from->isa("Math::BigInt") $from->isa("Math::BigRat") $from->isa("Math::BigFloat") $from->is_int
Truth table0%0/7
A or B or C and D
A= $from->isa("Math::BigInt")B= $from->isa("Math::BigRat")C= $from->isa("Math::BigFloat")D= $from->is_int
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
422 0 require Data::Identifier::Generate;
423 0 return Data::Identifier::Generate->integer($from->bstr);
424 } else {
425 0 croak 'Unsupported input data';
426 }
427 } else {
428 # If it's not a ref, try as ise.
429 126 $type = 'ise';
430 }
431 }
432  
433 2445 ▶ if (!ref($type) && $type eq 'ise') {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $type and $type eq "ise") 1102 1343 2445
Condition100%3/3
not ref $type and $type eq "ise"
!ll&&!rl&&r
9493941102
MC/DC100%2/2
not ref $type and $type eq "ise"
not ref $type $type eq "ise"
Truth table100%3/3
not(A) and B
A= not ref $typeB= $type eq "ise"
ABresult
0X0
100
111
434 1102 ▶ croak 'Undefined identifier but type is ISE' unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 1102 1102
435  
436 1102 ▶ if ($id =~ /^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\z/) { # allow less normalised form than RE_UUID
Branch: 3 branches
BranchTrueFalseTotal
if ($id =~ /^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\z/u) { } 1090 12 1102
elsif ($id =~ /^[0-2](?:\.(?:0|[1-9][0-9]*))+\z/u) { } 0 12 12
elsif ($id =~ /^[a-zA-Z][a-zA-Z0-9\+\.\-]+:/u) { } 12 0 12
437 1090 $type = $well_known_uuid;
438  
439 # For bootstrap only.
440 1090 ▶ if (!defined($type) && $id eq '8be115d2-dc2f-4a98-91e1-a6e3075cbc31') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $type and $id eq "8be115d2-dc2f-4a98-91e1-a6e3075cbc31") 8 1082 1090
Condition66%2/3
not defined $type and $id eq "8be115d2-dc2f-4a98-91e1-a6e3075cbc31"
!ll&&!rl&&r
108208
MC/DC50%1/2
not defined $type and $id eq "8be115d2-dc2f-4a98-91e1-a6e3075cbc31"
not defined $type $id eq "8be115d2-dc2f-4a98-91e1-a6e3075cbc31"
Truth table66%2/3
not(A) and B
A= not defined $typeB= $id eq "8be115d2-dc2f-4a98-91e1-a6e3075cbc31"
ABresult
0X0
100
111
441 8 $self->{type} = $well_known_uuid = $type = $self;
442 8 $self->{id} = $id;
443 }
444 } elsif ($id =~ RE_OID) {
445 0 $type = 'oid';
446 } elsif ($id =~ RE_URI) {
447 12 $type = 'uri';
448 } else {
449 0 croak 'Not a valid ISE identifier';
450 }
451 }
452  
453 2445 ▶ unless (ref $type) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $type) 406 2039 2445
454 406 ▶ if ($type =~ /^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\z/) { # allow less normalised form than RE_UUID
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\z/u) { } 6 400 406
elsif ($type eq 'wellknown') { } 35 365 400
455 6 $type = $pkg->new(uuid => $type);
456 6 $type->register;
457 } elsif ($type eq 'wellknown') {
458 35 $self = $well_known{$id};
459 35 ▶ croak 'Unknown well-known' unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 35 35
460 35 return $self;
461 } else {
462 365 $type = $well_known{$type};
463 }
464 371 ▶ croak 'Unknown type name' unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 371 371
465 }
466  
467 2410 ▶ croak 'Not a valid type' unless $type->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless $type->isa(__PACKAGE__) 0 2410 2410
468  
469 # we normalise URIs first as they may then normalised again
470 2410 ▶ if ($type == ($well_known{uri} // 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == ($well_known{"uri"} // 0)) 236 2174 2410
Condition100%2/2
$well_known{"uri"} // 0
l!l
2282128
MC/DC100%1/1
$well_known{"uri"} // 0
$well_known{"uri"}
Truth table100%2/2
A
A= $well_known{"uri"}
Aresult
11
00
471 236 my $uri = $id.''; # force stringification
472  
473 236 ▶ if ($uri =~ m#^urn:uuid:([0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})\z#) {
Branch: 6 branches
BranchTrueFalseTotal
if ($uri =~ /^urn:uuid:([0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})\z/u) { } 1 235 236
elsif ($uri =~ /^urn:oid:([0-2](?:\.(?:0|[1-9][0-9]*))+)\z/u) { } 0 235 235
elsif ($uri =~ /^urn:isbn:([0-9Xx-]+)\z/u and scalar eval { do { require Business::ISBN; 1 } }) { } 0 235 235
elsif ($uri =~ m[^https?://www\.wikidata\.org/entity/([QPL][1-9][0-9]*)\z]u) { } 0 235 235
elsif ($uri =~ m[^https?://doi\.org/(10\..+)\z]u) { } 0 235 235
elsif ($uri =~ m[^https?://uriid\.org/([^/]+)/[^/]+]u) { } 2 233 235
474 1 $id = $1;
475 1 $type = $well_known_uuid;
476 } elsif ($uri =~ m#^urn:oid:([0-2](?:\.(?:0|[1-9][0-9]*))+)\z#) {
477 0 $id = $1;
478 0 $type = $well_known{oid};
479 0 ▶ } elsif ($uri =~ m#^urn:isbn:([0-9Xx-]+)\z# && scalar(eval {require Business::ISBN; 1})) {
Condition50%1/2
$uri =~ /^urn:isbn:([0-9Xx-]+)\z/u and scalar eval { do { require Business::ISBN; 1 } }
!ll
2350
MC/DC0%0/1
$uri =~ /^urn:isbn:([0-9Xx-]+)\z/u and scalar eval { do { require Business::ISBN; 1 } }
$uri =~ /^urn:isbn:([0-9Xx-]+)\z/u
Truth table50%1/2
A
A= $uri =~ /^urn:isbn:([0-9Xx-]+)\z/u
Aresult
00
11
480 0 $id = Business::ISBN->new($1)->as_isbn13->as_string([]);
481 0 $type = $well_known{gtin};
482 0 ▶ $self->{id_cache} //= {};
Condition0%0/2
$self->{"id_cache"} //= {}
l!l
00
MC/DC0%0/1
$self->{"id_cache"} //= {}
$self->{"id_cache"}
Truth table0%0/2
A
A= $self->{"id_cache"}
Aresult
11
00
483 0 ▶ $self->{id_cache}{WK_URI()} //= $uri;
Condition0%0/3
$self->{"id_cache"}{"a8d1637d-af19-49e9-9ef8-6bc1fbcf6439"} //= $uri
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"id_cache"}{"a8d1637d-af19-49e9-9ef8-6bc1fbcf6439"} //= $uri
$self->{"id_cache"}{"a8d1637d-af19-49e9-9ef8-6bc1fbcf6439"} $uri
Truth table0%0/3
A //= B
A= $self->{"id_cache"}{"a8d1637d-af19-49e9-9ef8-6bc1fbcf6439"}B= $uri
ABresult
1X1
011
000
484 } elsif ($uri =~ m#^https?://www\.wikidata\.org/entity/([QPL][1-9][0-9]*)\z#) {
485 0 $id = $1;
486 0 $type = $well_known{wd};
487 } elsif ($uri =~ m#^https?://doi\.org/(10\..+)\z#) {
488 0 $id = $1;
489 0 $type = $well_known{doi};
490 } elsif ($uri =~ m#^https?://uriid\.org/([^/]+)/[^/]+#) {
491 2 my $ptype = $1;
492 2 ▶ if (defined($uuid_org_to_uuid{$ptype}) || $ptype =~ RE_UUID) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uuid_org_to_uuid{$ptype} or $ptype =~ /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}\z/u) 2 0 2
Condition66%2/3
defined $uuid_org_to_uuid{$ptype} or $ptype =~ /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}\z/u
l!l&&r!l&&!r
110
MC/DC0%0/2
defined $uuid_org_to_uuid{$ptype} or $ptype =~ /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}\z/u
defined $uuid_org_to_uuid{$ptype} $ptype =~ /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}\z/u
Truth table66%2/3
A or B
A= defined $uuid_org_to_uuid{$ptype}B= $ptype =~ /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}\z/u
ABresult
1X1
011
000
493 2 my $u = URI->new($uri);
494 2 my @path_segments = $u->path_segments;
495 2 ▶ if (scalar(@path_segments) == 3 && $path_segments[0] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @path_segments == 3 and $path_segments[0] eq "") 2 0 2
Condition33%1/3
scalar @path_segments == 3 and $path_segments[0] eq ""
!ll&&!rl&&r
002
MC/DC0%0/2
scalar @path_segments == 3 and $path_segments[0] eq ""
scalar @path_segments == 3 $path_segments[0] eq ""
Truth table33%1/3
A and B
A= scalar @path_segments == 3B= $path_segments[0] eq ""
ABresult
0X0
100
111
496 2 ▶ $type = $pkg->new(uuid => ($uuid_org_to_uuid{$path_segments[1]} // $path_segments[1]));
Condition66%2/3
$uuid_org_to_uuid{$path_segments[1]} // $path_segments[1]
l!l&&r!l&&!r
110
MC/DC0%0/2
$uuid_org_to_uuid{$path_segments[1]} // $path_segments[1]
$uuid_org_to_uuid{$path_segments[1]} $path_segments[1]
Truth table66%2/3
A // B
A= $uuid_org_to_uuid{$path_segments[1]}B= $path_segments[1]
ABresult
1X1
011
000
497 2 $id = $path_segments[2];
498 }
499 }
500 }
501 }
502  
503 2410 ▶ if ($type == ($well_known_uuid // 0)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == ($well_known_uuid // 0)) { } 1960 450 2410
elsif ($type == ($well_known{'oid'} // 0)) { } 1 449 450
Condition50%1/2
$well_known_uuid // 0
l!l
24100
MC/DC0%0/1
$well_known_uuid // 0
$well_known_uuid
Truth table50%1/2
A
A= $well_known_uuid
Aresult
11
00
504 1960 $id = lc($id); # normalise
505 ▶ } elsif ($type == ($well_known{oid} // 0)) {
Condition50%1/2
$well_known{"oid"} // 0
l!l
4500
MC/DC0%0/1
$well_known{"oid"} // 0
$well_known{"oid"}
Truth table50%1/2
A
A= $well_known{"oid"}
Aresult
11
00
506 1 ▶ if ($id =~ /^2\.25\.([1-9][0-9]*)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /^2\.25\.([1-9][0-9]*)\z/u) 1 0 1
507 1 my $hex = Math::BigInt->new($1)->as_hex;
508 1 $hex =~ s/^0x//;
509 1 $hex = ('0' x (32 - length($hex))) . $hex;
510 1 $hex =~ s/^(.{8})(.{4})(.{4})(.{4})(.{12})\z/$1-$2-$3-$4-$5/;
511 1 $type = $well_known_uuid;
512 1 $id = $hex;
513 }
514 }
515  
516 2410 ▶ if (defined($opts{displaycolour}) && !ref($opts{displaycolour})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"displaycolour"} and not ref $opts{"displaycolour"}) 0 2410 2410
Condition33%1/3
defined $opts{"displaycolour"} and not ref $opts{"displaycolour"}
!ll&&!rl&&r
241000
MC/DC0%0/2
defined $opts{"displaycolour"} and not ref $opts{"displaycolour"}
defined $opts{"displaycolour"} not ref $opts{"displaycolour"}
Truth table33%1/3
A and not(B)
A= defined $opts{"displaycolour"}B= not ref $opts{"displaycolour"}
ABresult
0X0
100
111
517 0 croak 'Invalid value for displaycolour passed: not an object. This should be a Data::URIID::Colour';
518 }
519  
520 2410 ▶ if (defined(my $v = $registered{$type->uuid}{$id})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = $registered{$type->uuid}{$id})) 792 1618 2410
521 792 foreach my $key (qw(displayname displaycolour icontext description)) {
522 3168 ▶ next unless defined $opts{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{$key} 3111 57 3168
523 57 ▶ $v->{$key} //= $opts{$key};
Condition66%2/3
$v->{$key} //= $opts{$key}
l!l&&r!l&&!r
3540
MC/DC0%0/2
$v->{$key} //= $opts{$key}
$v->{$key} $opts{$key}
Truth table66%2/3
A //= B
A= $v->{$key}B= $opts{$key}
ABresult
1X1
011
000
524 }
525 792 ▶ if (defined(my $tagname = $opts{tagname})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $tagname = $opts{"tagname"})) 0 792 792
526 0 ▶ $v->_add_tagnames(ref($tagname) ? @{$tagname} : ($tagname));
Branch: 1 branch
BranchTrueFalseTotal
ref $tagname ? : 0 0 0
527 }
528 792 return $v;
529 }
530  
531  
532 1618 ▶ if (defined $type->{validate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type->{"validate"}) 1551 67 1618
533 1551 ▶ croak 'Identifier did not validate against type' unless $id =~ $type->{validate};
Branch: 1 branch
BranchTrueFalseTotal
unless $id =~ /$type->{"validate"}/u 0 1551 1551
534 }
535  
536 1618 $self->{type} = $type;
537 1618 $self->{id} = $id;
538  
539 1618 foreach my $key (qw(validate namespace generator request generate displayname displaycolour icontext description)) {
540 14562 ▶ next unless defined $opts{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{$key} 13456 1106 14562
541 1106 ▶ $self->{$key} //= $opts{$key};
Condition33%1/3
$self->{$key} //= $opts{$key}
l!l&&r!l&&!r
011060
MC/DC0%0/2
$self->{$key} //= $opts{$key}
$self->{$key} $opts{$key}
Truth table33%1/3
A //= B
A= $self->{$key}B= $opts{$key}
ABresult
1X1
011
000
542 }
543  
544 1618 foreach my $key (qw(namespace generator)) {
545 3236 ▶ if (defined(my $v = $self->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = $self->{$key})) 3 3233 3236
546 3 ▶ unless (ref $v) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $v) 3 0 3
547 3 $self->{$key} = $pkg->new(from => $v)->register;
548 }
549 }
550 }
551  
552 1618 ▶ if (defined(my $tagname = $opts{tagname})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $tagname = $opts{"tagname"})) 0 1618 1618
553 0 my %tagnames;
554 0 ▶ $tagname = [$tagname] unless ref $tagname;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tagname 0 0 0
555 0 %tagnames = map {$_ => undef} grep {defined} @{$tagname};
556 0 $tagname = [keys %tagnames];
557 0 ▶ if (scalar(@{$tagname})) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$tagname;}) 0 0 0
558 0 $self->{tagname} = $tagname;
559 }
560 }
561  
562 1618 return bless $self;
563 }
564  
565  
566 #@returns __PACKAGE__
567 0 ▶sub random {
Subroutine random: not called CC=6 SCAR=37.4
Pod documented
568 0 my ($pkg, %opts) = @_;
569 0 ▶ my $type = $opts{type} // 'uuid';
Condition0%0/2
$opts{"type"} // "uuid"
l!l
00
MC/DC0%0/1
$opts{"type"} // "uuid"
$opts{"type"}
Truth table0%0/2
A
A= $opts{"type"}
Aresult
11
00
570  
571 0 ▶ if (ref $type) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $type) 0 0 0
572 0 ▶ if ($type == $well_known_uuid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == $well_known_uuid) { } 0 0 0
573 0 $type = 'uuid';
574 } else {
575 0 croak 'Invalid/Unsupported type';
576 }
577 }
578  
579 0 ▶ if ($type ne 'ise' && $type ne 'uuid') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "ise" and $type ne "uuid") 0 0 0
Condition0%0/3
$type ne "ise" and $type ne "uuid"
!ll&&!rl&&r
000
MC/DC0%0/2
$type ne "ise" and $type ne "uuid"
$type ne "ise" $type ne "uuid"
Truth table0%0/3
A and B
A= $type ne "ise"B= $type ne "uuid"
ABresult
0X0
100
111
580 0 croak 'Invalid/Unsupported type';
581 }
582  
583 0 require Data::Identifier::Generate;
584 0 my $uuid = Data::Identifier::Generate->_random(%opts{'sources'});
585 0 return $pkg->new(uuid => $uuid, %opts{'displayname'});
586 }
587  
588  
589  
590 #@returns __PACKAGE__
591 122 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
592 122 my ($self) = @_;
593 122 return $self->{type};
594 }
595  
596  
597  
598 123 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
599 123 my ($self) = @_;
600 123 return $self->{id};
601 }
602  
603  
604 18122 ▶sub uuid {
Subroutine uuid: called CC=9 SCAR=22.1
Pod documented
605 18122 my ($self, %opts) = @_;
606  
607 18122 ▶ return $self->{id_cache}{WK_UUID()} if !$opts{no_defaults} && defined($self->{id_cache}) && defined($self->{id_cache}{WK_UUID()});
Branch: 1 branch
BranchTrueFalseTotal
if not $opts{"no_defaults"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{"8be115d2-dc2f-4a98-91e1-a6e3075cbc31"} 1069 17053 18122
Condition100%6/6
not $opts{"no_defaults"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{"8be115d2-dc2f-4a98-91e1-a6e3075cbc31"}
!ll&&!rl&&r
2249148041069
not $opts{"no_defaults"} and defined $self->{"id_cache"}
!ll&&!rl&&r
165208415873
MC/DC100%3/3
not $opts{"no_defaults"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{"8be115d2-dc2f-4a98-91e1-a6e3075cbc31"}
not $opts{"no_defaults"} defined $self->{"id_cache"} defined $self->{"id_cache"}{"8be115d2-dc2f-4a98-91e1-a6e3075cbc31"}
Truth table100%4/4
not(A) and B and C
A= not $opts{"no_defaults"}B= defined $self->{"id_cache"}C= defined $self->{"id_cache"}{"8be115d2-dc2f-4a98-91e1-a6e3075cbc31"}
ABCresult
0XX0
10X0
1100
1111
608  
609 17053 ▶ if ($self->{type} == $well_known_uuid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"type"} == $well_known_uuid) 16940 113 17053
610 16940 return $self->{id};
611 }
612  
613 113 ▶ unless ($opts{no_defaults}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"no_defaults"}) 91 22 113
614 # Try to generate a UUID and recheck cache:
615 91 $self->_generate;
616 91 ▶ return $self->{id_cache}{WK_UUID()} if defined($self->{id_cache}) && defined($self->{id_cache}{WK_UUID()});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"id_cache"} and defined $self->{"id_cache"}{"8be115d2-dc2f-4a98-91e1-a6e3075cbc31"} 67 24 91
Condition66%2/3
defined $self->{"id_cache"} and defined $self->{"id_cache"}{"8be115d2-dc2f-4a98-91e1-a6e3075cbc31"}
!ll&&!rl&&r
24067
MC/DC50%1/2
defined $self->{"id_cache"} and defined $self->{"id_cache"}{"8be115d2-dc2f-4a98-91e1-a6e3075cbc31"}
defined $self->{"id_cache"} defined $self->{"id_cache"}{"8be115d2-dc2f-4a98-91e1-a6e3075cbc31"}
Truth table66%2/3
A and B
A= defined $self->{"id_cache"}B= defined $self->{"id_cache"}{"8be115d2-dc2f-4a98-91e1-a6e3075cbc31"}
ABresult
0X0
100
111
617 }
618  
619 46 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 46 0 46
620 0 croak 'Identifier has no valid UUID';
621 }
622  
623 2167 ▶sub oid {
Subroutine oid: called CC=8 SCAR=21.7
Pod documented
624 2167 my ($self, %opts) = @_;
625 2167 my $type = $well_known{oid};
626  
627 2167 ▶ return $self->{id_cache}{WK_OID()} if !$opts{no_defaults} && defined($self->{id_cache}) && defined($self->{id_cache}{WK_OID()});
Branch: 1 branch
BranchTrueFalseTotal
if not $opts{"no_defaults"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{"d08dc905-bbf6-4183-b219-67723c3c8374"} 674 1493 2167
Condition83%5/6
not $opts{"no_defaults"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{"d08dc905-bbf6-4183-b219-67723c3c8374"}
!ll&&!rl&&r
788705674
not $opts{"no_defaults"} and defined $self->{"id_cache"}
!ll&&!rl&&r
07881379
MC/DC66%2/3
not $opts{"no_defaults"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{"d08dc905-bbf6-4183-b219-67723c3c8374"}
not $opts{"no_defaults"} defined $self->{"id_cache"} defined $self->{"id_cache"}{"d08dc905-bbf6-4183-b219-67723c3c8374"}
Truth table75%3/4
not(A) and B and C
A= not $opts{"no_defaults"}B= defined $self->{"id_cache"}C= defined $self->{"id_cache"}{"d08dc905-bbf6-4183-b219-67723c3c8374"}
ABCresult
0XX0
10X0
1100
1111
628  
629 1493 ▶ if ($self->{type} == $type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"type"} == $type) 0 1493 1493
630 0 return $self->{id};
631 }
632  
633 1493 ▶ unless ($opts{no_defaults}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"no_defaults"}) 1493 0 1493
634 1493 ▶ if (defined(my $uuid = $self->uuid(default => undef))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $uuid = $self->uuid("default", undef))) 1481 12 1493
635 1481 return $self->{id_cache}{WK_OID()} = sprintf('2.25.%s', Math::BigInt->new('0x'.$uuid =~ tr/-//dr));
636 }
637 }
638  
639 12 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 12 0 12
640 0 croak 'Identifier has no valid OID';
641 }
642  
643 2168 ▶sub uri {
Subroutine uri: called CC=17 SCAR=31.9
Pod documented
644 2168 my ($self, %opts) = @_;
645 2168 my $type = $well_known{uri};
646  
647 2168 ▶ if (!$opts{no_defaults} && !defined($opts{style}) && defined($self->{id_cache}) && defined($self->{id_cache}{WK_URI()})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts{"no_defaults"} || defined $opts{"style"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{"a8d1637d-af19-49e9-9ef8-6bc1fbcf6439"}) 666 1502 2168
Condition88%8/9
not $opts{"no_defaults"} || defined $opts{"style"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{"a8d1637d-af19-49e9-9ef8-6bc1fbcf6439"}
!ll&&!rl&&r
141488666
not $opts{"no_defaults"} || defined $opts{"style"} and defined $self->{"id_cache"}
!ll&&!rl&&r
1132154
$opts{'no_defaults'} || defined $opts{'style'}
l!l&&r!l&&!r
012167
MC/DC75%3/4
not $opts{"no_defaults"} || defined $opts{"style"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{"a8d1637d-af19-49e9-9ef8-6bc1fbcf6439"}
$opts{'no_defaults'} defined $opts{'style'} defined $self->{"id_cache"} defined $self->{"id_cache"}{"a8d1637d-af19-49e9-9ef8-6bc1fbcf6439"}
Truth table80%4/5
not(A || B) and C and D
A= $opts{'no_defaults'}B= defined $opts{'style'}C= defined $self->{"id_cache"}D= defined $self->{"id_cache"}{"a8d1637d-af19-49e9-9ef8-6bc1fbcf6439"}
ABCDresult
1XXX0
01XX0
000X0
00100
00111
648 666 return $self->{id_cache}{WK_URI()};
649 }
650  
651 1502 ▶ if ($self->{type} == $type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"type"} == $type) 233 1269 1502
652 233 return $self->{id};
653 }
654  
655 1269 ▶ $opts{style} //= 'urn';
Condition100%2/2
$opts{"style"} //= "urn"
l!l
11268
MC/DC100%1/1
$opts{"style"} //= "urn"
$opts{"style"}
Truth table100%2/2
A
A= $opts{"style"}
Aresult
11
00
656  
657 1269 ▶ unless ($opts{no_defaults}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"no_defaults"}) 1269 0 1269
658 1269 ▶ if ($self->{type} == $well_known{wd}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'type'} == $well_known{'wd'}) { } 64 1205 1269
elsif ($self->{'type'} == $well_known{'doi'}) { } 0 1205 1205
elsif (defined(my $uuid = $self->uuid('default', undef)) and $opts{'style'} eq 'urn') { } 1204 1 1205
elsif ($enabled_oid and defined(my $oid = $self->oid('default', undef)) and $opts{'style'} eq 'urn') { } 0 1 1
659 64 return $self->{id_cache}{WK_URI()} = sprintf('http://www.wikidata.org/entity/%s', $self->{id});
660 } elsif ($self->{type} == $well_known{doi}) {
661 0 return $self->{id_cache}{WK_URI()} = sprintf('https://doi.org/%s', $self->{id});
662 ▶ } elsif (defined(my $uuid = $self->uuid(default => undef)) && $opts{style} eq 'urn') {
Condition66%2/3
defined(my $uuid = $self->uuid("default", undef)) and $opts{"style"} eq "urn"
!ll&&!rl&&r
011204
MC/DC50%1/2
defined(my $uuid = $self->uuid("default", undef)) and $opts{"style"} eq "urn"
defined(my $uuid = $self->uuid("default", undef)) $opts{"style"} eq "urn"
Truth table66%2/3
A and B
A= defined(my $uuid = $self->uuid("default", undef))B= $opts{"style"} eq "urn"
ABresult
0X0
100
111
663 1204 return $self->{id_cache}{WK_URI()} = sprintf('urn:uuid:%s', $uuid);
664 ▶ } elsif ($enabled_oid && defined(my $oid = $self->oid(default => undef)) && $opts{style} eq 'urn') {
Condition33%2/6
$enabled_oid and defined(my $oid = $self->oid("default", undef)) and $opts{"style"} eq "urn"
!ll&&!rl&&r
010
$enabled_oid and defined(my $oid = $self->oid("default", undef))
!ll&&!rl&&r
001
MC/DC0%0/3
$enabled_oid and defined(my $oid = $self->oid("default", undef)) and $opts{"style"} eq "urn"
$enabled_oid defined(my $oid = $self->oid("default", undef)) $opts{"style"} eq "urn"
Truth table25%1/4
A and B and C
A= $enabled_oidB= defined(my $oid = $self->oid("default", undef))C= $opts{"style"} eq "urn"
ABCresult
0XX0
10X0
1100
1111
665 0 return $self->{id_cache}{WK_URI()} = sprintf('urn:oid:%s', $oid);
666 } else {
667 1 my $u = URI->new("https://uriid.org/");
668 1 my $type_uuid = $self->{type}->uuid;
669 1 ▶ $u->path_segments('', $uuid_to_uriid_org{$type_uuid} // $type_uuid, $self->{id});
Condition33%1/3
$uuid_to_uriid_org{$type_uuid} // $type_uuid
l!l&&r!l&&!r
100
MC/DC0%0/2
$uuid_to_uriid_org{$type_uuid} // $type_uuid
$uuid_to_uriid_org{$type_uuid} $type_uuid
Truth table33%1/3
A // B
A= $uuid_to_uriid_org{$type_uuid}B= $type_uuid
ABresult
1X1
011
000
670 1 return $self->{id_cache}{WK_URI()} = $u;
671 }
672 }
673  
674 0 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 0 0 0
675 0 croak 'Identifier has no valid URI';
676 }
677  
678 2170 ▶sub sid {
Subroutine sid: called CC=5 SCAR=16.8
Pod documented
679 2170 my ($self, %opts) = @_;
680 2170 my $type = $well_known{sid};
681 2170 ▶ return $self->{id_cache}{WK_SID()} if defined($self->{id_cache}) && defined($self->{id_cache}{WK_SID()});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"id_cache"} and defined $self->{"id_cache"}{"f87a38cb-fd13-4e15-866c-e49901adbec5"} 909 1261 2170
Condition100%3/3
defined $self->{"id_cache"} and defined $self->{"id_cache"}{"f87a38cb-fd13-4e15-866c-e49901adbec5"}
!ll&&!rl&&r
121249909
MC/DC100%2/2
defined $self->{"id_cache"} and defined $self->{"id_cache"}{"f87a38cb-fd13-4e15-866c-e49901adbec5"}
defined $self->{"id_cache"} defined $self->{"id_cache"}{"f87a38cb-fd13-4e15-866c-e49901adbec5"}
Truth table100%3/3
A and B
A= defined $self->{"id_cache"}B= defined $self->{"id_cache"}{"f87a38cb-fd13-4e15-866c-e49901adbec5"}
ABresult
0X0
100
111
682 1261 ▶ if ($self->{type} == $type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"type"} == $type) 0 1261 1261
683 0 return $self->{id};
684 }
685  
686 1261 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 1261 0 1261
687 0 croak 'Identifier has no valid SID';
688 }
689  
690  
691  
692 240 ▶sub ise {
Subroutine ise: called CC=8 SCAR=30.8
Pod documented
693 240 my ($self, %opts) = @_;
694 240 my $type = $self->{type};
695 240 my $have_default = exists $opts{default};
696 240 my $default = delete $opts{default};
697 240 my $value;
698  
699 240 ▶ if ($type == $well_known{uuid} || $type == $well_known{oid} || $type == $well_known{uri}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == $well_known{'uuid'} or $type == $well_known{'oid'} or $type == $well_known{'uri'}) { } 240 0 240
Condition33%2/6
$type == $well_known{"uuid"} or $type == $well_known{"oid"} or $type == $well_known{"uri"}
l!l&&r!l&&!r
24000
$type == $well_known{"uuid"} or $type == $well_known{"oid"}
l!l&&r!l&&!r
24000
MC/DC0%0/3
$type == $well_known{"uuid"} or $type == $well_known{"oid"} or $type == $well_known{"uri"}
$type == $well_known{"uuid"} $type == $well_known{"oid"} $type == $well_known{"uri"}
Truth table25%1/4
A or B or C
A= $type == $well_known{"uuid"}B= $type == $well_known{"oid"}C= $type == $well_known{"uri"}
ABCresult
1XX1
01X1
0011
0000
700 240 $value = $self->{id};
701 } else {
702 0 $opts{default} = undef;
703 0 ▶ $value = $self->uuid(%opts) // $self->oid(%opts) // $self->uri(%opts);
Condition0%0/6
($self->uuid(%opts) // $self->oid(%opts)) // $self->uri(%opts)
l!l&&r!l&&!r
000
$self->uuid(%opts) // $self->oid(%opts)
l!l&&r!l&&!r
000
MC/DC0%0/3
($self->uuid(%opts) // $self->oid(%opts)) // $self->uri(%opts)
$self->uuid(%opts) $self->oid(%opts) $self->uri(%opts)
Truth table0%0/4
A // B // C
A= $self->uuid(%opts)B= $self->oid(%opts)C= $self->uri(%opts)
ABCresult
1XX1
01X1
0011
0000
704 }
705  
706 240 ▶ return $value if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 240 0 240
707 0 ▶ return $default if $have_default;
Branch: 1 branch
BranchTrueFalseTotal
if $have_default 0 0 0
708 0 croak 'Identifier has no valid ISE';
709 }
710  
711  
712 1191 ▶sub as {
Subroutine as: called CC=72 SCAR=77.3
Pod documented
713 1191 my ($self, $as, %opts) = @_;
714  
715 1191 ▶ $as = $opts{rawtype} if $as eq 'raw' && defined($opts{rawtype});
Branch: 1 branch
BranchTrueFalseTotal
if $as eq "raw" and defined $opts{"rawtype"} 248 943 1191
Condition66%2/3
$as eq "raw" and defined $opts{"rawtype"}
!ll&&!rl&&r
9430248
MC/DC50%1/2
$as eq "raw" and defined $opts{"rawtype"}
$as eq "raw" defined $opts{"rawtype"}
Truth table66%2/3
A and B
A= $as eq "raw"B= defined $opts{"rawtype"}
ABresult
0X0
100
111
716  
717 1191 ▶ if (ref($as) && eval {$as->isa(__PACKAGE__)} && $self->isa(__PACKAGE__)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $as and eval { do { $as->isa(__PACKAGE__) } } and $self->isa(__PACKAGE__)) 6 1185 1191
Condition66%4/6
ref $as and eval { do { $as->isa(__PACKAGE__) } } and $self->isa(__PACKAGE__)
!ll&&!rl&&r
118506
ref $as and eval { do { $as->isa(__PACKAGE__) } }
!ll&&!rl&&r
118506
MC/DC33%1/3
ref $as and eval { do { $as->isa(__PACKAGE__) } } and $self->isa(__PACKAGE__)
ref $as eval { do { $as->isa(__PACKAGE__) } } $self->isa(__PACKAGE__)
Truth table50%2/4
A and B and C
A= ref $asB= eval { do { $as->isa(__PACKAGE__) } }C= $self->isa(__PACKAGE__)
ABCresult
0XX0
10X0
1100
1111
718 6 my $type_uuid = $as->uuid;
719 6 my $next_type;
720  
721 6 ▶ return $self->id if $self->type->eq($as);
Branch: 1 branch
BranchTrueFalseTotal
if $self->type->eq($as) 0 6 6
722  
723 6 foreach my $test (qw(uuid oid uri sid)) {
724 24 ▶ if ($as == $well_known{$test}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($as == $well_known{$test}) 3 21 24
725 3 $next_type = $test;
726 3 last;
727 }
728 }
729  
730 6 ▶ if (defined $next_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next_type) { } 3 3 6
731 3 ▶ return $self->{id_cache}{$type_uuid} if !$opts{no_defaults} && defined($self->{id_cache}) && defined($self->{id_cache}{$type_uuid});
Branch: 1 branch
BranchTrueFalseTotal
if not $opts{"no_defaults"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{$type_uuid} 0 3 3
Condition33%2/6
not $opts{"no_defaults"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{$type_uuid}
!ll&&!rl&&r
300
not $opts{"no_defaults"} and defined $self->{"id_cache"}
!ll&&!rl&&r
300
MC/DC0%0/3
not $opts{"no_defaults"} and defined $self->{"id_cache"} and defined $self->{"id_cache"}{$type_uuid}
not $opts{"no_defaults"} defined $self->{"id_cache"} defined $self->{"id_cache"}{$type_uuid}
Truth table25%1/4
not(A) and B and C
A= not $opts{"no_defaults"}B= defined $self->{"id_cache"}C= defined $self->{"id_cache"}{$type_uuid}
ABCresult
0XX0
10X0
1100
1111
732 3 $as = $next_type;
733 } else {
734 3 ▶ return $self->{id_cache}{$type_uuid} if defined($self->{id_cache}) && defined($self->{id_cache}{$type_uuid});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"id_cache"} and defined $self->{"id_cache"}{$type_uuid} 3 0 3
Condition33%1/3
defined $self->{"id_cache"} and defined $self->{"id_cache"}{$type_uuid}
!ll&&!rl&&r
003
MC/DC0%0/2
defined $self->{"id_cache"} and defined $self->{"id_cache"}{$type_uuid}
defined $self->{"id_cache"} defined $self->{"id_cache"}{$type_uuid}
Truth table33%1/3
A and B
A= defined $self->{"id_cache"}B= defined $self->{"id_cache"}{$type_uuid}
ABresult
0X0
100
111
735 0 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 0 0 0
736 0 croak 'Unknown/Unsupported as: '.$as;
737 }
738 }
739  
740 1188 ▶ return $self if ($as =~ /^[A-Z]/ || $as =~ /::/) && eval {$self->isa($as)};
Branch: 1 branch
BranchTrueFalseTotal
if $as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } } 1185 3 1188
Condition66%4/6
$as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } }
!ll&&!rl&&r
301185
$as =~ /^[A-Z]/u or $as =~ /::/u
l!l&&r!l&&!r
118503
MC/DC33%1/3
$as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } }
$as =~ /^[A-Z]/u $as =~ /::/u eval { do { $self->isa($as) } }
Truth table40%2/5
A or B and C
A= $as =~ /^[A-Z]/uB= $as =~ /::/uC= eval { do { $self->isa($as) } }
ABCresult
00X0
1X00
0100
1X11
0111
741  
742 3 ▶ if ($self->isa('Data::Identifier::Interface::Subobjects')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa("Data::Identifier::Interface::Subobjects")) 0 3 3
743 0 require Data::Identifier::Interface::Subobjects; # Is this required?
744 0 ▶ $opts{$_} //= $self->so_get($_, default => undef) foreach Data::Identifier::Interface::Subobjects->KEYS;
Condition0%0/3
$opts{$_} //= $self->so_get($_, "default", undef)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{$_} //= $self->so_get($_, "default", undef)
$opts{$_} $self->so_get($_, "default", undef)
Truth table0%0/3
A //= B
A= $opts{$_}B= $self->so_get($_, "default", undef)
ABresult
1X1
011
000
745 }
746  
747 3 ▶ if (defined(my $so = $opts{so})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $so = $opts{"so"})) 0 3 3
748 0 require Data::Identifier::Interface::Subobjects; # Is this required?
749 0 ▶ $opts{$_} //= $so->so_get($_, default => undef) foreach Data::Identifier::Interface::Subobjects->KEYS;
Condition0%0/3
$opts{$_} //= $so->so_get($_, "default", undef)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{$_} //= $so->so_get($_, "default", undef)
$opts{$_} $so->so_get($_, "default", undef)
Truth table0%0/3
A //= B
A= $opts{$_}B= $so->so_get($_, "default", undef)
ABresult
1X1
011
000
750 }
751  
752 3 ▶ $self = __PACKAGE__->new(from => $self) unless eval {$self->isa(__PACKAGE__)};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $self->isa(__PACKAGE__) } } 0 3 3
753  
754 0 ▶ return $self if ($as =~ /^[A-Z]/ || $as =~ /::/) && eval {$self->isa($as)}; # Recheck after converting to a Data::Identifier
Branch: 1 branch
BranchTrueFalseTotal
if $as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } } 0 3 3
Condition33%2/6
$as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } }
!ll&&!rl&&r
300
$as =~ /^[A-Z]/u or $as =~ /::/u
l!l&&r!l&&!r
003
MC/DC0%0/3
$as =~ /^[A-Z]/u || $as =~ /::/u and eval { do { $self->isa($as) } }
$as =~ /^[A-Z]/u $as =~ /::/u eval { do { $self->isa($as) } }
Truth table20%1/5
A or B and C
A= $as =~ /^[A-Z]/uB= $as =~ /::/uC= eval { do { $self->isa($as) } }
ABCresult
00X0
1X00
0100
1X11
0111
755  
756 3 ▶ if ($as eq 'uuid' || $as eq 'oid' || $as eq 'uri' || $as eq 'sid' || $as eq 'ise') {
Branch: 13 branches
BranchTrueFalseTotal
if ($as eq 'uuid' or $as eq 'oid' or $as eq 'uri' or $as eq 'sid' or $as eq 'ise') { } 3 0 3
elsif ($as eq __PACKAGE__) { } 0 0 0
elsif ($as eq 'URI') { } 0 0 0
elsif ($as eq 'Mojo::URL') { } 0 0 0
elsif ($as eq 'Data::URIID::Result' and defined $opts{'extractor'}) { } 0 0 0
elsif ($as eq 'Data::URIID::Service' and defined $opts{'extractor'}) { } 0 0 0
elsif ($as eq 'SIRTX::Datecode' and eval { do { require SIRTX::Datecode; 'SIRTX::Datecode'->VERSION(v0.03); 1 } }) { } 0 0 0
elsif ($as eq 'Data::URIID::Colour' and eval { do { require Data::URIID; require Data::URIID::Colour; 'Data::URIID::Colour'->VERSION(v0.14); 1 } }) { } 0 0 0
elsif ($as eq 'Data::TagDB::Tag' and defined $opts{'db'}) { } 0 0 0
elsif ($as eq 'File::FStore::File' and defined $opts{'store'}) { } 0 0 0
elsif ($as eq 'Business::ISBN' and $self->type->eq('gtin')) { } 0 0 0
elsif ($as =~ /^Math::Big(?:Int|Rat|Float)\z/u and defined $self->request('default', undef, 'no_defaults', 1) and eval { do { $self->generator->eq('53863a15-68d4-448d-bd69-a9b19289a191') or $self->generator->eq('e8aa9e01-8d37-4b4b-8899-42ca0a2a906f') } }) { } 0 0 0
elsif ($as =~ /^Convert::Color(?:::.+)?\z/u) { } 0 0 0
Condition33%4/12
$as eq "uuid" or $as eq "oid" or $as eq "uri" or $as eq "sid" or $as eq "ise"
l!l&&r!l&&!r
300
$as eq "uuid" or $as eq "oid" or $as eq "uri" or $as eq "sid"
l!l&&r!l&&!r
030
$as eq "uuid" or $as eq "oid" or $as eq "uri"
l!l&&r!l&&!r
003
$as eq "uuid" or $as eq "oid"
l!l&&r!l&&!r
003
MC/DC0%0/5
$as eq "uuid" or $as eq "oid" or $as eq "uri" or $as eq "sid" or $as eq "ise"
$as eq "uuid" $as eq "oid" $as eq "uri" $as eq "sid" $as eq "ise"
Truth table16%1/6
A or B or C or D or E
A= $as eq "uuid"B= $as eq "oid"C= $as eq "uri"D= $as eq "sid"E= $as eq "ise"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
757 3 my $func = $self->can($as);
758 3 return $self->$func(%opts);
759 } elsif ($as eq __PACKAGE__) {
760 0 return $self;
761 } elsif ($as eq 'URI') {
762 0 my $had_default = exists $opts{default};
763 0 my $default = delete $opts{default};
764 0 my $val = $self->uri(%opts, default => undef);
765  
766 0 ▶ return URI->new($val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 0 0
767 0 ▶ if ($had_default) {
Branch: 1 branch
BranchTrueFalseTotal
if ($had_default) 0 0 0
768 0 ▶ return $default if ref $default;
Branch: 1 branch
BranchTrueFalseTotal
if ref $default 0 0 0
769 0 return URI->new($default);
770 }
771 0 croak 'No value for URI';
772 } elsif ($as eq 'Mojo::URL') {
773 0 my $had_default = exists $opts{default};
774 0 my $default = delete $opts{default};
775 0 my $val = $self->uri(%opts, default => undef);
776  
777 0 require Mojo::URL;
778  
779 0 ▶ return Mojo::URL->new($val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 0 0
780 0 ▶ if ($had_default) {
Branch: 1 branch
BranchTrueFalseTotal
if ($had_default) 0 0 0
781 0 ▶ return $default if ref $default;
Branch: 1 branch
BranchTrueFalseTotal
if ref $default 0 0 0
782 0 return Mojo::URL->new($default);
783 }
784 0 croak 'No value for URI';
785 ▶ } elsif ($as eq 'Data::URIID::Result' && defined($opts{extractor})) {
Condition0%0/3
$as eq "Data::URIID::Result" and defined $opts{"extractor"}
!ll&&!rl&&r
000
MC/DC0%0/2
$as eq "Data::URIID::Result" and defined $opts{"extractor"}
$as eq "Data::URIID::Result" defined $opts{"extractor"}
Truth table0%0/3
A and B
A= $as eq "Data::URIID::Result"B= defined $opts{"extractor"}
ABresult
0X0
100
111
786 0 return $opts{extractor}->lookup($self->type->uuid => $self->id);
787 ▶ } elsif ($as eq 'Data::URIID::Service' && defined($opts{extractor})) {
Condition0%0/3
$as eq "Data::URIID::Service" and defined $opts{"extractor"}
!ll&&!rl&&r
000
MC/DC0%0/2
$as eq "Data::URIID::Service" and defined $opts{"extractor"}
$as eq "Data::URIID::Service" defined $opts{"extractor"}
Truth table0%0/3
A and B
A= $as eq "Data::URIID::Service"B= defined $opts{"extractor"}
ABresult
0X0
100
111
788 0 return $opts{extractor}->service($self->uuid);
789 ▶ } elsif ($as eq 'SIRTX::Datecode' && eval {
Condition0%0/3
$as eq "SIRTX::Datecode" and eval { do { require SIRTX::Datecode; "SIRTX::Datecode"->VERSION(v0.03); 1 } }
!ll&&!rl&&r
000
MC/DC0%0/2
$as eq "SIRTX::Datecode" and eval { do { require SIRTX::Datecode; "SIRTX::Datecode"->VERSION(v0.03); 1 } }
$as eq "SIRTX::Datecode" eval { do { require SIRTX::Datecode; "SIRTX::Datecode"->VERSION(v0.03); 1 } }
Truth table0%0/3
A and B
A= $as eq "SIRTX::Datecode"B= eval { do { require SIRTX::Datecode; "SIRTX::Datecode"->VERSION(v0.03); 1 } }
ABresult
0X0
100
111
790 0 require SIRTX::Datecode;
791 0 SIRTX::Datecode->VERSION(v0.03);
792 0 1;
793 }) {
794 0 return SIRTX::Datecode->new(from => $self);
795 ▶ } elsif ($as eq 'Data::URIID::Colour' && eval {
Condition0%0/3
$as eq "Data::URIID::Colour" and eval { do { require Data::URIID; require Data::URIID::Colour; "Data::URIID::Colour"->VERSION(v0.14); 1 } }
!ll&&!rl&&r
000
MC/DC0%0/2
$as eq "Data::URIID::Colour" and eval { do { require Data::URIID; require Data::URIID::Colour; "Data::URIID::Colour"->VERSION(v0.14); 1 } }
$as eq "Data::URIID::Colour" eval { do { require Data::URIID; require Data::URIID::Colour; "Data::URIID::Colour"->VERSION(v0.14); 1 } }
Truth table0%0/3
A and B
A= $as eq "Data::URIID::Colour"B= eval { do { require Data::URIID; require Data::URIID::Colour; "Data::URIID::Colour"->VERSION(v0.14); 1 } }
ABresult
0X0
100
111
796 0 require Data::URIID;
797 0 require Data::URIID::Colour;
798 0 Data::URIID::Colour->VERSION(v0.14);
799 0 1;
800 }) {
801 0 return Data::URIID::Colour->new(from => $self, %opts{qw(extractor db fii store)});
802 ▶ } elsif ($as eq 'Data::TagDB::Tag' && defined($opts{db})) {
Condition0%0/3
$as eq "Data::TagDB::Tag" and defined $opts{"db"}
!ll&&!rl&&r
000
MC/DC0%0/2
$as eq "Data::TagDB::Tag" and defined $opts{"db"}
$as eq "Data::TagDB::Tag" defined $opts{"db"}
Truth table0%0/3
A and B
A= $as eq "Data::TagDB::Tag"B= defined $opts{"db"}
ABresult
0X0
100
111
803 0 ▶ if ($opts{autocreate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'autocreate'}) { } 0 0 0
804 0 return $opts{db}->create_tag($self);
805 } else {
806 0 return $opts{db}->tag_by_id($self);
807 }
808 ▶ } elsif ($as eq 'File::FStore::File' && defined($opts{store})) {
Condition0%0/3
$as eq "File::FStore::File" and defined $opts{"store"}
!ll&&!rl&&r
000
MC/DC0%0/2
$as eq "File::FStore::File" and defined $opts{"store"}
$as eq "File::FStore::File" defined $opts{"store"}
Truth table0%0/3
A and B
A= $as eq "File::FStore::File"B= defined $opts{"store"}
ABresult
0X0
100
111
809 0 return scalar($opts{store}->query(ise => $self));
810 ▶ } elsif ($as eq 'Business::ISBN' && $self->type->eq('gtin')) {
Condition0%0/3
$as eq "Business::ISBN" and $self->type->eq("gtin")
!ll&&!rl&&r
000
MC/DC0%0/2
$as eq "Business::ISBN" and $self->type->eq("gtin")
$as eq "Business::ISBN" $self->type->eq("gtin")
Truth table0%0/3
A and B
A= $as eq "Business::ISBN"B= $self->type->eq("gtin")
ABresult
0X0
100
111
811 0 require Business::ISBN;
812 0 my $val = Business::ISBN->new($self->id);
813 0 ▶ return $val if defined($val) && $val->is_valid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val and $val->is_valid 0 0 0
Condition0%0/3
defined $val and $val->is_valid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $val->is_valid
defined $val $val->is_valid
Truth table0%0/3
A and B
A= defined $valB= $val->is_valid
ABresult
0X0
100
111
814 ▶ } elsif ($as =~ /^Math::Big(?:Int|Rat|Float)\z/ &&
Condition0%0/6
$as =~ /^Math::Big(?:Int|Rat|Float)\z/u and defined $self->request("default", undef, "no_defaults", 1) and eval { do { $self->generator->eq("53863a15-68d4-448d-bd69-a9b19289a191") or $self->generator->eq("e8aa9e01-8d37-4b4b-8899-42ca0a2a906f") } }
!ll&&!rl&&r
000
$as =~ /^Math::Big(?:Int|Rat|Float)\z/u and defined $self->request("default", undef, "no_defaults", 1)
!ll&&!rl&&r
000
MC/DC0%0/3
$as =~ /^Math::Big(?:Int|Rat|Float)\z/u and defined $self->request("default", undef, "no_defaults", 1) and eval { do { $self->generator->eq("53863a15-68d4-448d-bd69-a9b19289a191") or $self->generator->eq("e8aa9e01-8d37-4b4b-8899-42ca0a2a906f") } }
$as =~ /^Math::Big(?:Int|Rat|Float)\z/u defined $self->request("default", undef, "no_defaults", 1) eval { do { $self->generator->eq("53863a15-68d4-448d-bd69-a9b19289a191") or $self->generator->eq("e8aa9e01-8d37-4b4b-8899-42ca0a2a906f") } }
Truth table0%0/4
A and B and C
A= $as =~ /^Math::Big(?:Int|Rat|Float)\z/uB= defined $self->request("default", undef, "no_defaults", 1)C= eval { do { $self->generator->eq("53863a15-68d4-448d-bd69-a9b19289a191") or $self->generator->eq("e8aa9e01-8d37-4b4b-8899-42ca0a2a906f") } }
ABCresult
0XX0
10X0
1100
1111
815 0 ▶ defined($self->request(default => undef, no_defaults => 1)) && eval { $self->generator->eq('53863a15-68d4-448d-bd69-a9b19289a191') || $self->generator->eq('e8aa9e01-8d37-4b4b-8899-42ca0a2a906f')}) {
Condition0%0/3
$self->generator->eq('53863a15-68d4-448d-bd69-a9b19289a191') || $self->generator->eq('e8aa9e01-8d37-4b4b-8899-42ca0a2a906f')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->generator->eq('53863a15-68d4-448d-bd69-a9b19289a191') || $self->generator->eq('e8aa9e01-8d37-4b4b-8899-42ca0a2a906f')
$self->generator->eq('53863a15-68d4-448d-bd69-a9b19289a191') $self->generator->eq('e8aa9e01-8d37-4b4b-8899-42ca0a2a906f')
Truth table0%0/3
A || B
A= $self->generator->eq('53863a15-68d4-448d-bd69-a9b19289a191')B= $self->generator->eq('e8aa9e01-8d37-4b4b-8899-42ca0a2a906f')
ABresult
1X1
011
000
816 0 ▶ if ($as eq 'Math::BigInt') {
Branch: 3 branches
BranchTrueFalseTotal
if ($as eq 'Math::BigInt') { } 0 0 0
elsif ($as eq 'Math::BigRat') { } 0 0 0
elsif ($as eq 'Math::BigFloat') { } 0 0 0
817 # Already loaded.
818 0 return Math::BigInt->new($self->request);
819 } elsif ($as eq 'Math::BigRat') {
820 0 require Math::BigRat;
821 0 state $x = Math::BigRat->import;
822 0 return Math::BigRat->new($self->request);
823 } elsif ($as eq 'Math::BigFloat') {
824 0 require Math::BigFloat;
825 0 state $x = Math::BigFloat->import;
826 0 return Math::BigFloat->new($self->request);
827 } else {
828 0 croak 'BUG';
829 }
830 } elsif ($as =~ /^Convert::Color(?:::.+)?\z/) {
831 0 ▶ if ($as eq 'Convert::Color' || $as eq 'Convert::Color::X11') {
Branch: 1 branch
BranchTrueFalseTotal
if ($as eq "Convert::Color" or $as eq "Convert::Color::X11") 0 0 0
Condition0%0/3
$as eq "Convert::Color" or $as eq "Convert::Color::X11"
l!l&&r!l&&!r
000
MC/DC0%0/2
$as eq "Convert::Color" or $as eq "Convert::Color::X11"
$as eq "Convert::Color" $as eq "Convert::Color::X11"
Truth table0%0/3
A or B
A= $as eq "Convert::Color"B= $as eq "Convert::Color::X11"
ABresult
1X1
011
000
832 0 my $x11_name = $self->as(state $type = Data::Identifier->new(uuid => '135032f7-cc60-46ee-8f64-1724c2a56fa2')->register, default => undef);
833 0 ▶ if (defined $x11_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $x11_name) 0 0 0
834 0 require Convert::Color::X11;
835 0 return Convert::Color::X11->new($x11_name);
836 }
837 }
838 0 return $self->as('Data::URIID::Colour')->as($as, %opts);
839 }
840  
841 0 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 0 0 0
842 0 croak 'Unknown/Unsupported as: '.$as;
843 }
844  
845  
846 41 ▶sub eq {
Subroutine eq: called CC=9 SCAR=24.1
Pod documented
847 41 my ($self, $other) = @_;
848  
849 41 foreach my $e ($self, $other) {
850 82 ▶ if (defined($e) && !scalar(eval {$e->isa(__PACKAGE__)})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e and not scalar eval { do { $e->isa(__PACKAGE__) } }) 4 78 82
Condition66%2/3
defined $e and not scalar eval { do { $e->isa(__PACKAGE__) } }
!ll&&!rl&&r
0784
MC/DC50%1/2
defined $e and not scalar eval { do { $e->isa(__PACKAGE__) } }
defined $e not scalar eval { do { $e->isa(__PACKAGE__) } }
Truth table66%2/3
A and not(B)
A= defined $eB= not scalar eval { do { $e->isa(__PACKAGE__) } }
ABresult
0X0
100
111
851 4 ▶ if (defined $well_known{$e}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $well_known{$e}) { } 0 4 4
852 0 $e = $well_known{$e}
853 } else {
854 4 $e = Data::Identifier->new(from => $e);
855 }
856 }
857 }
858  
859 41 ▶ if (defined($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self) { } 41 0 41
860 41 ▶ return undef unless defined $other;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other 0 41 41
861 41 ▶ return 1 if $self == $other;
Branch: 1 branch
BranchTrueFalseTotal
if $self == $other 30 11 41
862 11 ▶ if ($self->type->eq($other->type)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type->eq($other->type)) { } 11 0 11
863 11 return $self->id eq $other->id;
864 } else {
865 0 return scalar(eval {$self->ise eq $other->ise});
866 }
867 } else {
868 0 return !defined($other);
869 }
870 }
871  
872  
873 0 ▶sub cmp {
Subroutine cmp: not called CC=13 SCAR=52.0
Pod documented
874 0 my ($self, $other) = @_;
875  
876 0 foreach my $e ($self, $other) {
877 0 ▶ if (defined($e) && !scalar(eval {$e->isa(__PACKAGE__)})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e and not scalar eval { do { $e->isa(__PACKAGE__) } }) 0 0 0
Condition0%0/3
defined $e and not scalar eval { do { $e->isa(__PACKAGE__) } }
!ll&&!rl&&r
000
MC/DC0%0/2
defined $e and not scalar eval { do { $e->isa(__PACKAGE__) } }
defined $e not scalar eval { do { $e->isa(__PACKAGE__) } }
Truth table0%0/3
A and not(B)
A= defined $eB= not scalar eval { do { $e->isa(__PACKAGE__) } }
ABresult
0X0
100
111
878 0 ▶ if (defined $well_known{$e}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $well_known{$e}) { } 0 0 0
879 0 $e = $well_known{$e}
880 } else {
881 0 $e = Data::Identifier->new(from => $e);
882 }
883 }
884 }
885  
886 0 ▶ if (defined($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self) { } 0 0 0
887 0 ▶ return undef unless defined $other;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other 0 0 0
888 0 ▶ return 0 if $self == $other;
Branch: 1 branch
BranchTrueFalseTotal
if $self == $other 0 0 0
889 0 ▶ if ((my $r = $self->type->cmp($other->type)) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $r = $self->type->cmp($other->type)) != 0) 0 0 0
890 0 ▶ return 0 if eval {$self->ise eq $other->ise};
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $self->ise eq $other->ise } } 0 0 0
891 0 return $r;
892 }
893  
894 {
895 0 my $self_id = $self->id;
896 0 my $other_id = $other->id;
897  
898 0 ▶ if ((my ($sa, $sb) = $self_id =~ /^([^0-9]*)([0-9]+)\z/) && (my ($oa, $ob) = $other_id =~ /^([^0-9]*)([0-9]+)\z/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $self_id =~ /^([^0-9]*)([0-9]+)\z/u and () = $other_id =~ /^([^0-9]*)([0-9]+)\z/u) 0 0 0
Condition0%0/3
() = $self_id =~ /^([^0-9]*)([0-9]+)\z/u and () = $other_id =~ /^([^0-9]*)([0-9]+)\z/u
!ll&&!rl&&r
000
MC/DC0%0/2
() = $self_id =~ /^([^0-9]*)([0-9]+)\z/u and () = $other_id =~ /^([^0-9]*)([0-9]+)\z/u
() = $self_id =~ /^([^0-9]*)([0-9]+)\z/u () = $other_id =~ /^([^0-9]*)([0-9]+)\z/u
Truth table0%0/3
A and B
A= () = $self_id =~ /^([^0-9]*)([0-9]+)\z/uB= () = $other_id =~ /^([^0-9]*)([0-9]+)\z/u
ABresult
0X0
100
111
899 0 my $r = $sa cmp $oa;
900 0 ▶ return $r if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 0 0 0
901 0 return $sb <=> $ob;
902 }
903  
904 0 return $self_id cmp $other_id;
905 }
906 } else {
907 0 return !defined($other);
908 }
909 }
910  
911  
912 0 ▶sub null_to_undef {
Subroutine null_to_undef: not called CC=5 SCAR=34.0
Pod documented
913 0 my ($self, @opts) = @_;
914  
915 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
916  
917 0 ▶ return undef unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 0 0
918  
919 0 ▶ unless (eval {$self->isa(__PACKAGE__)}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $self->isa(__PACKAGE__) } }) 0 0 0
920 0 $self = __PACKAGE__->new(from => $self);
921 }
922  
923 0 ▶ return undef if $self->eq('null');
Branch: 1 branch
BranchTrueFalseTotal
if $self->eq("null") 0 0 0
924  
925 0 return $self;
926 }
927  
928  
929 0 ▶sub is_null {
Subroutine is_null: not called CC=2 SCAR=17.9
Pod documented
930 0 my ($self, @opts) = @_;
931  
932 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
933  
934 0 return !defined Data::Identifier::null_to_undef($self);
935 }
936  
937  
938 #@returns __PACKAGE__
939 67 ▶sub namespace {
Subroutine namespace: called CC=4 SCAR=16.6
Pod documented
940 67 my ($self, %opts) = @_;
941 67 my $has_default = exists $opts{default};
942 67 my $default = delete $opts{default};
943  
944 67 delete $opts{no_defaults};
945  
946 67 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 67 67
947  
948 67 ▶ return $self->{namespace} if defined $self->{namespace};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"namespace"} 67 0 67
949  
950 0 ▶ return $default if $has_default;
Branch: 1 branch
BranchTrueFalseTotal
if $has_default 0 0 0
951  
952 0 croak 'No namespace';
953 }
954  
955  
956 #@returns __PACKAGE__
957 0 ▶sub generator {
Subroutine generator: not called CC=4 SCAR=30.0
Pod documented
958 0 my ($self, %opts) = @_;
959 0 my $has_default = exists $opts{default};
960 0 my $default = delete $opts{default};
961  
962 0 delete $opts{no_defaults};
963  
964 0 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 0 0
965  
966 0 ▶ return $self->{generator} if defined $self->{generator};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"generator"} 0 0 0
967  
968 0 ▶ return $default if $has_default;
Branch: 1 branch
BranchTrueFalseTotal
if $has_default 0 0 0
969  
970 0 croak 'No generator';
971 }
972  
973  
974 0 ▶sub request {
Subroutine request: not called CC=4 SCAR=30.0
Pod documented
975 0 my ($self, %opts) = @_;
976 0 my $has_default = exists $opts{default};
977 0 my $default = delete $opts{default};
978  
979 0 delete $opts{no_defaults};
980  
981 0 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 0 0
982  
983 0 ▶ return $self->{request} if defined $self->{request};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"request"} 0 0 0
984  
985 0 ▶ return $default if $has_default;
Branch: 1 branch
BranchTrueFalseTotal
if $has_default 0 0 0
986  
987 0 croak 'No request';
988 }
989  
990  
991 #@returns __PACKAGE__
992 2160 ▶sub register {
Subroutine register: called CC=6 SCAR=18.0
Pod documented
993 2160 my ($self) = @_;
994 2160 $registered{$self->{type}->uuid}{$self->{id}} = $self;
995  
996 2160 foreach my $type_name (qw(uuid oid uri sid)) {
997 8640 ▶ my $f = $self->can($type_name) || next;
Condition50%1/2
$self->can($type_name) || (next)
l!l
86400
MC/DC0%0/1
$self->can($type_name) || (next)
$self->can($type_name)
Truth table50%1/2
A
A= $self->can($type_name)
Aresult
11
00
998 8640 ▶ my $v = $self->$f(default => undef) // next;
Condition100%2/2
$self->$f("default", undef) // (next)
l!l
73551285
MC/DC100%1/1
$self->$f("default", undef) // (next)
$self->$f("default", undef)
Truth table100%2/2
A
A= $self->$f("default", undef)
Aresult
11
00
999 7355 $registered{$well_known{$type_name}->uuid}{$v} = $self;
1000 }
1001  
1002 2160 foreach my $extra (keys %{$self->{id_cache}}) {
1003 5617 ▶ my $v = $self->{id_cache}{$extra} // next;
Condition50%1/2
$self->{"id_cache"}{$extra} // (next)
l!l
56170
MC/DC0%0/1
$self->{"id_cache"}{$extra} // (next)
$self->{"id_cache"}{$extra}
Truth table50%1/2
A
A= $self->{"id_cache"}{$extra}
Aresult
11
00
1004 5617 $registered{$extra}{$v} = $self;
1005 }
1006  
1007 2160 return $self;
1008 }
1009  
1010  
1011  
1012 953 ▶sub displayname {
Subroutine displayname: called CC=8 SCAR=22.0
Pod documented
1013 953 my ($self, %opts) = @_;
1014  
1015 953 ▶ if (defined(my $displayname = $self->{displayname})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $displayname = $self->{"displayname"})) 897 56 953
1016 897 ▶ $displayname = $self->$displayname() if ref $displayname;
Branch: 1 branch
BranchTrueFalseTotal
if ref $displayname 0 897 897
1017  
1018 # recheck and return as any of the above conversions could result in $displayname becoming invalid.
1019 897 ▶ return $displayname if defined($displayname) && length($displayname);
Branch: 1 branch
BranchTrueFalseTotal
if defined $displayname and length $displayname 897 0 897
Condition33%1/3
defined $displayname and length $displayname
!ll&&!rl&&r
00897
MC/DC0%0/2
defined $displayname and length $displayname
defined $displayname length $displayname
Truth table33%1/3
A and B
A= defined $displaynameB= length $displayname
ABresult
0X0
100
111
1020 }
1021  
1022 56 ▶ if (defined(my $tagname = $self->tagname(default => undef, no_defaults => 1))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $tagname = $self->tagname("default", undef, "no_defaults", 1))) 20 36 56
1023 20 return $tagname;
1024 }
1025  
1026 36 ▶ return $self->id.'' unless $opts{no_defaults}; # force stringification.
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"no_defaults"} 34 2 36
1027 2 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 2 0 2
1028 0 croak 'No value for displayname';
1029 }
1030  
1031  
1032 0 ▶sub displaycolour {
Subroutine displaycolour: not called CC=6 SCAR=37.4
Pod documented
1033 0 my ($self, %opts) = @_;
1034  
1035 0 ▶ if (defined(my $value = $self->{displaycolour})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = $self->{"displaycolour"})) 0 0 0
1036 0 ▶ $value = $self->$value() if ref($value) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "CODE" 0 0 0
1037  
1038 # recheck and return as any of the above conversions could result in $displayname becoming invalid.
1039 0 ▶ return $value if defined($value) && length($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
1040 }
1041  
1042 0 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 0 0 0
1043 0 croak 'No value found';
1044 }
1045 0 ▶sub icontext {
Subroutine icontext: not called CC=6 SCAR=37.4
Pod documented
1046 0 my ($self, %opts) = @_;
1047  
1048 0 ▶ if (defined(my $value = $self->{icontext})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = $self->{"icontext"})) 0 0 0
1049 0 ▶ $value = $self->$value() if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 0 0
1050  
1051 # recheck and return as any of the above conversions could result in $displayname becoming invalid.
1052 0 ▶ return $value if defined($value) && length($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
1053 }
1054  
1055 0 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 0 0 0
1056 0 croak 'No value found';
1057 }
1058 0 ▶sub description {
Subroutine description: not called CC=6 SCAR=37.4
Pod documented
1059 0 my ($self, %opts) = @_;
1060  
1061 0 ▶ if (defined(my $value = $self->{description})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = $self->{"description"})) 0 0 0
1062 0 ▶ $value = $self->$value() if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 0 0
1063  
1064 # recheck and return as any of the above conversions could result in $displayname becoming invalid.
1065 0 ▶ return $value if defined($value) && length($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
1066 }
1067  
1068 0 ▶ return $opts{default} if exists $opts{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"default"} 0 0 0
1069 0 croak 'No value found';
1070 }
1071  
1072  
1073 56 ▶sub tagname {
Subroutine tagname: called CC=6 SCAR=19.2
Pod documented
1074 56 my ($self, %opts) = @_;
1075 56 my $had_default = exists $opts{default};
1076 56 my $default = delete $opts{default};
1077 56 my $list = delete $opts{list};
1078  
1079 56 delete $opts{no_defaults}; # for compatibility.
1080  
1081 56 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 56 56
1082  
1083 56 ▶ if (defined(my $tagname = $self->{tagname})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $tagname = $self->{"tagname"})) 20 36 56
1084 0 ▶ return @{$tagname} if $list;
Branch: 1 branch
BranchTrueFalseTotal
if $list 0 20 20
1085  
1086 20 return $tagname->[0];
1087 }
1088  
1089 36 ▶ if ($had_default) {
Branch: 1 branch
BranchTrueFalseTotal
if ($had_default) 36 0 36
1090 0 ▶ return @{$default} if $list;
Branch: 1 branch
BranchTrueFalseTotal
if $list 0 36 36
1091 36 return $default;
1092 }
1093 0 croak 'No value for tagname found';
1094 }
1095  
1096 # ---- Private helpers ----
1097  
1098 18 ▶sub import {
Subroutine import: called CC=11 SCAR=46.2
1099 18 my ($pkg, $opts) = @_;
1100 18 ▶ return unless defined $opts;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts 18 0 18
1101 0 ▶ croak 'Bad options' unless ref($opts) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts eq "HASH" 0 0 0
1102  
1103 0 ▶ if (defined(my $disable = $opts->{disable})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $disable = $opts->{"disable"})) 0 0 0
1104 0 ▶ $disable = [split /\s*,\s*/, $disable] unless ref $disable;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $disable 0 0 0
1105 0 foreach my $to_disable (@{$disable}) {
1106 0 ▶ if ($to_disable eq 'oid') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_disable eq 'oid') { } 0 0 0
1107 0 $enabled_oid = undef;
1108 0 undef *oid;
1109 } else {
1110 0 croak 'Unknown feature: '.$to_disable;
1111 }
1112 }
1113 }
1114  
1115 0 ▶ if (defined(my $allow_use = $opts->{allow_use})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $allow_use = $opts->{"allow_use"})) 0 0 0
1116 0 ▶ $allow_use = [split /\s*,\s*/, $allow_use] unless ref $allow_use;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $allow_use 0 0 0
1117 0 foreach my $to_use (@{$allow_use}) {
1118 0 ▶ if ($to_use eq 'Data::URIID::Colour') {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_use eq "Data::URIID::Colour") 0 0 0
1119 0 require Data::URIID::Colour;
1120 }
1121 }
1122 }
1123 }
1124  
1125 91 ▶sub _generate {
Subroutine _generate: called CC=8 SCAR=21.3
1126 91 my ($self) = @_;
1127 91 ▶ unless (exists $self->{_generate}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_generate"}) 79 12 91
1128 79 my __PACKAGE__ $type = $self->type;
1129  
1130 79 ▶ if (defined(my $generate = $type->{generate})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $generate = $type->{"generate"})) 67 12 79
1131 67 ▶ unless (ref $generate) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $generate) 67 0 67
1132 67 $self->{generate} = $generate = {style => $generate};
1133 }
1134  
1135 67 ▶ $self->{id_cache} //= {};
Condition50%1/2
$self->{"id_cache"} //= {}
l!l
067
MC/DC0%0/1
$self->{"id_cache"} //= {}
$self->{"id_cache"}
Truth table50%1/2
A
A= $self->{"id_cache"}
Aresult
11
00
1136  
1137 67 ▶ if (defined(my __PACKAGE__ $ns = eval {$type->namespace->uuid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my Data::Identifier $ns = eval { do { $type->namespace->uuid } })) 67 0 67
1138 67 my $style = $generate->{style};
1139 67 my $input;
1140  
1141 67 ▶ if ($style eq 'id-based') {
Branch: 1 branch
BranchTrueFalseTotal
if ($style eq 'id-based') { } 67 0 67
1142 67 $input = lc($self->id);
1143 } else {
1144 0 croak 'Unsupported generator style';
1145 }
1146  
1147 67 ▶ if (defined $input) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $input) 67 0 67
1148 67 require Data::Identifier::Generate;
1149 67 $self->{id_cache}{WK_UUID()} = Data::Identifier::Generate->_uuid_v5($ns, $input);
1150 }
1151 }
1152 }
1153 }
1154 91 $self->{_generate} = undef;
1155 }
1156  
1157 13 ▶sub _known_provider {
Subroutine _known_provider: called CC=5 SCAR=16.3
1158 13 my ($pkg, $class, %opts) = @_;
1159 13 ▶ croak 'Unsupported options passed' if scalar(keys %opts);
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 13 13
1160  
1161 13 ▶ if ($class eq 'wellknown') {
Branch: 2 branches
BranchTrueFalseTotal
if ($class eq 'wellknown') { } 10 3 13
elsif ($class eq 'registered' or $class eq ':all') { } 3 0 3
1162 10 state $wellknown = do {
1163 8 my %hash = map{$_ => $_} values(%well_known), map {values %{$_}} values(%registered);
1164 8 [values %hash];
1165 };
1166  
1167 10 return ($wellknown, rawtype => __PACKAGE__);
1168 ▶ } elsif ($class eq 'registered' || $class eq ':all') {
Condition66%2/3
$class eq "registered" or $class eq ":all"
l!l&&r!l&&!r
210
MC/DC0%0/2
$class eq "registered" or $class eq ":all"
$class eq "registered" $class eq ":all"
Truth table66%2/3
A or B
A= $class eq "registered"B= $class eq ":all"
ABresult
1X1
011
000
1169 3 my %hash = map{$_ => $_} values(%well_known), map {values %{$_}} values(%registered);
1170 3 return ([values %hash], rawtype => __PACKAGE__);
1171 }
1172  
1173 0 croak 'Unsupported class';
1174 }
1175  
1176 #@returns __PACKAGE__
1177 460 ▶sub _add_tagnames {
Subroutine _add_tagnames: called CC=2 SCAR=6.9
1178 460 my ($self, @tagnames) = @_;
1179 460 ▶ my %tagnames = map {$_ => undef} grep {defined} @{$self->{tagname} //= []}, @tagnames;
Condition100%2/2
$self->{"tagname"} //= []
l!l
45415
MC/DC100%1/1
$self->{"tagname"} //= []
$self->{"tagname"}
Truth table100%2/2
A
A= $self->{"tagname"}
Aresult
11
00
1180 460 @{$self->{tagname}} = keys %tagnames;
1181 460 return $self;
1182 }
1183  
1184 8 1;
1185  
1186 __END__
↑ Summary Identifier/Generate.pm »