Identifier/Generate.pm

filter: Statementstmt 77.8% 246 / 316 Branchbran 54.0% 106 / 196 Conditioncond 44.8% 91 / 203 MC/DCmcdc 11.5% 14 / 121 Subroutinesub 91.6% 22 / 24 Podpod 100% 10 / 10 totaltotal 56.2% 489 / 870 CC 179 SCAR 42.3
CC
179
Cov
62%
_random
132.0
unicode_character
111.5
generic
104.5
CRAP 68.9
« Identifier/Cloudlet.pm ↑ Summary Identifier/Util.pm »
1 # Copyright (c) 2023-2026 Philipp Schafft
2  
3 # licensed under Artistic License 2.0 (see LICENSE file)
4  
5 # ABSTRACT: format independent identifier object
6  
7  
8 package Data::Identifier::Generate;
9  
10 4 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Encode qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Digest;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 ▶use Data::Identifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 4 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 NS_GTE => '90355e77-6942-4d82-a0b6-3a6de65bf948',
22  
23 WK_UNSIGNED_INTEGER_GENERATOR => '53863a15-68d4-448d-bd69-a9b19289a191',
24 WK_SIGNED_INTEGER_GENERATOR => 'e8aa9e01-8d37-4b4b-8899-42ca0a2a906f',
25 WK_UNICODE_CHARACTER_GENERATOR => 'd74f8c35-bcb8-465c-9a77-01010e8ed25c',
26 WK_RGB_COLOUR_GENERATOR => '55febcc4-6655-4397-ae3d-2353b5856b34',
27 WK_DATE_GENERATOR => '97b7f241-e1c5-4f02-ae3c-8e31e501e1dc',
28 #WK_LANGUAGE_GENERATOR => '',
29 WK_MULTIPLICITY_GENERATOR => '19659233-0a22-412c-bdf1-8ee9f8fc4086',
30 WK_MINIMUM_MULTIPLICITY_GENERATOR => '5ec197c3-1406-467c-96c7-4b1a6ec2c5c9',
31 WK_STD_DIGEST_ALGO_GENERATOR => '65284e17-5550-42ef-9449-cdf13cb97a9e',
32 4 };
33  
34  
35 4 our $VERSION = v0.39;
36  
37 4 my %_multiplicity_prefix = (
38 total => '4.1',
39 minimum => '4.3',
40 );
41  
42 4 my %_multiplicity_names = (
43 0 => 'noone',
44 1 => 'solo',
45 2 => 'duo',
46 3 => 'trio',
47 );
48  
49 4 my %_multiplicity_generators = (
50 total => WK_MULTIPLICITY_GENERATOR,
51 minimum => WK_MINIMUM_MULTIPLICITY_GENERATOR,
52 );
53  
54 4 my %_gte_simple_profiles = (
55 'ab332382-a6f8-4a24-914d-5f823dd866c1' => {
56 namespace => 'a13377a3-88d4-484e-90a8-245afb22a793',
57 order => 'MFHCSmfhcs',
58 case_folding => undef,
59 strip_slash => undef,
60 strip_spaces => undef,
61 },
62 'e537db94-85b9-4125-972a-cc2ea1fdf51d' => {
63 namespace => '52f20647-1dc7-4234-81ad-0639ab6cef60',
64 order => 'FAfa',
65 case_folding => undef,
66 strip_slash => undef,
67 strip_spaces => undef,
68 },
69 '60764502-18cb-41c9-8531-e4c8b43140b9' => {
70 namespace => '1e2edf8d-d459-47cb-9d6e-0690f404fadf',
71 order => 'MFHCSmfhcs',
72 case_folding => undef,
73 strip_slash => undef,
74 strip_spaces => undef,
75 },
76 '5aad9d75-7020-41a4-8ec6-2bf09566f985' => {
77 namespace => 'fc9741b4-2ac7-412b-9d36-2b675fc0482b',
78 order => 'NDTBndtb',
79 case_folding => undef,
80 strip_slash => undef,
81 strip_spaces => undef,
82 },
83 );
84  
85 4 my %_generators = (
86 WK_UNSIGNED_INTEGER_GENERATOR() => {
87 style => 'integer-based',
88 namespace => Data::Identifier->NS_INT(),
89 },
90 WK_SIGNED_INTEGER_GENERATOR() => {
91 style => 'integer-based',
92 namespace => Data::Identifier->NS_INT(),
93 },
94 WK_UNICODE_CHARACTER_GENERATOR() => {},
95 WK_RGB_COLOUR_GENERATOR() => {
96 style => 'colour',
97 namespace => '88d3944f-a13b-4e35-89eb-e3c1fbe53e76',
98 },
99 WK_DATE_GENERATOR() => {
100 namespace => Data::Identifier->NS_DATE(),
101 4 ▶ icontext => "\N{TEAR-OFF CALENDAR}",
Subroutine BEGIN: called CC=1 SCAR=0.0
102 },
103 #WK_LANGUAGE_GENERATOR() => {},
104 WK_MULTIPLICITY_GENERATOR() => {
105 namespace => NS_GTE,
106 },
107 WK_MINIMUM_MULTIPLICITY_GENERATOR() => {
108 namespace => NS_GTE,
109 },
110 WK_STD_DIGEST_ALGO_GENERATOR() => {
111 style => 'id-based',
112 namespace => '34f1f1d2-51be-4754-9585-83e33c5cb7e8',
113 },
114 );
115  
116 4 my %_hash_type_to_utag = (
117 '8238da08-ca93-4d67-bf40-54818aa94405' => { # rfc9530-digest-identifier
118 'md5' => 'md-5-128',
119 'sha' => 'sha-1-160',
120 'sha-256' => 'sha-2-256',
121 'sha-512' => 'sha-2-512',
122 },
123 '0d4ef6fa-0f9a-4bc8-9fc1-e4f00725397e' => { # openpgp-digest-identifier
124 1 => 'md-5-128',
125 2 => 'sha-1-160',
126 3 => 'ripemd-1-160',
127 # 4 - 7
128 8 => 'sha-2-256',
129 9 => 'sha-2-384',
130 10 => 'sha-2-512',
131 11 => 'sha-2-224',
132 12 => 'sha-3-256',
133 # 13
134 14 => 'sha-3-512',
135 },
136 '039e0bb7-5dd3-40ee-a98c-596ff6cce405' => { # sirtx-numerical-identifier
137 185 => 'sha-1-160',
138 186 => 'sha-3-512',
139 },
140 );
141  
142 my %_hash_utag_to_type = map {
143 4 my $x = $_;
144 12 $x => {map {$_hash_type_to_utag{$x}{$_} => $_} keys %{$_hash_type_to_utag{$x}}},
145 } keys %_hash_type_to_utag;
146  
147 4 my %_hash_type_aliases = (
148 rfc9530 => '8238da08-ca93-4d67-bf40-54818aa94405',
149 openpgp => '0d4ef6fa-0f9a-4bc8-9fc1-e4f00725397e',
150 sni => '039e0bb7-5dd3-40ee-a98c-596ff6cce405',
151 );
152  
153 4 my %_language_backups = (
154 tok => 'Toki Pona',
155 djd => 'Djamindjung',
156 pgl => 'Primitive Irish',
157 pgl_ogam => 'Primitive Irish (Ogham)',
158 pgl_latn => 'Primitive Irish (Latin)',
159 );
160  
161  
162 #@returns Data::Identifier
163 70 ▶sub integer {
Subroutine integer: called CC=7 SCAR=19.7
Pod documented
164 70 my ($pkg, $request, %opts) = @_;
165 70 $opts{request} = $request.'';
166 70 ▶ $opts{displayname}//= $request.'';
Condition50%1/2
$opts{"displayname"} //= $request . ''
l!l
070
MC/DC0%0/1
$opts{"displayname"} //= $request . ''
$opts{"displayname"}
Truth table50%1/2
A
A= $opts{"displayname"}
Aresult
11
00
167 70 ▶ $opts{generator} = $request >= 0 ? WK_UNSIGNED_INTEGER_GENERATOR : WK_SIGNED_INTEGER_GENERATOR;
Branch: 1 branch
BranchTrueFalseTotal
$request >= 0 ? : 69 1 70
168  
169 # We currently don't set one for $request == 0
170 70 ▶ if ($request > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($request > 0) { } 66 4 70
elsif ($request < 0) { } 1 3 4
171 66 ▶ $opts{icontext} //= "\N{DOUBLE-STRUCK CAPITAL N}";
Condition50%1/2
$opts{"icontext"} //= "\x{2115}"
l!l
066
MC/DC0%0/1
$opts{"icontext"} //= "\x{2115}"
$opts{"icontext"}
Truth table50%1/2
A
A= $opts{"icontext"}
Aresult
11
00
172 } elsif ($request < 0) {
173 1 ▶ $opts{icontext} //= "\N{DOUBLE-STRUCK CAPITAL Z}";
Condition50%1/2
$opts{"icontext"} //= "\x{2124}"
l!l
01
MC/DC0%0/1
$opts{"icontext"} //= "\x{2124}"
$opts{"icontext"}
Truth table50%1/2
A
A= $opts{"icontext"}
Aresult
11
00
174 }
175  
176 70 return $pkg->generic(%opts);
177 }
178  
179  
180 #@returns Data::Identifier
181 3 ▶sub unicode_character {
Subroutine unicode_character: called CC=25 SCAR=47.1
Pod documented
182 3 my ($pkg, $type, $request, %opts) = @_;
183 3 my Data::Identifier $ret;
184 my $unicode_cp;
185 3 my $unicode_cp_str;
186 3 my $tagname;
187  
188 3 ▶ croak 'No type given' unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 3 3
189 3 ▶ croak 'No/Bad request given' unless defined($request) && length($request);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request and length $request 0 3 3
Condition33%1/3
defined $request and length $request
!ll&&!rl&&r
003
MC/DC0%0/2
defined $request and length $request
defined $request length $request
Truth table33%1/3
A and B
A= defined $requestB= length $request
ABresult
0X0
100
111
190  
191 3 ▶ if ($type eq 'unicode') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'unicode') { } 0 3 3
elsif ($type eq 'ascii') { } 0 3 3
elsif ($type eq 'raw') { } 3 0 3
192 0 ▶ if ($request =~ /^[Uu]\+([0-9a-fA-F]+)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($request =~ /^[Uu]\+([0-9a-fA-F]+)$/u) { } 0 0 0
elsif ($request =~ /^[0-9]+\z/u) { } 0 0 0
193 0 $unicode_cp = hex($1);
194 } elsif ($request =~ /^[0-9]+\z/) {
195 0 $unicode_cp = int($request);
196 } else {
197 0 croak 'Bad request given: '.$request;
198 }
199 } elsif ($type eq 'ascii') {
200 0 ▶ if ($request =~ /^[0-9]+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request =~ /^[0-9]+\z/u) { } 0 0 0
201 0 $unicode_cp = int($request);
202 } else {
203 0 croak 'Bad request given: '.$request;
204 }
205 0 ▶ croak 'US-ASCII character out of range: '.$unicode_cp if $unicode_cp < 0 || $unicode_cp > 0x7F;
Branch: 1 branch
BranchTrueFalseTotal
if $unicode_cp < 0 or $unicode_cp > 127 0 0 0
Condition0%0/3
$unicode_cp < 0 or $unicode_cp > 127
l!l&&r!l&&!r
000
MC/DC0%0/2
$unicode_cp < 0 or $unicode_cp > 127
$unicode_cp < 0 $unicode_cp > 127
Truth table0%0/3
A or B
A= $unicode_cp < 0B= $unicode_cp > 127
ABresult
1X1
011
000
206 } elsif ($type eq 'raw') {
207 3 ▶ croak 'Raw value is not exactly one character long' unless length($request) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless length $request == 1 0 3 3
208 3 $unicode_cp = ord($request);
209 } else {
210 0 croak 'Bad type given: '.$type;
211 }
212  
213 3 ▶ croak 'Unicode character out of range: '.$unicode_cp if $unicode_cp < 0 || $unicode_cp > 0x10FFFF;
Branch: 1 branch
BranchTrueFalseTotal
if $unicode_cp < 0 or $unicode_cp > 1114111 0 3 3
Condition33%1/3
$unicode_cp < 0 or $unicode_cp > 1114111
l!l&&r!l&&!r
003
MC/DC0%0/2
$unicode_cp < 0 or $unicode_cp > 1114111
$unicode_cp < 0 $unicode_cp > 1114111
Truth table33%1/3
A or B
A= $unicode_cp < 0B= $unicode_cp > 1114111
ABresult
1X1
011
000
214  
215 3 $unicode_cp_str = sprintf('U+%04X', $unicode_cp);
216  
217 3 ▶ if ($unicode_cp == 0xFFFC || $unicode_cp == 0xFFFD || $unicode_cp == 0xFEFF || $unicode_cp == 0xFFFE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unicode_cp == 65532 or $unicode_cp == 65533 or $unicode_cp == 65279 or $unicode_cp == 65534) 0 3 3
Condition33%3/9
$unicode_cp == 65532 or $unicode_cp == 65533 or $unicode_cp == 65279 or $unicode_cp == 65534
l!l&&r!l&&!r
003
$unicode_cp == 65532 or $unicode_cp == 65533 or $unicode_cp == 65279
l!l&&r!l&&!r
003
$unicode_cp == 65532 or $unicode_cp == 65533
l!l&&r!l&&!r
003
MC/DC0%0/4
$unicode_cp == 65532 or $unicode_cp == 65533 or $unicode_cp == 65279 or $unicode_cp == 65534
$unicode_cp == 65532 $unicode_cp == 65533 $unicode_cp == 65279 $unicode_cp == 65534
Truth table20%1/5
A or B or C or D
A= $unicode_cp == 65532B= $unicode_cp == 65533C= $unicode_cp == 65279D= $unicode_cp == 65534
ABCDresult
1XXX1
01XX1
001X1
00011
00000
218 0 ▶ croak 'Rejected use of special character: '.$unicode_cp_str unless $opts{allow_special};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"allow_special"} 0 0 0
219 }
220  
221 3 ▶ if ($unicode_cp > 31 && $unicode_cp != 127) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unicode_cp > 31 and $unicode_cp != 127) 2 1 3
Condition66%2/3
$unicode_cp > 31 and $unicode_cp != 127
!ll&&!rl&&r
102
MC/DC50%1/2
$unicode_cp > 31 and $unicode_cp != 127
$unicode_cp > 31 $unicode_cp != 127
Truth table66%2/3
A and B
A= $unicode_cp > 31B= $unicode_cp != 127
ABresult
0X0
100
111
222 2 $tagname = eval {
223 2 require charnames;
224 2 charnames::viacode($unicode_cp);
225 };
226 }
227  
228 3 ▶ $opts{displayname} //= $tagname // $unicode_cp_str;
Condition50%3/6
$opts{"displayname"} //= $tagname // $unicode_cp_str
l!l&&r!l&&!r
030
$tagname // $unicode_cp_str
l!l&&r!l&&!r
210
MC/DC0%0/3
$opts{"displayname"} //= $tagname // $unicode_cp_str
$opts{"displayname"} $tagname $unicode_cp_str
Truth table0%0/4
A //= B // C
A= $opts{"displayname"}B= $tagnameC= $unicode_cp_str
ABCresult
1XX1
01X1
0011
0000
229  
230 3 $ret = Data::Identifier->new(unicodecp => $unicode_cp_str, displayname => $opts{displayname}, generator => WK_UNICODE_CHARACTER_GENERATOR, request => $unicode_cp_str);
231 3 ▶ $ret->_add_tagnames($tagname) if defined $tagname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tagname 2 1 3
232 3 return $ret;
233 }
234  
235  
236 #@returns Data::Identifier
237 5 ▶sub colour {
Subroutine colour: called CC=1 SCAR=0.0
Pod documented
238 5 my ($pkg, $colour, %opts) = @_;
239 5 $opts{request} = $colour;
240 5 $opts{generator} = WK_RGB_COLOUR_GENERATOR;
241  
242 5 return $pkg->generic(%opts);
243 }
244  
245  
246 #@returns Data::Identifier
247 9 ▶sub date {
Subroutine date: called CC=35 SCAR=44.5
Pod documented
248 9 my ($pkg, $request, %opts) = @_;
249 9 my ($year, $month, $day);
250 9 my $precision;
251  
252 9 ▶ if (ref($request)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $request) 0 9 9
253 0 ▶ if (eval {$request->can('epoch')}) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $request->can('epoch') } }) { } 0 0 0
254 0 $request = $request->epoch;
255 } else {
256 0 return $pkg->date(scalar($request->()), %opts);
257 }
258 }
259  
260 9 ($year, $month, $day) = $request =~ /^([12][0-9]{3})(?:-([01][0-9])(?:-([0-3][0-9]))?)?Z$/;
261  
262 9 ▶ unless (length($year // '') == 4) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length($year // "") == 4) 3 6 9
Condition100%2/2
$year // ""
l!l
63
MC/DC100%1/1
$year // ""
$year
Truth table100%2/2
A
A= $year
Aresult
11
00
263 3 ▶ if ($request eq 'now' || $request eq 'today') {
Branch: 2 branches
BranchTrueFalseTotal
if ($request eq 'now' or $request eq 'today') { } 0 3 3
elsif ($request =~ /^(?:0|-?[1-9][0-9]*)$/u) { } 3 0 3
Condition33%1/3
$request eq "now" or $request eq "today"
l!l&&r!l&&!r
003
MC/DC0%0/2
$request eq "now" or $request eq "today"
$request eq "now" $request eq "today"
Truth table33%1/3
A or B
A= $request eq "now"B= $request eq "today"
ABresult
1X1
011
000
264 0 $request = time();
265 } elsif ($request =~ /^(?:0|-?[1-9][0-9]*)$/) {
266 3 $request = int($request);
267 3 ▶ if ($request > 32503680000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request > '32503680000') 0 3 3
268 0 croak 'Unlikely far date given. Likely miliseconds are passed as seconds?';
269 }
270 } else {
271 0 croak 'Invalid format';
272 }
273  
274 3 (undef,undef,undef,$day,$month,$year) = gmtime($request);
275 3 $year += 1900;
276 3 $month += 1;
277 }
278  
279 9 foreach my $entry ($year, $month, $day) {
280 27 ▶ $entry = int($entry // 0);
Condition100%2/2
$entry // 0
l!l
243
MC/DC100%1/1
$entry // 0
$entry
Truth table100%2/2
A
A= $entry
Aresult
11
00
281 }
282  
283 9 ▶ croak 'Invalid year' if $year && ($year < 1583 || $year > 9999);
Branch: 1 branch
BranchTrueFalseTotal
if $year and $year < 1583 || $year > 9999 0 9 9
Condition33%2/6
$year and $year < 1583 || $year > 9999
!ll&&!rl&&r
090
$year < 1583 or $year > 9999
l!l&&r!l&&!r
009
MC/DC0%0/3
$year and $year < 1583 || $year > 9999
$year $year < 1583 $year > 9999
Truth table25%1/4
A and B or C
A= $yearB= $year < 1583C= $year > 9999
ABCresult
0XX0
1000
11X1
1011
284 9 ▶ croak 'Invalid month' if $month && ($month < 1 || $month > 12);
Branch: 1 branch
BranchTrueFalseTotal
if $month and $month < 1 || $month > 12 0 9 9
Condition50%3/6
$month and $month < 1 || $month > 12
!ll&&!rl&&r
180
$month < 1 or $month > 12
l!l&&r!l&&!r
008
MC/DC0%0/3
$month and $month < 1 || $month > 12
$month $month < 1 $month > 12
Truth table50%2/4
A and B or C
A= $monthB= $month < 1C= $month > 12
ABCresult
0XX0
1000
11X1
1011
285 9 ▶ croak 'Invalid day' if $day && ($day < 1 || $day > 31);
Branch: 1 branch
BranchTrueFalseTotal
if $day and $day < 1 || $day > 31 0 9 9
Condition50%3/6
$day and $day < 1 || $day > 31
!ll&&!rl&&r
270
$day < 1 or $day > 31
l!l&&r!l&&!r
007
MC/DC0%0/3
$day and $day < 1 || $day > 31
$day $day < 1 $day > 31
Truth table50%2/4
A and B or C
A= $dayB= $day < 1C= $day > 31
ABCresult
0XX0
1000
11X1
1011
286  
287 9 ▶ $month = 0 unless $year;
Branch: 1 branch
BranchTrueFalseTotal
unless $year 0 9 9
288 9 ▶ $day = 0 unless $month;
Branch: 1 branch
BranchTrueFalseTotal
unless $month 1 8 9
289  
290 9 ▶ $precision = $opts{precision} // ($day ? 'day' : undef) // ($month ? 'month' : undef) // 'year';
Branch: 2 branches
BranchTrueFalseTotal
$day ? : 7 2 9
$month ? : 1 1 2
Condition83%5/6
(($opts{"precision"} // ($day ? "day" : undef)) // ($month ? "month" : undef)) // "year"
l!l
81
($opts{"precision"} // ($day ? "day" : undef)) // ($month ? "month" : undef)
l!l
72
$opts{"precision"} // ($day ? "day" : undef)
l!l
09
MC/DC0%0/1
(($opts{"precision"} // ($day ? "day" : undef)) // ($month ? "month" : undef)) // "year"
$opts{"precision"}
Truth table50%1/2
A
A= $opts{"precision"}
Aresult
11
00
291 9 ▶ if ($precision eq 'day' && $day) {
Branch: 3 branches
BranchTrueFalseTotal
if ($precision eq 'day' and $day) { } 7 2 9
elsif ($precision eq 'month' and $month) { } 1 1 2
elsif ($precision eq 'year' and $year) { } 1 0 1
Condition66%2/3
$precision eq "day" and $day
!ll&&!rl&&r
207
MC/DC50%1/2
$precision eq "day" and $day
$precision eq "day" $day
Truth table66%2/3
A and B
A= $precision eq "day"B= $day
ABresult
0X0
100
111
292 7 $request = sprintf('%04u-%02u-%02uZ', $year, $month, $day);
293 ▶ } elsif ($precision eq 'month' && $month) {
Condition66%2/3
$precision eq "month" and $month
!ll&&!rl&&r
101
MC/DC50%1/2
$precision eq "month" and $month
$precision eq "month" $month
Truth table66%2/3
A and B
A= $precision eq "month"B= $month
ABresult
0X0
100
111
294 1 $request = sprintf('%04u-%02uZ', $year, $month);
295 ▶ } elsif ($precision eq 'year' && $year) {
Condition33%1/3
$precision eq "year" and $year
!ll&&!rl&&r
001
MC/DC0%0/2
$precision eq "year" and $year
$precision eq "year" $year
Truth table33%1/3
A and B
A= $precision eq "year"B= $year
ABresult
0X0
100
111
296 1 $request = sprintf('%04uZ', $year);
297 } else {
298 0 croak 'Bad precision: '.$precision;
299 }
300  
301 9 $opts{request} = $request;
302 9 ▶ $opts{input} //= $request; # force raw value!
Condition33%1/3
$opts{"input"} //= $request
l!l&&r!l&&!r
090
MC/DC0%0/2
$opts{"input"} //= $request
$opts{"input"} $request
Truth table33%1/3
A //= B
A= $opts{"input"}B= $request
ABresult
1X1
011
000
303 9 $opts{style} = undef;
304 9 ▶ $opts{tagname} //= $request;
Condition33%1/3
$opts{"tagname"} //= $request
l!l&&r!l&&!r
090
MC/DC0%0/2
$opts{"tagname"} //= $request
$opts{"tagname"} $request
Truth table33%1/3
A //= B
A= $opts{"tagname"}B= $request
ABresult
1X1
011
000
305 9 $opts{generator} = WK_DATE_GENERATOR;
306  
307 9 return $pkg->generic(%opts);
308 }
309  
310  
311 #@returns Data::Identifier
312 8 ▶sub language {
Subroutine language: called CC=8 SCAR=23.6
Pod documented
313 8 my ($pkg, $req, %opts) = @_;
314 8 my $name;
315 my $identifier;
316  
317 {
318 8 local $_; # Workaround invalid usage in earlier versions of I18N::LangTags::List
319 # Fix https://github.com/Perl/perl5/pull/24697 was merged 2026-08-13
320 8 require I18N::LangTags::List;
321 }
322  
323 8 $opts{request} = $req;
324 8 $opts{style} = 'id-based';
325 8 $opts{namespace} = '47dd950c-9089-4956-87c1-54c122533219';
326 #$opts{generator} = WK_LANGUAGE_GENERATOR;
327  
328 8 ▶ croak 'Bad language: '.$req unless I18N::LangTags::List::is_decent($req);
Branch: 1 branch
BranchTrueFalseTotal
unless I18N::LangTags::List::is_decent($req) 0 8 8
329  
330 8 ▶ $name = I18N::LangTags::List::name($req) // $_language_backups{lc($req) =~ tr/-/_/r};
Condition33%1/3
I18N::LangTags::List::name($req) // $_language_backups{lc($req) =~ tr/\-/_/r}
l!l&&r!l&&!r
800
MC/DC0%0/2
I18N::LangTags::List::name($req) // $_language_backups{lc($req) =~ tr/\-/_/r}
I18N::LangTags::List::name($req) $_language_backups{lc($req) =~ tr/\-/_/r}
Truth table33%1/3
A // B
A= I18N::LangTags::List::name($req)B= $_language_backups{lc($req) =~ tr/\-/_/r}
ABresult
1X1
011
000
331  
332 8 ▶ unless (defined($name) && length($name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name and length $name) 0 8 8
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
008
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
333 0 croak 'Bad language: '.$req;
334 }
335  
336 8 ▶ $opts{displayname} //= $name;
Condition33%1/3
$opts{"displayname"} //= $name
l!l&&r!l&&!r
080
MC/DC0%0/2
$opts{"displayname"} //= $name
$opts{"displayname"} $name
Truth table33%1/3
A //= B
A= $opts{"displayname"}B= $name
ABresult
1X1
011
000
337 8 $identifier = $pkg->generic(%opts);
338  
339 8 ▶ $identifier->{id_cache} //= {};
Condition50%1/2
$identifier->{"id_cache"} //= {}
l!l
08
MC/DC0%0/1
$identifier->{"id_cache"} //= {}
$identifier->{"id_cache"}
Truth table50%1/2
A
A= $identifier->{"id_cache"}
Aresult
11
00
340 8 ▶ $identifier->{id_cache}->{'d0a4c6e2-ce2f-4d4c-b079-60065ac681f1'} //= $req;
Condition33%1/3
$identifier->{"id_cache"}{"d0a4c6e2-ce2f-4d4c-b079-60065ac681f1"} //= $req
l!l&&r!l&&!r
080
MC/DC0%0/2
$identifier->{"id_cache"}{"d0a4c6e2-ce2f-4d4c-b079-60065ac681f1"} //= $req
$identifier->{"id_cache"}{"d0a4c6e2-ce2f-4d4c-b079-60065ac681f1"} $req
Truth table33%1/3
A //= B
A= $identifier->{"id_cache"}{"d0a4c6e2-ce2f-4d4c-b079-60065ac681f1"}B= $req
ABresult
1X1
011
000
341  
342 8 return $identifier;
343 }
344  
345  
346 #@returns Data::Identifier
347 8 ▶sub multiplicity {
Subroutine multiplicity: called CC=9 SCAR=24.3
Pod documented
348 8 my ($pkg, $subtype, $request, %opts) = @_;
349 8 ▶ my $prefix = $_multiplicity_prefix{$subtype} // croak 'Invalid subtype: '.$subtype;
Condition50%1/2
$_multiplicity_prefix{$subtype} // croak('Invalid subtype: ' . $subtype)
l!l
80
MC/DC0%0/1
$_multiplicity_prefix{$subtype} // croak('Invalid subtype: ' . $subtype)
$_multiplicity_prefix{$subtype}
Truth table50%1/2
A
A= $_multiplicity_prefix{$subtype}
Aresult
11
00
350 8 my $identifier;
351 my $oid;
352  
353 8 ▶ croak 'Invalid value: '.$request unless $request eq '0' || $request =~ /^[1-9][0-9]*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $request eq 0 or $request =~ /^[1-9][0-9]*$/u 0 8 8
Condition66%2/3
$request eq 0 or $request =~ /^[1-9][0-9]*$/u
l!l&&r!l&&!r
260
MC/DC0%0/2
$request eq 0 or $request =~ /^[1-9][0-9]*$/u
$request eq 0 $request =~ /^[1-9][0-9]*$/u
Truth table66%2/3
A or B
A= $request eq 0B= $request =~ /^[1-9][0-9]*$/u
ABresult
1X1
011
000
354  
355 8 $oid = '1.3.6.1.4.1.46942.16.2.'.$prefix.'.'.$request;
356  
357 8 $opts{request} = $request;
358 8 $opts{input} = $prefix.'.'.$request;
359 8 ▶ $opts{displayname}//= $_multiplicity_names{$request};
Condition33%1/3
$opts{"displayname"} //= $_multiplicity_names{$request}
l!l&&r!l&&!r
080
MC/DC0%0/2
$opts{"displayname"} //= $_multiplicity_names{$request}
$opts{"displayname"} $_multiplicity_names{$request}
Truth table33%1/3
A //= B
A= $opts{"displayname"}B= $_multiplicity_names{$request}
ABresult
1X1
011
000
360 8 ▶ $opts{displayname}//= $request;
Condition33%1/3
$opts{"displayname"} //= $request
l!l&&r!l&&!r
800
MC/DC0%0/2
$opts{"displayname"} //= $request
$opts{"displayname"} $request
Truth table33%1/3
A //= B
A= $opts{"displayname"}B= $request
ABresult
1X1
011
000
361 8 $opts{generator} = $_multiplicity_generators{$subtype};
362 8 $identifier = $pkg->generic(%opts);
363  
364 8 ▶ $identifier->{id_cache} //= {};
Condition50%1/2
$identifier->{"id_cache"} //= {}
l!l
08
MC/DC0%0/1
$identifier->{"id_cache"} //= {}
$identifier->{"id_cache"}
Truth table50%1/2
A
A= $identifier->{"id_cache"}
Aresult
11
00
365 8 ▶ $identifier->{id_cache}->{Data::Identifier->WK_OID} //= $oid;
Condition33%1/3
$identifier->{"id_cache"}{"Data::Identifier"->WK_OID} //= $oid
l!l&&r!l&&!r
080
MC/DC0%0/2
$identifier->{"id_cache"}{"Data::Identifier"->WK_OID} //= $oid
$identifier->{"id_cache"}{"Data::Identifier"->WK_OID} $oid
Truth table33%1/3
A //= B
A= $identifier->{"id_cache"}{"Data::Identifier"->WK_OID}B= $oid
ABresult
1X1
011
000
366  
367 8 ▶ if (defined $_multiplicity_names{$request}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_multiplicity_names{$request}) 8 0 8
368 8 $identifier->register;
369 }
370  
371 8 return $identifier;
372 }
373  
374  
375 #@returns Data::Identifier
376 2 ▶sub gte_simple {
Subroutine gte_simple: called CC=14 SCAR=34.6
Pod documented
377 2 my ($pkg, $profile, $request, %opts) = @_;
378 2 my %order;
379 my $normal;
380  
381 2 ▶ croak 'Called in list context' if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 2 2
382  
383 2 ▶ $profile = $profile->ise if eval {$profile->can('ise')};
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $profile->can("ise") } } 0 2 2
384 2 ▶ $profile = $_gte_simple_profiles{$profile} // $profile;
Condition33%1/3
$_gte_simple_profiles{$profile} // $profile
l!l&&r!l&&!r
200
MC/DC0%0/2
$_gte_simple_profiles{$profile} // $profile
$_gte_simple_profiles{$profile} $profile
Truth table33%1/3
A // B
A= $_gte_simple_profiles{$profile}B= $profile
ABresult
1X1
011
000
385  
386 {
387 2 my $i = 0;
388 2 %order = map {$_ => $i++} split(//, $profile->{order});
389 }
390  
391 2 ▶ if (defined(my $folding = $profile->{case_folding})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $folding = $profile->{"case_folding"})) 0 2 2
392 0 ▶ if ($folding eq 'none') {
Branch: 3 branches
BranchTrueFalseTotal
if ($folding eq 'none') { } 0 0 0
elsif ($folding eq 'upper') { } 0 0 0
elsif ($folding eq 'lower') { } 0 0 0
393 # no-op
394 } elsif ($folding eq 'upper') {
395 0 $request = uc($request);
396 } elsif ($folding eq 'lower') {
397 0 $request = lc($request);
398 } else {
399 0 croak 'Unsupported/invalid folding rule: '.$folding;
400 }
401 }
402  
403 2 ▶ if ($profile->{strip_slash}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($profile->{"strip_slash"}) 0 2 2
404 0 $request =~ s#/+##g;
405 }
406  
407 2 ▶ if ($profile->{strip_spaces}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($profile->{"strip_spaces"}) 0 2 2
408 0 $request =~ s#\s+##g;
409 }
410  
411 $normal = join('',
412 2 sort {$order{$a} <=> $order{$b}}
413 2 ▶ map {croak 'Invalid input element: '.$_ unless defined $order{$_}; $_}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $order{$_} 0 4 4
414 split //, $request);
415  
416 2 ▶ if (defined(my $info = delete $opts{info})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $info = delete $opts{"info"})) 0 2 2
417 0 $info->{count} = length($normal);
418 0 $info->{request} = $normal;
419 }
420  
421 2 $opts{input} = $normal;
422 2 $opts{request} = $normal;
423 2 ▶ $opts{namespace} //= $profile->{namespace};
Condition33%1/3
$opts{"namespace"} //= $profile->{"namespace"}
l!l&&r!l&&!r
020
MC/DC0%0/2
$opts{"namespace"} //= $profile->{"namespace"}
$opts{"namespace"} $profile->{"namespace"}
Truth table33%1/3
A //= B
A= $opts{"namespace"}B= $profile->{"namespace"}
ABresult
1X1
011
000
424 2 ▶ $opts{displayname}//= $normal;
Condition33%1/3
$opts{"displayname"} //= $normal
l!l&&r!l&&!r
020
MC/DC0%0/2
$opts{"displayname"} //= $normal
$opts{"displayname"} $normal
Truth table33%1/3
A //= B
A= $opts{"displayname"}B= $normal
ABresult
1X1
011
000
425 2 return $pkg->generic(%opts);
426 }
427  
428  
429 #@returns Data::Identifier
430 7 ▶sub unit {
Subroutine unit: called CC=1 SCAR=0.0
Pod documented
431 7 my ($pkg, $request, %opts) = @_;
432  
433 7 require Data::Identifier::Util;
434  
435 7 return Data::Identifier::Util->render_unit_request('Data::Identifier' => $request, %opts);
436 }
437  
438  
439 #@returns Data::Identifier
440 7 ▶sub digest {
Subroutine digest: called CC=19 SCAR=36.1
Pod documented
441 7 my ($pkg, $type, $request, %opts) = @_;
442 7 state $generator = Data::Identifier->new(uuid => WK_STD_DIGEST_ALGO_GENERATOR)->register;
443 7 my Data::Identifier $identifier;
444 my $utag;
445  
446 7 ▶ croak 'Bad type or request' unless defined($type) && defined($request);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and defined $request 0 7 7
Condition33%1/3
defined $type and defined $request
!ll&&!rl&&r
007
MC/DC0%0/2
defined $type and defined $request
defined $type defined $request
Truth table33%1/3
A and B
A= defined $typeB= defined $request
ABresult
0X0
100
111
447  
448 7 ▶ $type = $type->ise if ref $type;
Branch: 1 branch
BranchTrueFalseTotal
if ref $type 0 7 7
449  
450 7 ▶ if ($type eq 'utag' || $type eq '8db88212-69df-40f3-a5cf-105dcd853d44') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'utag' or $type eq '8db88212-69df-40f3-a5cf-105dcd853d44') { } 2 5 7
elsif (defined $_hash_type_to_utag{$type} and defined($utag = $_hash_type_to_utag{$type}{$request})) { } 0 5 5
elsif (defined $_hash_type_to_utag{$_hash_type_aliases{$type} // '_nx'} and defined($utag = $_hash_type_to_utag{$_hash_type_aliases{$type}}{$request})) { } 5 0 5
Condition66%2/3
$type eq "utag" or $type eq "8db88212-69df-40f3-a5cf-105dcd853d44"
l!l&&r!l&&!r
205
MC/DC50%1/2
$type eq "utag" or $type eq "8db88212-69df-40f3-a5cf-105dcd853d44"
$type eq "utag" $type eq "8db88212-69df-40f3-a5cf-105dcd853d44"
Truth table66%2/3
A or B
A= $type eq "utag"B= $type eq "8db88212-69df-40f3-a5cf-105dcd853d44"
ABresult
1X1
011
000
451 2 $utag = $request;
452 ▶ } elsif (defined($_hash_type_to_utag{$type}) && defined($utag = $_hash_type_to_utag{$type}{$request})) {
Condition33%1/3
defined $_hash_type_to_utag{$type} and defined($utag = $_hash_type_to_utag{$type}{$request})
!ll&&!rl&&r
500
MC/DC0%0/2
defined $_hash_type_to_utag{$type} and defined($utag = $_hash_type_to_utag{$type}{$request})
defined $_hash_type_to_utag{$type} defined($utag = $_hash_type_to_utag{$type}{$request})
Truth table33%1/3
A and B
A= defined $_hash_type_to_utag{$type}B= defined($utag = $_hash_type_to_utag{$type}{$request})
ABresult
0X0
100
111
453 # no-op
454 ▶ } elsif (defined($_hash_type_to_utag{$_hash_type_aliases{$type} // '_nx'}) && defined($utag = $_hash_type_to_utag{$_hash_type_aliases{$type}}{$request})) {
Condition40%2/5
defined $_hash_type_to_utag{$_hash_type_aliases{$type} // "_nx"} and defined($utag = $_hash_type_to_utag{$_hash_type_aliases{$type}}{$request})
!ll&&!rl&&r
005
$_hash_type_aliases{$type} // "_nx"
l!l
50
MC/DC0%0/2
defined $_hash_type_to_utag{$_hash_type_aliases{$type} // "_nx"} and defined($utag = $_hash_type_to_utag{$_hash_type_aliases{$type}}{$request})
defined $_hash_type_to_utag{$_hash_type_aliases{$type} // "_nx"} defined($utag = $_hash_type_to_utag{$_hash_type_aliases{$type}}{$request})
MC/DC0%0/1
$_hash_type_aliases{$type} // "_nx"
$_hash_type_aliases{$type}
Truth table33%1/3
A and B
A= defined $_hash_type_to_utag{$_hash_type_aliases{$type} // "_nx"}B= defined($utag = $_hash_type_to_utag{$_hash_type_aliases{$type}}{$request})
ABresult
0X0
100
111
Truth table50%1/2
A
A= $_hash_type_aliases{$type}
Aresult
11
00
455 # no-op
456 } else {
457 0 croak 'Invalid or unsupported type: '.$type;
458 }
459  
460 7 ▶ croak 'Bad request: '.$utag unless $utag =~ /^[a-z]{2,6}-(?:0|[1-9][0-9]*)-[1-9][0-9]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $utag =~ /^[a-z]{2,6}-(?:0|[1-9][0-9]*)-[1-9][0-9]*\z/u 0 7 7
461  
462 7 $identifier = $pkg->generic(request => $utag, generator => $generator, tagname => $utag, %opts);
463  
464 7 ▶ $identifier->{generator} //= $generator;
Condition33%1/3
$identifier->{"generator"} //= $generator
l!l&&r!l&&!r
700
MC/DC0%0/2
$identifier->{"generator"} //= $generator
$identifier->{"generator"} $generator
Truth table33%1/3
A //= B
A= $identifier->{"generator"}B= $generator
ABresult
1X1
011
000
465 7 ▶ $identifier->{request} //= $utag;
Condition33%1/3
$identifier->{"request"} //= $utag
l!l&&r!l&&!r
700
MC/DC0%0/2
$identifier->{"request"} //= $utag
$identifier->{"request"} $utag
Truth table33%1/3
A //= B
A= $identifier->{"request"}B= $utag
ABresult
1X1
011
000
466  
467 {
468 7 ▶ my $id_cache = $identifier->{id_cache} //= {};
Condition50%1/2
$identifier->{"id_cache"} //= {}
l!l
07
MC/DC0%0/1
$identifier->{"id_cache"} //= {}
$identifier->{"id_cache"}
Truth table50%1/2
A
A= $identifier->{"id_cache"}
Aresult
11
00
469 7 ▶ $id_cache->{'8db88212-69df-40f3-a5cf-105dcd853d44'} = $utag unless $identifier->type->eq('8db88212-69df-40f3-a5cf-105dcd853d44');
Branch: 1 branch
BranchTrueFalseTotal
unless $identifier->type->eq("8db88212-69df-40f3-a5cf-105dcd853d44") 7 0 7
470  
471 7 foreach my $type (keys %_hash_utag_to_type) {
472 21 ▶ my $v = $_hash_utag_to_type{$type}{$utag} // next;
Condition100%2/2
$_hash_utag_to_type{$type}{$utag} // (next)
l!l
183
MC/DC100%1/1
$_hash_utag_to_type{$type}{$utag} // (next)
$_hash_utag_to_type{$type}{$utag}
Truth table100%2/2
A
A= $_hash_utag_to_type{$type}{$utag}
Aresult
11
00
473 18 ▶ $id_cache->{$type} //= $v;
Condition33%1/3
$id_cache->{$type} //= $v
l!l&&r!l&&!r
0180
MC/DC0%0/2
$id_cache->{$type} //= $v
$id_cache->{$type} $v
Truth table33%1/3
A //= B
A= $id_cache->{$type}B= $v
ABresult
1X1
011
000
474 }
475 }
476  
477 7 return $identifier;
478 }
479  
480  
481 #@returns Data::Identifier
482 252 ▶sub generic {
Subroutine generic: called CC=49 SCAR=46.5
Pod documented
483 252 my ($pkg, %opts) = @_;
484 252 my $generator = $opts{generator};
485  
486 252 ▶ if (defined($generator)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $generator) 224 28 252
487 224 ▶ $generator = Data::Identifier->new(from => $generator) unless ref($generator);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $generator 92 132 224
488  
489 224 ▶ %opts = (%{$_generators{$generator->ise}//{}}, %opts);
Condition100%2/2
$_generators{$generator->ise} // {}
l!l
13292
MC/DC100%1/1
$_generators{$generator->ise} // {}
$_generators{$generator->ise}
Truth table100%2/2
A
A= $_generators{$generator->ise}
Aresult
11
00
490 }
491  
492 252 ▶ if (defined(my $type = $opts{type})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $type = $opts{"type"})) 0 252 252
493 0 ▶ $opts{namespace} //= $type->namespace;
Condition0%0/3
$opts{"namespace"} //= $type->namespace
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"namespace"} //= $type->namespace
$opts{"namespace"} $type->namespace
Truth table0%0/3
A //= B
A= $opts{"namespace"}B= $type->namespace
ABresult
1X1
011
000
494 }
495  
496 252 ▶ if (defined(my $style = $opts{style}) && defined(my $request = $opts{request})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $style = $opts{"style"}) and defined(my $request = $opts{"request"})) 227 25 252
Condition66%2/3
defined(my $style = $opts{"style"}) and defined(my $request = $opts{"request"})
!ll&&!rl&&r
250227
MC/DC50%1/2
defined(my $style = $opts{"style"}) and defined(my $request = $opts{"request"})
defined(my $style = $opts{"style"}) defined(my $request = $opts{"request"})
Truth table66%2/3
A and B
A= defined(my $style = $opts{"style"})B= defined(my $request = $opts{"request"})
ABresult
0X0
100
111
497 227 ▶ if ($style eq 'integer-based') {
Branch: 6 branches
BranchTrueFalseTotal
if ($style eq 'integer-based') { } 98 129 227
elsif ($style eq 'id-based') { } 16 113 129
elsif ($style eq 'name-based') { } 79 34 113
elsif ($style eq 'tag-based') { } 4 30 34
elsif ($style eq 'tagcombiner') { } 14 16 30
elsif ($style eq 'colour') { } 16 0 16
498 98 ▶ croak 'Invalid request' unless $request =~ /^(?:0|-?[1-9][0-9]*)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $request =~ /^(?:0|-?[1-9][0-9]*)$/u 0 98 98
499 98 ▶ $opts{input} //= $request;
Condition33%1/3
$opts{"input"} //= $request
l!l&&r!l&&!r
0980
MC/DC0%0/2
$opts{"input"} //= $request
$opts{"input"} $request
Truth table33%1/3
A //= B
A= $opts{"input"}B= $request
ABresult
1X1
011
000
500 } elsif ($style eq 'id-based') {
501 16 my ($input, $name);
502  
503 16 ▶ if (($input, $name) = $request =~ /^(#?[a-zA-Z0-9\-\.\+]+) (.+)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = $request =~ /^(#?[a-zA-Z0-9\-\.\+]+) (.+)$/u) { } 1 15 16
elsif (($input) = $request =~ /^(#?[a-zA-Z0-9\-\.\+]+)$/u) { } 15 0 15
504 # noop
505 } elsif (($input) = $request =~ /^(#?[a-zA-Z0-9\-\.\+]+)$/) {
506 15 $name = undef;
507 } else {
508 0 croak 'Invalid format, expected: "id name", or "id", got: '.$request;
509 }
510  
511 16 ▶ $opts{input} //= lc($input);
Condition50%1/2
$opts{"input"} //= lc $input
l!l
016
MC/DC0%0/1
$opts{"input"} //= lc $input
$opts{"input"}
Truth table50%1/2
A
A= $opts{"input"}
Aresult
11
00
512 16 ▶ $opts{displayname} //= $name;
Condition100%3/3
$opts{"displayname"} //= $name
l!l&&r!l&&!r
817
MC/DC100%2/2
$opts{"displayname"} //= $name
$opts{"displayname"} $name
Truth table100%3/3
A //= B
A= $opts{"displayname"}B= $name
ABresult
1X1
011
000
513  
514 } elsif ($style eq 'name-based') {
515 79 ▶ $opts{input} //= encode('UTF-8', $request);
Condition33%1/3
$opts{"input"} //= &encode("UTF-8", $request)
l!l&&r!l&&!r
0790
MC/DC0%0/2
$opts{"input"} //= &encode("UTF-8", $request)
$opts{"input"} &encode("UTF-8", $request)
Truth table33%1/3
A //= B
A= $opts{"input"}B= &encode("UTF-8", $request)
ABresult
1X1
011
000
516 79 ▶ $opts{displayname} //= $request;
Condition66%2/3
$opts{"displayname"} //= $request
l!l&&r!l&&!r
21580
MC/DC0%0/2
$opts{"displayname"} //= $request
$opts{"displayname"} $request
Truth table66%2/3
A //= B
A= $opts{"displayname"}B= $request
ABresult
1X1
011
000
517 } elsif ($style eq 'tag-based') {
518 4 ▶ if (ref($request)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $request) { } 2 2 4
elsif ($request =~ 'Data::Identifier'->RE_UUID) { } 2 0 2
519 2 my $identifier = Data::Identifier->new(from => $request);
520 2 ▶ $opts{input} //= $identifier->uuid;
Condition33%1/3
$opts{"input"} //= $identifier->uuid
l!l&&r!l&&!r
020
MC/DC0%0/2
$opts{"input"} //= $identifier->uuid
$opts{"input"} $identifier->uuid
Truth table33%1/3
A //= B
A= $opts{"input"}B= $identifier->uuid
ABresult
1X1
011
000
521 2 ▶ $opts{displayname} //= $identifier->{displayname}; # steal the raw value here.
Condition33%1/3
$opts{"displayname"} //= $identifier->{"displayname"}
l!l&&r!l&&!r
002
MC/DC0%0/2
$opts{"displayname"} //= $identifier->{"displayname"}
$opts{"displayname"} $identifier->{"displayname"}
Truth table33%1/3
A //= B
A= $opts{"displayname"}B= $identifier->{"displayname"}
ABresult
1X1
011
000
522 } elsif ($request =~ Data::Identifier->RE_UUID) {
523 2 ▶ $opts{input} //= $request;
Condition33%1/3
$opts{"input"} //= $request
l!l&&r!l&&!r
020
MC/DC0%0/2
$opts{"input"} //= $request
$opts{"input"} $request
Truth table33%1/3
A //= B
A= $opts{"input"}B= $request
ABresult
1X1
011
000
524 } else {
525 0 croak 'Invalid format for tag-based generator: '.$request;
526 }
527 } elsif ($style eq 'tagcombiner') {
528 14 ▶ if (ref($request) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $request eq 'ARRAY') { } 14 0 14
529 14 my %uuids;
530  
531 14 foreach my $entry (@{$request}) {
532 28 ▶ if (ref($entry)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $entry) { } 14 14 28
elsif ($entry =~ 'Data::Identifier'->RE_UUID) { } 14 0 14
533 14 $uuids{Data::Identifier->new(from => $entry)->uuid} = undef;
534 } elsif ($entry =~ Data::Identifier->RE_UUID) {
535 14 $uuids{$entry} = undef;
536 } else {
537 0 croak 'Invalid format for tag-based generator: '.$entry;
538 }
539 }
540  
541 14 ▶ croak 'Less than two tags being combined' unless scalar(keys %uuids) > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %uuids > 1 4 10 14
542  
543 10 ▶ $opts{input} //= join(',', sort keys %uuids);
Condition50%1/2
$opts{"input"} //= join(",", sort(keys %uuids))
l!l
010
MC/DC0%0/1
$opts{"input"} //= join(",", sort(keys %uuids))
$opts{"input"}
Truth table50%1/2
A
A= $opts{"input"}
Aresult
11
00
544 } else {
545 0 croak 'Invalid request for tagcombiner generator: '.$request;
546 }
547 } elsif ($style eq 'colour') {
548 16 ▶ if (defined $request) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $request) 16 0 16
549 16 my $req = lc($request);
550  
551 16 ▶ if (exists &Data::URIID::Colour::new) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists &Data::URIID::Colour::new) 0 16 16
552 0 ▶ eval { $opts{displaycolour} //= Data::URIID::Colour->new(rgb => $request) };
Condition0%0/3
$opts{"displaycolour"} //= "Data::URIID::Colour"->new("rgb", $request)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"displaycolour"} //= "Data::URIID::Colour"->new("rgb", $request)
$opts{"displaycolour"} "Data::URIID::Colour"->new("rgb", $request)
Truth table0%0/3
A //= B
A= $opts{"displaycolour"}B= "Data::URIID::Colour"->new("rgb", $request)
ABresult
1X1
011
000
553 }
554  
555 # Ensure our requests are always in standard format, at least for now.
556 16 ▶ delete $opts{request} if length($request) != 7;
Branch: 1 branch
BranchTrueFalseTotal
if length $request != 7 0 16 16
557  
558 16 ▶ $req = sprintf('#%s%s%s', $1 x 6, $2 x 6, $3 x 6) if $req =~ /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/;
Branch: 1 branch
BranchTrueFalseTotal
if $req =~ /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/u 16 0 16
559 16 ▶ $req = sprintf('#%s%s%s', $1 x 3, $2 x 3, $3 x 3) if $req =~ /^#([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})$/;
Branch: 1 branch
BranchTrueFalseTotal
if $req =~ /^#([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})$/u 0 16 16
560  
561 16 ▶ if ($req =~ /^#[a-f0-9]{36}$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req =~ /^#[a-f0-9]{36}$/u) { } 16 0 16
562 16 ▶ $opts{input} //= $req;
Condition33%1/3
$opts{"input"} //= $req
l!l&&r!l&&!r
0160
MC/DC0%0/2
$opts{"input"} //= $req
$opts{"input"} $req
Truth table33%1/3
A //= B
A= $opts{"input"}B= $req
ABresult
1X1
011
000
563 } else {
564 0 croak 'Bad format for colour';
565 }
566 }
567 } else {
568 0 croak 'Style not supported: '.$style;
569 }
570 }
571  
572 248 ▶ croak 'No valid style/request or input is provided' unless defined $opts{input};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"input"} 1 247 248
573  
574 {
575 247 ▶ my $ns = ref($opts{namespace}) ? $opts{namespace}->uuid(no_defaults => 1) : $opts{namespace};
Branch: 1 branch
BranchTrueFalseTotal
ref $opts{'namespace'} ? : 124 123 247
576 247 my $uuid = $pkg->_uuid_v5($ns, $opts{input});
577 247 my $tag = Data::Identifier->new(uuid => $uuid, displayname => $opts{displayname});
578 247 foreach my $key (qw(request displaycolour description icontext displayname)) {
579 1235 ▶ $tag->{$key} //= $opts{$key} if defined $opts{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{$key} 517 718 1235
Condition66%2/3
$tag->{$key} //= $opts{$key}
l!l&&r!l&&!r
1963210
MC/DC0%0/2
$tag->{$key} //= $opts{$key}
$tag->{$key} $opts{$key}
Truth table66%2/3
A //= B
A= $tag->{$key}B= $opts{$key}
ABresult
1X1
011
000
580 }
581 0 ▶ $tag->_add_tagnames(ref $opts{tagname} ? @{$opts{tagname}} : $opts{tagname}) if defined $opts{tagname};
Branch: 2 branches
BranchTrueFalseTotal
if defined $opts{"tagname"} 16 231 247
ref $opts{'tagname'} ? : 0 16 16
582 247 ▶ $tag->{generator} //= $generator;
Condition100%3/3
$tag->{"generator"} //= $generator
l!l&&r!l&&!r
122224
MC/DC100%2/2
$tag->{"generator"} //= $generator
$tag->{"generator"} $generator
Truth table100%3/3
A //= B
A= $tag->{"generator"}B= $generator
ABresult
1X1
011
000
583 247 return $tag;
584 }
585 }
586  
587 # ---- Private helpers ----
588  
589 1 ▶sub _register_generator {
Subroutine _register_generator: called CC=5 SCAR=16.8
590 1 my ($pkg, $generator, %opts) = @_;
591 1 ▶ my $g = $_generators{$generator->ise} //= {};
Condition50%1/2
$_generators{$generator->ise} //= {}
l!l
01
MC/DC0%0/1
$_generators{$generator->ise} //= {}
$_generators{$generator->ise}
Truth table50%1/2
A
A= $_generators{$generator->ise}
Aresult
11
00
592  
593 1 foreach my $key (keys %opts) {
594 3 ▶ my $v = $opts{$key} // next;
Condition100%2/2
$opts{$key} // (next)
l!l
21
MC/DC100%1/1
$opts{$key} // (next)
$opts{$key}
Truth table100%2/2
A
A= $opts{$key}
Aresult
11
00
595  
596 2 ▶ $g->{$key} //= $v;
Condition33%1/3
$g->{$key} //= $v
l!l&&r!l&&!r
020
MC/DC0%0/2
$g->{$key} //= $v
$g->{$key} $v
Truth table33%1/3
A //= B
A= $g->{$key}B= $v
ABresult
1X1
011
000
597 }
598 }
599  
600 0 ▶sub _available_module {
Subroutine _available_module: not called CC=5 SCAR=34.0
601 0 my (@modules) = @_;
602 0 state $tried = {};
603  
604 0 foreach my $module (@modules) {
605 0 ▶ if (exists $tried->{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tried->{$module}) { } 0 0 0
606 0 ▶ next unless $tried->{$module};
Branch: 1 branch
BranchTrueFalseTotal
unless $tried->{$module} 0 0 0
607 0 return $module;
608 } else {
609 0 my $res = eval {
610 0 my $modname = $module =~ s#::#/#gr;
611 0 require $modname.'.pm';
612 0 1;
613 };
614 0 $tried->{$module} = $res;
615 0 ▶ return $module if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
616 }
617 }
618  
619 0 croak 'Found none of modules ['.join(', ', @modules).']';
620 }
621  
622 606 ▶sub _finish {
Subroutine _finish: called CC=1 SCAR=0.0
623 606 my ($raw, $version) = @_;
624 606 substr($raw, 6, 1, chr((ord(substr($raw, 6, 1)) & 0x0F) | ($version << 4)));
625 606 substr($raw, 8, 1, chr((ord(substr($raw, 8, 1)) & 0x3F) | 0x80));
626 606 return join('-', unpack('H8H4H4H4H12', $raw));
627 }
628  
629 0 ▶sub _random {
Subroutine _random: not called CC=11 SCAR=48.8
630 0 my ($pkg, %opts) = @_;
631 0 ▶ my $sources = $opts{sources} // (state $default_sources = [qw(Crypt::URandom UUID4::Tiny Math::Random::Secure UUID::URandom UUID::Tiny::Patch::UseMRS)]);
Condition0%0/3
$opts{"sources"} // (state $default_sources = ["Crypt::URandom", "UUID4::Tiny", "Math::Random::Secure", "UUID::URandom", "UUID::Tiny::Patch::UseMRS"])
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"sources"} // (state $default_sources = ["Crypt::URandom", "UUID4::Tiny", "Math::Random::Secure", "UUID::URandom", "UUID::Tiny::Patch::UseMRS"])
$opts{"sources"} (state $default_sources = ["Crypt::URandom", "UUID4::Tiny", "Math::Random::Secure", "UUID::URandom", "UUID::Tiny::Patch::UseMRS"])
Truth table0%0/3
A // B
A= $opts{"sources"}B= (state $default_sources = ["Crypt::URandom", "UUID4::Tiny", "Math::Random::Secure", "UUID::URandom", "UUID::Tiny::Patch::UseMRS"])
ABresult
1X1
011
000
632 0 my $source = _available_module(@{$sources});
633 0 my $raw;
634  
635 # Secure:
636 0 ▶ if ($source eq 'Crypt::URandom') {
Branch: 7 branches
BranchTrueFalseTotal
if ($source eq 'Crypt::URandom') { } 0 0 0
elsif ($source eq 'UUID4::Tiny') { } 0 0 0
elsif ($source eq 'Math::Random::Secure') { } 0 0 0
elsif ($source eq 'UUID::URandom') { } 0 0 0
elsif ($source eq 'UUID::Tiny::Patch::UseMRS') { } 0 0 0
elsif ($source eq 'UUID::Tiny') { } 0 0 0
elsif ($source eq 'Data::UUID') { } 0 0 0
637 0 $raw = Crypt::URandom::urandom(16);
638 } elsif ($source eq 'UUID4::Tiny') {
639 0 return UUID4::Tiny::create_uuid_string();
640 } elsif ($source eq 'Math::Random::Secure') {
641 0 $raw = join('', map {chr Math::Random::Secure::irand(256)} 0..15);
642 } elsif ($source eq 'UUID::URandom') {
643 0 return UUID::URandom::create_uuid_string();
644 } elsif ($source eq 'UUID::Tiny::Patch::UseMRS') {
645 0 return UUID::Tiny::create_uuid_as_string(UUID::Tiny::UUID_RANDOM());
646  
647 # Insecure:
648 } elsif ($source eq 'UUID::Tiny') {
649 0 return UUID::Tiny::create_uuid_as_string(UUID::Tiny::UUID_RANDOM());
650 } elsif ($source eq 'Data::UUID') {
651 0 require Data::UUID;
652 0 return Data::UUID->create_str;
653 #} elsif ($source eq '') {
654 } else {
655 0 croak 'Invalid/unsupported source';
656 }
657  
658 0 ▶ if (defined($raw) && length($raw) == 16) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $raw and length $raw == 16) 0 0 0
Condition0%0/3
defined $raw and length $raw == 16
!ll&&!rl&&r
000
MC/DC0%0/2
defined $raw and length $raw == 16
defined $raw length $raw == 16
Truth table0%0/3
A and B
A= defined $rawB= length $raw == 16
ABresult
0X0
100
111
659 0 return _finish($raw, 4);
660 }
661  
662 0 croak 'Bug!';
663 }
664  
665 606 ▶sub _uuid_v5 {
Subroutine _uuid_v5: called CC=3 SCAR=11.1
666 606 my ($pkg, $ns, $data) = @_;
667 606 my $digest = Digest->new('SHA-1');
668  
669 606 ▶ $ns = $ns->uuid(no_defaults => 1) if ref $ns;
Branch: 1 branch
BranchTrueFalseTotal
if ref $ns 0 606 606
670  
671 606 $ns = pack('H*', $ns =~ tr/-//dr);
672  
673 606 ▶ croak 'Invalid namespace given' unless length($ns) == 16;
Branch: 1 branch
BranchTrueFalseTotal
unless length $ns == 16 0 606 606
674  
675 606 $digest->add($ns);
676 606 $digest->add($data);
677  
678 606 return _finish(substr($digest->digest, 0, 16), 5);
679 }
680  
681 4 1;
682  
683 __END__
« Identifier/Cloudlet.pm ↑ Summary Identifier/Util.pm »