| 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() // []
MC/DC100%1/1
shift() // []
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||
| 64 | 21 | ▶ | my $type1 = Scalar::Util::reftype($ref1) // ''; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
builtin::reftype($ref1) // ""
MC/DC100%1/1
builtin::reftype($ref1) // ""
builtin::reftype($ref1)
Truth table100%2/2
A
A= builtin::reftype($ref1)
| |||||||||||||||||||||||||||||||||||||
| 65 | 21 | ▶ | my $type0 = Scalar::Util::reftype($ref0) // ''; | ||||||||||||||||||||||||||||||||||
|
Condition100%2/2
builtin::reftype($ref0) // ""
MC/DC100%1/1
builtin::reftype($ref0) // ""
builtin::reftype($ref0)
Truth table100%2/2
A
A= builtin::reftype($ref0)
| |||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||
| 67 | 21 | ▶ | if (!$sloppy && $type1 ne $type0) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $sloppy and $type1 ne $type0
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
| |||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $class->throw( | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$type0 || 'SCALAR'
MC/DC0%0/1
$type0 || 'SCALAR'
$type0
Truth table0%0/2
A
A= $type0
| |||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$type1 eq "" or $type1 eq "CODE"
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"
| |||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $ref0->[0] eq "" and ref $ref0->[1] ne ""
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 ""
| |||||||||||||||||||||||||||||||||||||
| 81 | # KEYVAL | ||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | for (my $i = 0; $i < @$ref1; $i += 2) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||