lib/Test2/Harness/UI/UUID.pm

filter: Statementstmt 90.9% 101 / 111 Branchbran 83.3% 45 / 54 Conditioncond 75.0% 33 / 44 MC/DCmcdc 44.0% 11 / 25 Subroutinesub 88.0% 22 / 25 Podpod 0.0% 0 / 12 totaltotal 78.2% 212 / 271 CC 46 SCAR 23.0
CC
46
Cov
86%
_uuid_mass_flate
21.8
gen_deflated_uuid
12.0
uuid_deflate
7.0
CRAP 9.9
« lib/App/Yath/Tester/UI.pm ↑ Summary lib/Test2/Harness/Renderer/UIDB.pm »
1 package Test2::Harness::UI::UUID;
2 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 10 ▶use overload(
Subroutine BEGIN: called CC=1 SCAR=0.0
6 fallback => 1,
7 421 ▶ '""' => sub { $_[0]->magic_stringify },
Subroutine __ANON__: called CC=1 SCAR=0.0
8 659 ▶ bool => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
9 10 );
10  
11 10 ▶use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Scalar::Util qw/blessed reftype/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use Test2::Harness::Util qw/looks_like_uuid/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use Test2::Harness::Util::UUID qw/UG/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 10 require Test2::Harness::Util::UUID;
17 10 require bytes;
18  
19 10 ▶use Importer Importer => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 10 our @EXPORT_OK = qw/uuid_inflate uuid_deflate gen_uuid gen_deflated_uuid uuid_mass_inflate uuid_mass_deflate looks_like_uuid_36_or_16/;
21  
22 7 ▶sub gen_uuid {
Subroutine gen_uuid: called CC=1 SCAR=0.0
Pod undocumented
23 7 my $binary = UG()->create();
24 7 my $forsql = _reorder_bin($binary);
25 7 my $string = UG()->to_string($binary);
26  
27 7 return bless(
28 {
29 binary => $forsql,
30 string => lc($string),
31 },
32 __PACKAGE__
33 );
34 }
35  
36 # gen_uuid() builds both forms of the id and blesses them. A row headed
37 # straight for the database needs only the stored form.
38 0 ▶sub gen_deflated_uuid {
Subroutine gen_deflated_uuid: not called CC=3 SCAR=24.8
Pod undocumented
39 0 my $binary = UG()->create();
40  
41 0 ▶ return _reorder_bin($binary) if $Test2::Harness::UI::Schema::LOADED && $Test2::Harness::UI::Schema::LOADED =~ m/mysql/i;
Branch: 1 branch
BranchTrueFalseTotal
if $Test2::Harness::UI::Schema::LOADED and $Test2::Harness::UI::Schema::LOADED =~ /mysql/i 0 0 0
Condition0%0/3
$Test2::Harness::UI::Schema::LOADED and $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
!ll&&!rl&&r
000
MC/DC0%0/2
$Test2::Harness::UI::Schema::LOADED and $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
$Test2::Harness::UI::Schema::LOADED $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
Truth table0%0/3
A and B
A= $Test2::Harness::UI::Schema::LOADEDB= $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
ABresult
0X0
100
111
42  
43 0 return lc(UG()->to_string($binary));
44 }
45  
46 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
47 0 my $class = shift;
48 0 my ($val) = @_;
49 0 ▶ $val //= lc(Test2::Harness::Util::UUID::gen_uuid());
Condition0%0/2
$val //= lc Test2::Harness::Util::UUID::gen_uuid()
l!l
00
MC/DC0%0/1
$val //= lc Test2::Harness::Util::UUID::gen_uuid()
$val
Truth table0%0/2
A
A= $val
Aresult
11
00
50 0 return uuid_inflate($val);
51 }
52  
53 87 ▶sub _reorder_bin {
Subroutine _reorder_bin: called CC=1 SCAR=0.0
54 87 my $bin = shift;
55  
56 87 return join '' => (
57 scalar(reverse(substr($bin, 6, 2))),
58 scalar(reverse(substr($bin, 4, 2))),
59 scalar(reverse(substr($bin, 0, 4))),
60 substr($bin, 8, 8),
61 );
62 }
63  
64 66 ▶sub _unorder_bin {
Subroutine _unorder_bin: called CC=1 SCAR=0.0
65 66 my ($bin) = @_;
66  
67 66 return join '' => (
68 scalar(reverse(substr($bin, 4, 4))),
69 scalar(reverse(substr($bin, 2, 2))),
70 scalar(reverse(substr($bin, 0, 2))),
71 substr($bin, 8, 8),
72 );
73 }
74  
75 219 ▶sub uuid_inflate {
Subroutine uuid_inflate: called CC=7 SCAR=19.5
Pod undocumented
76 219 my ($val) = @_;
77 219 ▶ return undef unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 9 210 219
78 210 ▶ return $val if blessed($val) && $val->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($val) and $val->isa(__PACKAGE__) 52 158 210
Condition66%2/3
builtin::blessed($val) and $val->isa(__PACKAGE__)
!ll&&!rl&&r
158052
MC/DC50%1/2
builtin::blessed($val) and $val->isa(__PACKAGE__)
builtin::blessed($val) $val->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($val)B= $val->isa(__PACKAGE__)
ABresult
0X0
100
111
79  
80 158 my $size = bytes::length($val);
81  
82 158 my $out;
83 158 ▶ if ($size == 16) {
Branch: 2 branches
BranchTrueFalseTotal
if ($size == 16) { } 66 92 158
elsif ($size == 36) { } 80 12 92
84 66 my $unbin = UG()->to_string(_unorder_bin($val));
85  
86 66 $out = {
87 string => lc($unbin),
88 binary => $val,
89 };
90 }
91 elsif ($size == 36) {
92 80 $val = $val;
93  
94 80 my $bin = UG()->from_string($val);
95  
96 80 $out = {
97 string => lc($val),
98 binary => _reorder_bin($bin),
99 };
100 }
101  
102 158 ▶ return undef unless $out;
Branch: 1 branch
BranchTrueFalseTotal
unless $out 12 146 158
103  
104 146 return bless($out, __PACKAGE__);
105 }
106  
107 421 ▶sub magic_stringify {
Subroutine magic_stringify: called CC=6 SCAR=18.2
Pod undocumented
108 421 my $self = shift;
109 421 ▶ return $self->{string} unless $Test2::Harness::UI::Schema::LOADED && $Test2::Harness::UI::Schema::LOADED =~ m/mysql/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $Test2::Harness::UI::Schema::LOADED and $Test2::Harness::UI::Schema::LOADED =~ /mysql/i 212 209 421
Condition100%3/3
$Test2::Harness::UI::Schema::LOADED and $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
!ll&&!rl&&r
3209209
MC/DC100%2/2
$Test2::Harness::UI::Schema::LOADED and $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
$Test2::Harness::UI::Schema::LOADED $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
Truth table100%3/3
A and B
A= $Test2::Harness::UI::Schema::LOADEDB= $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
ABresult
0X0
100
111
110  
111 209 my $i = 0;
112 209 ▶ while (my @call = caller($i++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@call) = caller $i++) 627 0 627
113 627 ▶ return $self->{binary} if $call[0] =~ m/DBIx::Class::Storage::DBI/;
Branch: 1 branch
BranchTrueFalseTotal
if $call[0] =~ /DBIx::Class::Storage::DBI/ 0 627 627
114 627 ▶ return $self->{string} if $i > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $i > 2 209 418 627
115 }
116  
117 0 $self->{string};
118 }
119  
120 140 ▶sub uuid_deflate {
Subroutine uuid_deflate: called CC=7 SCAR=19.5
Pod undocumented
121 140 my ($val) = @_;
122 140 ▶ return undef unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 9 131 140
123 131 ▶ $val = uuid_inflate($val) unless blessed($val) && $val->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($val) and $val->isa(__PACKAGE__) 74 57 131
Condition66%2/3
builtin::blessed($val) and $val->isa(__PACKAGE__)
!ll&&!rl&&r
74057
MC/DC50%1/2
builtin::blessed($val) and $val->isa(__PACKAGE__)
builtin::blessed($val) $val->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($val)B= $val->isa(__PACKAGE__)
ABresult
0X0
100
111
124 131 ▶ return undef unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 6 125 131
125 125 ▶ return $val->{binary} if $Test2::Harness::UI::Schema::LOADED && $Test2::Harness::UI::Schema::LOADED =~ m/mysql/i;
Branch: 1 branch
BranchTrueFalseTotal
if $Test2::Harness::UI::Schema::LOADED and $Test2::Harness::UI::Schema::LOADED =~ /mysql/i 63 62 125
Condition66%2/3
$Test2::Harness::UI::Schema::LOADED and $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
!ll&&!rl&&r
06263
MC/DC50%1/2
$Test2::Harness::UI::Schema::LOADED and $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
$Test2::Harness::UI::Schema::LOADED $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
Truth table66%2/3
A and B
A= $Test2::Harness::UI::Schema::LOADEDB= $Test2::Harness::UI::Schema::LOADED =~ /mysql/i
ABresult
0X0
100
111
126 62 return $val->{string};
127 }
128  
129 10 *deflate = \&uuid_deflate;
130 10 *inflate = \&uuid_inflate;
131  
132 33 ▶sub binary { $_[0]->{binary} }
Subroutine binary: called CC=1 SCAR=0.0
Pod undocumented
133 53 ▶sub string { $_[0]->{string} }
Subroutine string: called CC=1 SCAR=0.0
Pod undocumented
134 0 ▶sub TO_JSON { $_[0]->{string} }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
135  
136 6 ▶sub uuid_mass_inflate { _uuid_mass_flate($_[0], \&uuid_inflate, \&uuid_mass_inflate) }
Subroutine uuid_mass_inflate: called CC=1 SCAR=0.0
Pod undocumented
137 6 ▶sub uuid_mass_deflate { _uuid_mass_flate($_[0], \&uuid_deflate, \&uuid_mass_deflate) }
Subroutine uuid_mass_deflate: called CC=1 SCAR=0.0
Pod undocumented
138  
139 372 ▶sub _uuid_mass_flate {
Subroutine _uuid_mass_flate: called CC=21 SCAR=30.8
140 372 my ($val_do_not_use, $flate, $mass_flate) = @_;
141 372 ▶ return $_[0] unless $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 372 372
142  
143 372 ▶ if (blessed($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_[0])) 104 268 372
144 104 ▶ return $_[0] = $flate->($_[0]) if $_[0]->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->isa(__PACKAGE__) 104 0 104
145 0 return $_[0];
146 }
147  
148 268 ▶ return $_[0] = $flate->($_[0]) if looks_like_uuid_36_or_16($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if looks_like_uuid_36_or_16($_[0]) 136 132 268
149  
150 132 ▶ my $type = reftype($_[0]) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $type = builtin::reftype($_[0]) or return 132 0 132
151  
152 132 ▶ if ($type eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'HASH') { } 48 84 132
elsif ($type eq 'ARRAY') { } 84 0 84
153 my @list = grep {
154 252 my $ok = 1;
155 252 ▶ $ok &&= $_ eq 'owner' || (m/_(id|key)$/ && $_ ne 'trace_id');
Condition77%7/9
$ok &&= $_ eq "owner" || /_(id|key)$/ && $_ ne "trace_id"
!ll&&!rl&&r
0132120
$_ eq 'owner' || /_(id|key)$/ && $_ ne 'trace_id'
l!l&&r!l&&!r
3684132
/_(id|key)$/ and $_ ne "trace_id"
!ll&&!rl&&r
132084
MC/DC0%0/4
$ok &&= $_ eq "owner" || /_(id|key)$/ && $_ ne "trace_id"
$ok $_ eq 'owner' /_(id|key)$/ $_ ne "trace_id"
Truth table0%0/5
A &&= B || C and D
A= $okB= $_ eq 'owner'C= /_(id|key)$/D= $_ ne "trace_id"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
156 252 ▶ $ok &&= looks_like_uuid_36_or_16($_[0]->{$_});
Condition66%2/3
$ok &&= looks_like_uuid_36_or_16($_[0]{$_})
!ll&&!rl&&r
1320120
MC/DC50%1/2
$ok &&= looks_like_uuid_36_or_16($_[0]{$_})
$ok looks_like_uuid_36_or_16($_[0]{$_})
Truth table66%2/3
A &&= B
A= $okB= looks_like_uuid_36_or_16($_[0]{$_})
ABresult
0X0
100
111
157  
158 252 ▶ my $rt = reftype($_[0]->{$_}) // '';
Condition100%2/2
builtin::reftype($_[0]{$_}) // ""
l!l
144108
MC/DC100%1/1
builtin::reftype($_[0]{$_}) // ""
builtin::reftype($_[0]{$_})
Truth table100%2/2
A
A= builtin::reftype($_[0]{$_})
Aresult
11
00
159 252 ▶ $ok ||= $rt eq 'HASH' || $rt eq 'ARRAY';
Condition100%6/6
$ok ||= $rt eq "HASH" || $rt eq "ARRAY"
l!l&&r!l&&!r
1209636
$rt eq 'HASH' || $rt eq 'ARRAY'
l!l&&r!l&&!r
247236
MC/DC0%0/3
$ok ||= $rt eq "HASH" || $rt eq "ARRAY"
$ok $rt eq 'HASH' $rt eq 'ARRAY'
Truth table0%0/4
A ||= B || C
A= $okB= $rt eq 'HASH'C= $rt eq 'ARRAY'
ABCresult
1XX1
01X1
0011
0000
160  
161 252 $ok;
162 48 } keys %{$_[0]};
163  
164 48 $_[0]->{$_} = _uuid_mass_flate($_[0]->{$_}, $flate, $mass_flate) for @list;
165 }
166 elsif($type eq 'ARRAY') {
167 84 $_ = _uuid_mass_flate($_, $flate, $mass_flate) for grep {
168 168 my $ok = looks_like_uuid_36_or_16($_);
169  
170 168 ▶ my $dt = reftype($_) // '';
Condition100%2/2
builtin::reftype($_) // ""
l!l
8088
MC/DC100%1/1
builtin::reftype($_) // ""
builtin::reftype($_)
Truth table100%2/2
A
A= builtin::reftype($_)
Aresult
11
00
171 168 ▶ $ok ||= 1 if $dt eq 'HASH' || $dt eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $dt eq "HASH" or $dt eq "ARRAY" 80 88 168
Condition100%5/5
$dt eq "HASH" or $dt eq "ARRAY"
l!l&&r!l&&!r
681288
$ok ||= 1
l!l
5624
MC/DC100%2/2
$dt eq "HASH" or $dt eq "ARRAY"
$dt eq "HASH" $dt eq "ARRAY"
MC/DC100%1/1
$ok ||= 1
$ok
Truth table100%3/3
A or B
A= $dt eq "HASH"B= $dt eq "ARRAY"
ABresult
1X1
011
000
Truth table100%2/2
A
A= $ok
Aresult
11
00
172  
173 168 $ok;
174 84 } @{$_[0]};
175 }
176  
177 132 return $_[0];
178 }
179  
180 561 ▶sub looks_like_uuid_36_or_16 {
Subroutine looks_like_uuid_36_or_16: called CC=6 SCAR=17.9
Pod undocumented
181 561 my ($val) = @_;
182 561 ▶ return 0 unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 561 561
183 561 my $len = length($val);
184  
185 561 ▶ if ($len == 16) {
Branch: 2 branches
BranchTrueFalseTotal
if ($len == 16) { } 135 426 561
elsif ($len == 36) { } 270 156 426
186 135 ▶ return 1 if $val !~ m/^[[:ascii:]]+$/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ /^[[:ascii:]]+$/s 121 14 135
187 14 return 0;
188 }
189 elsif ($len == 36) {
190 270 ▶ return unless $val =~ m/-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ /-/ 12 258 270
191 258 return looks_like_uuid($val);
192 }
193  
194 156 return 0;
195 }
196  
197 10 1;
« lib/App/Yath/Tester/UI.pm ↑ Summary lib/Test2/Harness/Renderer/UIDB.pm »