Quiq/Database/ResultSet/Array.pm

filter: Statementstmt 75.6% 28 / 37 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 100% 4 / 4 totaltotal 75.8% 44 / 58 CC 7 SCAR 14.1
CC
7
Cov
73%
index
12.0
columnIndex
3.1
lookupSub
3.0
CRAP 4.1
« Quiq/Html/Widget/FileUpload.pm ↑ Summary Quiq/Sql/Composer.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Database::ResultSet::Array - Liste von Datensätzen in Array-Repräsentation
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Database::ResultSet>
12  
13 =head1 DESCRIPTION
14  
15 Ein Objekt der Klasse repräsentiert eine Liste von gleichartigen
16 Datensätzen in Array-Repräsentation.
17  
18 =cut
19  
20 # -----------------------------------------------------------------------------
21  
22 package Quiq::Database::ResultSet::Array;
23 9 ▶use base qw/Quiq::Database::ResultSet/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 9 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 9 our $VERSION = '1.240';
30  
31 9 ▶use Quiq::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 # -----------------------------------------------------------------------------
34  
35 =head1 METHODS
36  
37 =head2 Miscellaneous
38  
39 =head3 columnIndex() - Liefere Index des Kolumnentitels
40  
41 =head4 Synopsis
42  
43 $idx = $tab->columnIndex($title);
44  
45 =head4 Description
46  
47 Liefere den Index der Kolumne mit dem Titel $title. Existiert die
48 Kolumne nicht, löse eine Exception aus.
49  
50 =cut
51  
52 # -----------------------------------------------------------------------------
53  
54 2 ▶sub columnIndex {
Subroutine columnIndex: called CC=3 SCAR=11.2
Pod documented
55 2 my ($self,$key) = @_;
56  
57 2 my $titleA = $self->{'titles'};
58 2 ▶ for (my $i = 0; $i < @$titleA; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$titleA) 4 0 4
59 4 ▶ if ($titleA->[$i] eq $key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($titleA->[$i] eq $key) 2 2 4
60 2 return $i;
61 }
62 }
63  
64 0 $self->throw('TAB-00002: Kolumne existiert nicht',Column=>$key);
65 }
66  
67 # -----------------------------------------------------------------------------
68  
69 =head3 defaultRowClass() - Liefere Namen der Default-Rowklasse
70  
71 =head4 Synopsis
72  
73 $rowClass = $class->defaultRowClass;
74  
75 =head4 Description
76  
77 Liefere den Namen der Default-Rowklasse: 'Quiq::Database::Row::Array'
78  
79 Auf die Default-Rowklasse werden Datensätze instantiiert, für die
80 bei der Instantiierung einer Table-Klasse keine Row-Klasse
81 explizit angegeben wurde.
82  
83 =cut
84  
85 # -----------------------------------------------------------------------------
86  
87 0 ▶sub defaultRowClass {
Subroutine defaultRowClass: not called CC=1 SCAR=6.9
Pod documented
88 0 return 'Quiq::Database::Row::Array';
89 }
90  
91 # -----------------------------------------------------------------------------
92  
93 =head2 Subclass Implementation
94  
95 =head3 lookupSub() - Suche Datensatz
96  
97 =head4 Synopsis
98  
99 $row = $tab->lookupSub($key=>$val);
100  
101 =head4 Description
102  
103 Durchsuche die Tabelle nach dem ersten Datensatz, dessen
104 Attribut $key den Wert $val besitzt und liefere diesen zurück.
105 Erfüllt kein Datensatz das Kriterium, liefere undef.
106  
107 =head4 Details
108  
109 Wird durch Basisklasse getestet
110  
111 =cut
112  
113 # -----------------------------------------------------------------------------
114  
115 2 ▶sub lookupSub {
Subroutine lookupSub: called CC=3 SCAR=11.0
Pod documented
116 2 my ($self,$key,$val) = @_;
117  
118 2 my $idx = $self->columnIndex($key);
119  
120 2 for my $row (@{$self->rows}) {
121 21 ▶ if ($row->[$idx] eq $val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->[$idx] eq $val) 1 20 21
122 1 return $row;
123 }
124 }
125  
126 1 return undef;
127 }
128  
129 # -----------------------------------------------------------------------------
130  
131 =head3 index() - Indiziere Tabelle nach Kolumne
132  
133 =head4 Synopsis
134  
135 %idx|$idxH = $tab->index($key);
136  
137 =cut
138  
139 # -----------------------------------------------------------------------------
140  
141 0 ▶sub index {
Subroutine index: not called CC=3 SCAR=24.8
Pod documented
142 0 my ($self,$key) = @_;
143  
144 0 my $idx = $self->columnIndex($key);
145  
146 0 my %idx;
147 0 for my $row (@{$self->rows}) {
148 0 $idx{$row->[$idx]} = $row;
149 }
150  
151 0 ▶ return wantarray? %idx: Quiq::Hash->new(\%idx)->unlockKeys;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
152 }
153  
154 # -----------------------------------------------------------------------------
155  
156 =head1 VERSION
157  
158 1.240
159  
160 =head1 AUTHOR
161  
162 Frank Seitz, L<http://fseitz.de/>
163  
164 =head1 COPYRIGHT
165  
166 Copyright (C) 2026 Frank Seitz
167  
168 =head1 LICENSE
169  
170 This code is free software; you can redistribute it and/or modify
171 it under the same terms as Perl itself.
172  
173 =cut
174  
175 # -----------------------------------------------------------------------------
176  
177 9 1;
178  
179 # eof
« Quiq/Html/Widget/FileUpload.pm ↑ Summary Quiq/Sql/Composer.pm »