Quiq/DataStructure.pm

filter: Statementstmt 92.1% 35 / 38 Branchbran 81.2% 13 / 16 Conditioncond 64.7% 11 / 17 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 80.6% 71 / 88 CC 17 SCAR 27.5
CC
17
Cov
83%
validate
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 15.7
« Quiq/Gd/Component/ColorBar.pm ↑ Summary Quiq/ModelCache.pm »
1 # -----------------------------------------------------------------------------
2  
3 =head1 NAME
4  
5 Quiq::DataStructure - Operationen auf einer komplexen Datenstruktur
6  
7 =head1 BASE CLASS
8  
9 L<Quiq::Object>
10  
11 =cut
12  
13 # -----------------------------------------------------------------------------
14  
15 package Quiq::DataStructure;
16 1 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 our $VERSION = '1.240';
23  
24 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # -----------------------------------------------------------------------------
27  
28 =head1 METHODS
29  
30 =head2 Klassenmethoden
31  
32 =head3 validate() - Gleiche Datenstruktur gegen Vorlage ab
33  
34 =head4 Synopsis
35  
36 $class->validate($ref0,$ref1,$sloppy);
37  
38 =head4 Arguments
39  
40 =over 4
41  
42 =item $ref0
43  
44 Datenstruktur als Vorlage
45  
46 =item $ref1
47  
48 Datenstruktur
49  
50 =item $sloppy
51  
52 Wenn "wahr", nur Komponentenvergleich, kein Typvergleich.
53  
54 =back
55  
56 =cut
57  
58 # -----------------------------------------------------------------------------
59  
60 21 ▶sub validate {
Subroutine validate: called CC=17 SCAR=30.0
Pod documented
61 21 my ($class,$ref0,$ref1,$sloppy) = splice @_,0,4;
62 21 ▶ my $keyA = shift // [];
Condition100%2/2
shift() // []
l!l
174
MC/DC100%1/1
shift() // []
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
63  
64 21 ▶ my $type1 = Scalar::Util::reftype($ref1) // '';
Condition100%2/2
builtin::reftype($ref1) // ""
l!l
813
MC/DC100%1/1
builtin::reftype($ref1) // ""
builtin::reftype($ref1)
Truth table100%2/2
A
A= builtin::reftype($ref1)
Aresult
11
00
65 21 ▶ my $type0 = Scalar::Util::reftype($ref0) // '';
Condition100%2/2
builtin::reftype($ref0) // ""
l!l
813
MC/DC100%1/1
builtin::reftype($ref0) // ""
builtin::reftype($ref0)
Truth table100%2/2
A
A= builtin::reftype($ref0)
Aresult
11
00
66  
67 21 ▶ if (!$sloppy && $type1 ne $type0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $sloppy and $type1 ne $type0) 0 21 21
Condition33%1/3
not $sloppy and $type1 ne $type0
!ll&&!rl&&r
2100
MC/DC0%0/2
not $sloppy and $type1 ne $type0
not $sloppy $type1 ne $type0
Truth table33%1/3
not(A) and B
A= not $sloppyB= $type1 ne $type0
ABresult
0X0
100
111
68 0 ▶ $class->throw(
Condition0%0/2
$type0 || 'SCALAR'
l!l
00
MC/DC0%0/1
$type0 || 'SCALAR'
$type0
Truth table0%0/2
A
A= $type0
Aresult
11
00
69 'VALIDATE-00099: Type mismatch',
70 Path => join('.',@$keyA),
71 Types => "$type1 vs. ".($type0 || 'SCALAR'),
72 );
73 }
74  
75 21 ▶ if ($type1 eq '' || $type1 eq 'CODE') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type1 eq '' or $type1 eq 'CODE') { } 13 8 21
elsif ($type1 eq 'ARRAY') { } 3 5 8
elsif ($type1 eq 'HASH') { } 5 0 5
Condition66%2/3
$type1 eq "" or $type1 eq "CODE"
l!l&&r!l&&!r
1308
MC/DC50%1/2
$type1 eq "" or $type1 eq "CODE"
$type1 eq "" $type1 eq "CODE"
Truth table66%2/3
A or B
A= $type1 eq ""B= $type1 eq "CODE"
ABresult
1X1
011
000
76 # SCALAR, CODE
77 13 return;
78 }
79 elsif ($type1 eq 'ARRAY') {
80 3 ▶ if (ref($ref0->[0]) eq '' && ref($ref0->[1]) ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref0->[0] eq "" and ref $ref0->[1] ne "") 2 1 3
Condition66%2/3
ref $ref0->[0] eq "" and ref $ref0->[1] ne ""
!ll&&!rl&&r
012
MC/DC50%1/2
ref $ref0->[0] eq "" and ref $ref0->[1] ne ""
ref $ref0->[0] eq "" ref $ref0->[1] ne ""
Truth table66%2/3
A and B
A= ref $ref0->[0] eq ""B= ref $ref0->[1] ne ""
ABresult
0X0
100
111
81 # KEYVAL
82 2 ▶ for (my $i = 0; $i < @$ref1; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$ref1) 3 2 5
83 3 $class->validate($ref0->[0],$ref1->[$i],$sloppy);
84 3 $class->validate($ref0->[1],$ref1->[$i+1],$sloppy,
85 [@$keyA,$ref1->[$i]]);
86 }
87 2 return;
88 }
89 # ARRAY
90 1 ▶ for (my $i = 0; $i < @$ref1; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$ref1) 1 1 2
91 1 $class->validate($ref0->[0],$ref1->[$i],$sloppy,[@$keyA,"[$i]"]);
92 }
93 1 return;
94 }
95 elsif ($type1 eq 'HASH') {
96 5 for my $key (keys %$ref1) {
97 13 ▶ if (!exists $ref0->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ref0->{$key}) 0 13 13
98 0 $class->throw(
99 'VALIDATE-00001: Access path does not exist',
100 Path => join('.',@$keyA,$key),
101 );
102 }
103 13 $class->validate($ref0->{$key},$ref1->{$key},$sloppy,
104 [@$keyA,$key]);
105 }
106 5 return;
107 }
108  
109 $class->throw(
110 0 'VALIDATE-00099: Unknown Type',
111 Type => $type1,
112 Path => join('.',@$keyA),
113 );
114 }
115  
116 # -----------------------------------------------------------------------------
117  
118 =head1 VERSION
119  
120 1.240
121  
122 =head1 AUTHOR
123  
124 Frank Seitz, L<http://fseitz.de/>
125  
126 =head1 COPYRIGHT
127  
128 Copyright (C) 2026 Frank Seitz
129  
130 =head1 LICENSE
131  
132 This code is free software; you can redistribute it and/or modify
133 it under the same terms as Perl itself.
134  
135 =cut
136  
137 # -----------------------------------------------------------------------------
138  
139 1 1;
140  
141 # eof
« Quiq/Gd/Component/ColorBar.pm ↑ Summary Quiq/ModelCache.pm »