Quiq/Database/Row/Array.pm

filter: Statementstmt 84.3% 27 / 32 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 100% 5 / 5 totaltotal 83.0% 44 / 53 CC 4 SCAR 7.7
CC
4
Cov
82%
asLine
6.0
new
2.0
asArray
2.0
CRAP 2.2
« Quiq/JQuery/Accordion.pm ↑ Summary Quiq/Html/Component/Bundle.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Database::Row::Array - Datensatz als Array
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Database::Row>
12  
13 =head1 DESCRIPTION
14  
15 Ein Objekt der Klasse repräsentiert einen Datensatz mit
16 einer einfachen Array-Repräsentation.
17  
18 Das Objekt ist eine Liste von Attributwerten, es besitzt
19 keine weitere Information über Titel, Datensatz-Status usw.
20  
21 =cut
22  
23 # -----------------------------------------------------------------------------
24  
25 package Quiq::Database::Row::Array;
26 9 ▶use base qw/Quiq::Database::Row/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 9 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 9 our $VERSION = '1.240';
33  
34 # -----------------------------------------------------------------------------
35  
36 9 our $TableClass = 'Quiq::Database::ResultSet::Array'; # Default-Tabellenklasse
37  
38 # -----------------------------------------------------------------------------
39  
40 =head1 METHODS
41  
42 =head2 Konstruktor
43  
44 =head3 new() - Konstruktor
45  
46 =head4 Synopsis
47  
48 $row = $class->new(\@values);
49 $row = $class->new(\@titles,\@values);
50  
51 =head4 Description
52  
53 Instantiiere ein Datensatz-Array-Objekt mit den Kolumnenwerten
54 @values und liefere eine Referenz auf dieses Objekt zurück.
55  
56 Beim einparametrigen Aufruf wird @values einfach auf die
57 Klasse geblesst.
58  
59 Der zweiparametrige Aufruf ist der normierte Aufruf, mit dem
60 $cur->fetch() Datensatzobjekte instantiiert. In dem Fall
61 kopieren wir das Array, da DBI das Array wiederbenutzt
62 (readonly-Array).
63  
64 =cut
65  
66 # -----------------------------------------------------------------------------
67  
68 58 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
69 58 my $class = shift;
70  
71 58 ▶ if (@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 57 1 58
72 # Aufruf aus $cur->fetch() heraus. Wir kopieren das
73 # Array, da DBI das Array wiederbenutzt (readonly-Array).
74 # Bei anderen Schnittstellen (die momentan nicht existieren)
75 # ist ein kopieren eventuell nicht notwendig, dies sollten
76 # wir dann auf irgend einem Wege unterscheiden.
77 57 return bless [@{$_[1]}],$class;
78 }
79  
80 1 return bless $_[0],$class;
81 }
82  
83 # -----------------------------------------------------------------------------
84  
85 =head2 Common
86  
87 =head3 asArray() - Liefere Datensatz als Array
88  
89 =head4 Synopsis
90  
91 $arr|@arr = $row->asArray;
92  
93 =head4 Description
94  
95 Liefere den Datensatz als Array, entweder in Form einer Referenz
96 (Skalarkontext) oder als Array von Werten (Listkontext).
97  
98 Da der Datensatz bereits ein Array ist, scheint die Methode
99 überflüssig. Sie existiert jedoch, damit Object-Rows und
100 Array-Rows einheitlich behandelt werden können.
101  
102 =cut
103  
104 # -----------------------------------------------------------------------------
105  
106 26 ▶sub asArray {
Subroutine asArray: called CC=2 SCAR=6.9
Pod documented
107 26 ▶ return wantarray? @{$_[0]}: $_[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 19 26
108 }
109  
110 # -----------------------------------------------------------------------------
111  
112 =head3 asLine() - Liefere Datensatz als Zeichenkette
113  
114 =head4 Synopsis
115  
116 $str = $row->asLine;
117 $str = $row->asLine($colSep);
118  
119 =head4 Alias
120  
121 asString()
122  
123 =head4 Description
124  
125 Liefere den Datensatz als Zeichenkette. Per Default werden die Kolumnen
126 per TAB getrennt. Der Trenner kann mittels $colSep explizit angegeben
127 werden.
128  
129 =cut
130  
131 # -----------------------------------------------------------------------------
132  
133 0 ▶sub asLine {
Subroutine asLine: not called CC=2 SCAR=17.9
Pod documented
134 0 my $self = shift;
135 0 ▶ my $colSep = @_? shift: "\t";
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
136 0 return join $colSep,@$self;
137 }
138  
139 {
140 9 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
141 9 *asString = \&asLine;
142 }
143  
144 # -----------------------------------------------------------------------------
145  
146 =head3 copy() - Kopiere Datensatz
147  
148 =head4 Synopsis
149  
150 $newRow = $row->copy;
151  
152 =cut
153  
154 # -----------------------------------------------------------------------------
155  
156 0 ▶sub copy {
Subroutine copy: not called CC=1 SCAR=6.9
Pod documented
157 0 my $self = shift;
158 0 return bless [@$self],ref($self);
159 }
160  
161 # -----------------------------------------------------------------------------
162  
163 =head3 isRaw() - Liefere, ob Klasse Raw-Datensätze repräsentiert
164  
165 =head4 Synopsis
166  
167 $bool = $row->isRaw;
168  
169 =cut
170  
171 # -----------------------------------------------------------------------------
172  
173 2 ▶sub isRaw {
Subroutine isRaw: called CC=1 SCAR=0.0
Pod documented
174 2 return 1;
175 }
176  
177 # -----------------------------------------------------------------------------
178  
179 =head1 VERSION
180  
181 1.240
182  
183 =head1 AUTHOR
184  
185 Frank Seitz, L<http://fseitz.de/>
186  
187 =head1 COPYRIGHT
188  
189 Copyright (C) 2026 Frank Seitz
190  
191 =head1 LICENSE
192  
193 This code is free software; you can redistribute it and/or modify
194 it under the same terms as Perl itself.
195  
196 =cut
197  
198 # -----------------------------------------------------------------------------
199  
200 9 1;
201  
202 # eof
« Quiq/JQuery/Accordion.pm ↑ Summary Quiq/Html/Component/Bundle.pm »