| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | Quiq::Table - Tabelle | ||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | L<Quiq::Hash> | ||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | Mit Kolumnennamen: | ||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | use Quiq::Table; | ||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||
| 19 | # Daten | ||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | @rows = ( | ||||||||||||||||||||||||||||||||||||||
| 22 | [1, 'A', 76.253], | ||||||||||||||||||||||||||||||||||||||
| 23 | [12, 'AB', 1.7 ], | ||||||||||||||||||||||||||||||||||||||
| 24 | [123,'ABC',9999 ], | ||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | # Objekt instantiieren | ||||||||||||||||||||||||||||||||||||||
| 28 | $tab = Quiq::Table->new(['a','b','c'],\@rows); | ||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | # Werte der Kolumne b | ||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | @values = $tab->values('b'); | ||||||||||||||||||||||||||||||||||||||
| 33 | say "@values"; | ||||||||||||||||||||||||||||||||||||||
| 34 | ==> | ||||||||||||||||||||||||||||||||||||||
| 35 | A AB ABC | ||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | # Ausgabe als Text-Tabelle | ||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | print $tab->asText; | ||||||||||||||||||||||||||||||||||||||
| 40 | ==> | ||||||||||||||||||||||||||||||||||||||
| 41 | | 1 | A | 76.253 | | ||||||||||||||||||||||||||||||||||||||
| 42 | | 12 | AB | 1.700 | | ||||||||||||||||||||||||||||||||||||||
| 43 | | 123 | ABC | 9999.000 | | ||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | Ohne Kolumnennamen: | ||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | use Quiq::Table; | ||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | # Daten | ||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | @rows = ( | ||||||||||||||||||||||||||||||||||||||
| 52 | [1, 'A', 76.253], | ||||||||||||||||||||||||||||||||||||||
| 53 | [12, 'AB', 1.7 ], | ||||||||||||||||||||||||||||||||||||||
| 54 | [123,'ABC',9999 ], | ||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | # Objekt instantiieren | ||||||||||||||||||||||||||||||||||||||
| 58 | $tab = Quiq::Table->new(3,\@rows); | ||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||
| 60 | # Werte der Kolumne 1 (0-basierte Zählung) | ||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||
| 62 | @values = $tab->values(1); | ||||||||||||||||||||||||||||||||||||||
| 63 | say "@values"; | ||||||||||||||||||||||||||||||||||||||
| 64 | ==> | ||||||||||||||||||||||||||||||||||||||
| 65 | A AB ABC | ||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | # Ausgabe als Text-Tabelle | ||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | print $tab->asText; | ||||||||||||||||||||||||||||||||||||||
| 70 | ==> | ||||||||||||||||||||||||||||||||||||||
| 71 | | 1 | A | 76.253 | | ||||||||||||||||||||||||||||||||||||||
| 72 | | 12 | AB | 1.700 | | ||||||||||||||||||||||||||||||||||||||
| 73 | | 123 | ABC | 9999.000 | | ||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||
| 77 | Ein Objekt der Klasse repräsentiert eine Tabelle, also eine Liste | ||||||||||||||||||||||||||||||||||||||
| 78 | von Arrays identischer Größe. Die Kolumnen können über ihre Position | ||||||||||||||||||||||||||||||||||||||
| 79 | oder ihren Namen (sofern definiert) angesprochen werden. | ||||||||||||||||||||||||||||||||||||||
| 80 | Die Klasse kann die Daten in verschiedenen Formaten tabellarisch | ||||||||||||||||||||||||||||||||||||||
| 81 | ausgegeben. | ||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||
| 83 | =head1 EXAMPLE | ||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | Siehe quiq-ls | ||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||
| 91 | package Quiq::Table; | ||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | use base qw/Quiq::Hash/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 96 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | 2 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | use Quiq::Hash; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | use Quiq::Properties; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | use Quiq::TableRow; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | use Quiq::AnsiColor; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||
| 105 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | =head2 Klassenmethoden | ||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||
| 111 | =head3 new() - Konstruktor | ||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | $tab = $class->new($width); | ||||||||||||||||||||||||||||||||||||||
| 116 | $tab = $class->new($width,\@rows); | ||||||||||||||||||||||||||||||||||||||
| 117 | $tab = $class->new(\@columns); | ||||||||||||||||||||||||||||||||||||||
| 118 | $tab = $class->new(\@columns,\@rows); | ||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||
| 120 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||
| 122 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | =item $width | ||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | Anzahl der Kolumnen (Integer). | ||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | =item @columns | ||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||
| 130 | Liste von Kolumnennamen (Array of Strings). | ||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||
| 132 | =item @rows | ||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||
| 134 | Liste von Zeilen (Array of Arrays). | ||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||
| 136 | =back | ||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||
| 138 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||
| 140 | Referenz auf Tabellen-Objekt | ||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||
| 142 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||
| 144 | Instantiiere ein Tabellen-Objekt und liefere eine Referenz auf dieses | ||||||||||||||||||||||||||||||||||||||
| 145 | Objekt zurück. | ||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||
| 149 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 152 | 4 | my ($class,$arg,$rowA) = @_; | |||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||
| 154 | # Objekt instantiieren | ||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | 4 | my $self = $class->SUPER::new( | |||||||||||||||||||||||||||||||||||||
| 157 | columnA => [], | ||||||||||||||||||||||||||||||||||||||
| 158 | columnH => {}, | ||||||||||||||||||||||||||||||||||||||
| 159 | propertyA => undef, | ||||||||||||||||||||||||||||||||||||||
| 160 | rowA => [], | ||||||||||||||||||||||||||||||||||||||
| 161 | width => 0, | ||||||||||||||||||||||||||||||||||||||
| 162 | ); | ||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||
| 164 | # Kolumnen | ||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||
| 166 | 4 | ▶ | if (ref $arg) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 167 | # \@columns | ||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||
| 169 | 3 | my $i = 0; | |||||||||||||||||||||||||||||||||||||
| 170 | $self->set( | ||||||||||||||||||||||||||||||||||||||
| 171 | width => scalar @$arg, | ||||||||||||||||||||||||||||||||||||||
| 172 | columnA => $arg, | ||||||||||||||||||||||||||||||||||||||
| 173 | 3 | columnH => Quiq::Hash->new({map {$_ => $i++} @$arg}), | |||||||||||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||
| 176 | else { | ||||||||||||||||||||||||||||||||||||||
| 177 | # $width | ||||||||||||||||||||||||||||||||||||||
| 178 | 1 | $self->set(width=>$arg); | |||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||
| 181 | # Zeilen | ||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||
| 183 | 4 | for my $row (@$rowA) { | |||||||||||||||||||||||||||||||||||||
| 184 | 9 | $self->push($row); | |||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||
| 187 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||
| 190 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||
| 192 | =head2 Objektmethoden | ||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||
| 194 | =head3 columns() - Liste der Kolumnennamen | ||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||
| 196 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||
| 198 | @columns | $columnA = $tab->columns(@opt); | ||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||
| 200 | =head4 Options | ||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||
| 202 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||
| 204 | =item -sloppy => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||
| 206 | Wirf keine Exception, wenn keine Kolumnennamen definiert sind, sondern | ||||||||||||||||||||||||||||||||||||||
| 207 | liefere eine leere Liste. | ||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||
| 209 | =back | ||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||
| 211 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||
| 213 | Liste der Kolumnennamen (Strings). Im Skalarkontext eine Referenz | ||||||||||||||||||||||||||||||||||||||
| 214 | auf die Liste. | ||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||
| 216 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||
| 218 | Liefere die Liste der Kolumnennamen der Tabelle. | ||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||
| 220 | =cut | ||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||
| 222 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||
| 224 | 3 | ▶ | sub columns { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
columns: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 225 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 226 | # @_: @opt | ||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||
| 228 | # Optionen | ||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||
| 230 | 3 | my $sloppy = 0; | |||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||
| 232 | 3 | $self->parameters(\@_, | |||||||||||||||||||||||||||||||||||||
| 233 | -sloppy => \$sloppy, | ||||||||||||||||||||||||||||||||||||||
| 234 | ); | ||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||
| 236 | # Operation ausführen | ||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||
| 238 | 3 | my $columnA = $self->{'columnA'}; | |||||||||||||||||||||||||||||||||||||
| 239 | 3 | ▶ | if (!@$columnA && !$sloppy) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$columnA or $sloppy
MC/DC0%0/2
@$columnA or $sloppy
@$columnA
$sloppy
Truth table33%1/3
A or B
A= @$columnAB= $sloppy
| |||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $self->throw( | |||||||||||||||||||||||||||||||||||||
| 241 | 'TABLE-00099: No column names defined', | ||||||||||||||||||||||||||||||||||||||
| 242 | ); | ||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||
| 244 | 3 | ▶ | return wantarray? @$columnA: $columnA; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||
| 247 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||
| 249 | =head3 count() - Anzahl der Zeilen | ||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||
| 251 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||
| 253 | $count = $tab->count; | ||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||
| 255 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||
| 257 | Integer | ||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||
| 259 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||
| 261 | Liefere die Anzahl der Zeilen der Tabelle. | ||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||
| 263 | =cut | ||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||
| 265 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||
| 267 | 2 | ▶ | sub count { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 268 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 269 | 2 | return scalar @{$self->{'rowA'}}; | |||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||
| 272 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||
| 274 | =head3 pos() - Position einer Kolumne | ||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||
| 276 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||
| 278 | $pos = $tab->pos($column); | ||||||||||||||||||||||||||||||||||||||
| 279 | $pos = $tab->pos($pos); | ||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||
| 281 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||
| 283 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||
| 285 | =item $column | ||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||
| 287 | Kolumnenname (String). | ||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||
| 289 | =item $pos | ||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||
| 291 | Kolumnenposition (Integer). | ||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||
| 293 | =back | ||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||
| 295 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||
| 297 | Integer | ||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||
| 299 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||
| 301 | Liefere die Position der Kolumne $column in den Zeilen-Arrays. | ||||||||||||||||||||||||||||||||||||||
| 302 | Die Position ist 0-basiert. Ist das Argument eine Zahl (Position), | ||||||||||||||||||||||||||||||||||||||
| 303 | liefere diese unverändert zurück. | ||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||
| 305 | =cut | ||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||
| 307 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||
| 309 | 26 | ▶ | sub pos { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
pos: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 310 | 26 | my ($self,$arg) = @_; | |||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||
| 312 | 26 | ▶ | if ($arg =~ /^[0-9]+$/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 313 | 19 | return $arg; | |||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||
| 316 | 7 | my $columnH = $self->{'columnH'}; | |||||||||||||||||||||||||||||||||||||
| 317 | 7 | ▶ | if (!%$columnH) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $self->throw( | |||||||||||||||||||||||||||||||||||||
| 319 | 'TABLE-00099: No column names defined', | ||||||||||||||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||
| 323 | 7 | return $columnH->{$arg}; | |||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||
| 326 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||
| 328 | =head3 properties() - Eigenschaften einer Kolumne | ||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||
| 330 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||
| 332 | $prp = $tab->properties($pos); | ||||||||||||||||||||||||||||||||||||||
| 333 | $prp = $tab->properties($column); | ||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||
| 335 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||
| 337 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||
| 339 | =item $pos | ||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||
| 341 | (Integer) Kolumnenposition | ||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||
| 343 | =item $column | ||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||
| 345 | (String) Kolumnenname (nur, wenn Kolumennamen definiert sind) | ||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||
| 347 | =back | ||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||
| 349 | =head4 Options | ||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||
| 351 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||
| 353 | =item -withTitles => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||
| 355 | Beziehe die Länge der Kolumnennamen mit ein. D.h, wenn ein Kolumnenname | ||||||||||||||||||||||||||||||||||||||
| 356 | länger ist als der längste Wert, setzte die maximale Länge | ||||||||||||||||||||||||||||||||||||||
| 357 | (Property width) auf die Länge des Kolumnennamens. | ||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||
| 359 | =back | ||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||
| 361 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||
| 363 | Properties-Objekt (Quiq::Properties) | ||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||
| 365 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||
| 367 | Ermittele die Eigenschaften der Werte der Kolumne $column und liefere | ||||||||||||||||||||||||||||||||||||||
| 368 | ein Objekt, das diese Eigenschaften abfragbar zur Verfügung stellt, | ||||||||||||||||||||||||||||||||||||||
| 369 | zurück. Die Eigenschaften werden gecacht, so dass bei einem wiederholten | ||||||||||||||||||||||||||||||||||||||
| 370 | Aufruf die Eigenschaften nicht erneut ermittelt werden müssen. Wird die | ||||||||||||||||||||||||||||||||||||||
| 371 | Tabelle mit push() erweitert, wird der Cache automatisch gelöscht. | ||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||
| 373 | =cut | ||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||
| 375 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||
| 377 | 9 | ▶ | sub properties { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
properties: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 378 | 9 | my ($self,$arg) = splice @_,0,2; | |||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||
| 380 | # Optionen | ||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||
| 382 | 9 | my $withTitles = 0; | |||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||
| 384 | 9 | my $opt = $self->parameters(0,0,\@_, | |||||||||||||||||||||||||||||||||||||
| 385 | -withTitles => \$withTitles, | ||||||||||||||||||||||||||||||||||||||
| 386 | ); | ||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||
| 388 | # Operation ausführen | ||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||
| 390 | 9 | my $pos = $self->pos($arg); | |||||||||||||||||||||||||||||||||||||
| 391 | 9 | my $prp = $self->{'propertyA'}->[$pos]; | |||||||||||||||||||||||||||||||||||||
| 392 | 9 | ▶ | if (!$prp) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 393 | 9 | $prp = Quiq::Properties->new; | |||||||||||||||||||||||||||||||||||||
| 394 | 9 | for my $val ($self->values($pos,-distinct=>1)) { | |||||||||||||||||||||||||||||||||||||
| 395 | 27 | $prp->analyze($val); | |||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||
| 398 | 9 | ▶ | if ($withTitles) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 399 | 3 | my $l = length $self->{'columnA'}->[$pos]; | |||||||||||||||||||||||||||||||||||||
| 400 | 3 | ▶ | if ($l > $prp->width) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 401 | 2 | $prp->width($l); | |||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||
| 405 | 9 | $self->{'propertyA'}->[$pos] = $prp; | |||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||
| 408 | 9 | return $prp; | |||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||
| 411 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||
| 413 | =head3 push() - Füge Zeile hinzu | ||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||
| 415 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||
| 417 | $tab->push(\@arr); | ||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||
| 419 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||
| 421 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||
| 423 | =item @arr | ||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||
| 425 | Liste von Zeilendaten (Strings). | ||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||
| 427 | =back | ||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||
| 429 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||
| 431 | Füge eine Zeile mit den Kolumnenwerten @arr zur Tabelle hinzu. Die Anzahl der | ||||||||||||||||||||||||||||||||||||||
| 432 | Elemente in @arr muss mit der Anzahl der Kolumnen übereinstimmen, | ||||||||||||||||||||||||||||||||||||||
| 433 | sonst wird eine Exception geworfen. Durch das Hinzufügen einer Zeile | ||||||||||||||||||||||||||||||||||||||
| 434 | werden die gecachten Kolumneneigenschaften - sofern vorhanden - | ||||||||||||||||||||||||||||||||||||||
| 435 | gelöscht (siehe Methode L<properties|"properties() - Eigenschaften einer Kolumne">()). | ||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||
| 437 | =cut | ||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||
| 439 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||
| 441 | 13 | ▶ | sub push { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
push: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 442 | 13 | my ($self,$valueA) = @_; | |||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||
| 444 | 13 | my $row = Quiq::TableRow->new($self,$valueA); | |||||||||||||||||||||||||||||||||||||
| 445 | 12 | $self->SUPER::push('rowA',$row); | |||||||||||||||||||||||||||||||||||||
| 446 | 12 | $self->{'propertyA'} = undef; # Kolumneneigenschaften löschen | |||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||
| 448 | 12 | return; | |||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||
| 451 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||
| 453 | =head3 rows() - Liste der Zeilen | ||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||
| 455 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||
| 457 | @rows | $rowA = $tab->rows; | ||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||
| 459 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||
| 461 | Liste der Zeilen (Objekte der Klasse Quiq::TableRow). Im Skalarkontext | ||||||||||||||||||||||||||||||||||||||
| 462 | eine Referenz auf die Liste. | ||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||
| 464 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||
| 466 | Liefere die Liste der Zeilen der Tabelle. | ||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||
| 468 | =cut | ||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||
| 470 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||
| 472 | 10 | ▶ | sub rows { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
rows: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 473 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||
| 475 | 10 | my $rowA = $self->{'rowA'}; | |||||||||||||||||||||||||||||||||||||
| 476 | 10 | ▶ | return wantarray? @$rowA: $rowA; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||
| 479 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||
| 481 | =head3 row() - Liefere Zeile | ||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||
| 483 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||
| 485 | $row = $tab->row($i); | ||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||
| 487 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||
| 489 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||
| 491 | =item $i | ||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||
| 493 | Index der Zeile (0 .. $tab->count-1) | ||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||
| 495 | =back | ||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||
| 497 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||
| 499 | (Object) Zeile | ||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||
| 501 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||
| 503 | Liefere Zeile mit Index $i. | ||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||
| 505 | =cut | ||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||
| 507 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | sub row { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
row: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 510 | 0 | my ($self,$i) = @_; | |||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | if ($i < 0 || $i > $self->count-1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i < 0 or $i > $self->count - 1
MC/DC0%0/2
$i < 0 or $i > $self->count - 1
$i < 0
$i > $self->count - 1
Truth table0%0/3
A or B
A= $i < 0B= $i > $self->count - 1
| |||||||||||||||||||||||||||||||||||||||
| 513 | 0 | $self->throw( | |||||||||||||||||||||||||||||||||||||
| 514 | 'TABLE-00099: Row does not exist, index out of range', | ||||||||||||||||||||||||||||||||||||||
| 515 | Index => $i, | ||||||||||||||||||||||||||||||||||||||
| 516 | Range => '0 .. '.($self->count-1), | ||||||||||||||||||||||||||||||||||||||
| 517 | ); | ||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||
| 520 | 0 | return $self->rows->[$i]; | |||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||
| 523 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||
| 525 | =head3 values() - Werte einer Kolumne | ||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||
| 527 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||
| 529 | @values | $valueA = $tab->values($pos,@opt); | ||||||||||||||||||||||||||||||||||||||
| 530 | @values | $valueA = $tab->values($column,@opt); | ||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||
| 532 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||
| 534 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||
| 536 | =item $column | ||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||
| 538 | Kolumnenname (String). | ||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||
| 540 | =back | ||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||
| 542 | =head4 Options | ||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||
| 544 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||
| 546 | =item -distinct => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||
| 548 | Liste der I<verschiedenen> Werte. | ||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||
| 550 | =back | ||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||
| 552 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||
| 554 | Liste der Werte (Strings). Im Skalarkontext eine Referenz auf die Liste. | ||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||
| 556 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||
| 558 | Liefere die Liste der Werte der Kolumne $column. Per Default wird die | ||||||||||||||||||||||||||||||||||||||
| 559 | Liste I<aller> Werte geliefert, auch wenn sie mehrfach vorkommen. Siehe | ||||||||||||||||||||||||||||||||||||||
| 560 | auch Option C<-distinct>. | ||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||
| 562 | =cut | ||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||
| 564 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||
| 566 | 14 | ▶ | sub values { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
values: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 567 | 14 | my ($self,$arg) = splice @_,0,2; | |||||||||||||||||||||||||||||||||||||
| 568 | # @_: @opt | ||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||
| 570 | # Optionen | ||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||
| 572 | 14 | my $distinct = 0; | |||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||
| 574 | 14 | $self->parameters(\@_, | |||||||||||||||||||||||||||||||||||||
| 575 | -distinct => \$distinct, | ||||||||||||||||||||||||||||||||||||||
| 576 | ); | ||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||
| 578 | # Operation ausführen | ||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||
| 580 | 14 | my (@arr,%seen); | |||||||||||||||||||||||||||||||||||||
| 581 | 14 | my $pos = $self->pos($arg); | |||||||||||||||||||||||||||||||||||||
| 582 | 14 | for my $row (@{$self->{'rowA'}}) { | |||||||||||||||||||||||||||||||||||||
| 583 | 42 | my $val = $row->[1][$pos]; | |||||||||||||||||||||||||||||||||||||
| 584 | 42 | ▶ | if ($distinct && $seen{$val//''}++) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$distinct and $seen{$val // ""}++
$val // ""
MC/DC100%2/2
$distinct and $seen{$val // ""}++
$distinct
$seen{$val // ""}++
MC/DC0%0/1
$val // ""
$val
Truth table100%3/3
A and B
A= $distinctB= $seen{$val // ""}++
Truth table50%1/2
A
A= $val
| |||||||||||||||||||||||||||||||||||||||
| 585 | 1 | next; | |||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||
| 587 | 41 | CORE::push @arr,$val; | |||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||
| 590 | 14 | ▶ | return wantarray? @arr: \@arr; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||
| 593 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||
| 595 | =head3 width() - Anzahl der Kolumnen | ||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||
| 597 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||
| 599 | $width = $tab->width; | ||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||
| 601 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||
| 603 | Integer | ||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||
| 605 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||
| 607 | Liefere die Anzahl der Kolumnen der Tabelle. | ||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||
| 609 | =cut | ||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||
| 611 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||
| 613 | 5 | ▶ | sub width { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
width: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 614 | 5 | return shift->{'width'}; | |||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||
| 617 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||
| 619 | =head2 Formatierung | ||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||
| 621 | =head3 asAsciiTable() - Tabelle als Ascii-Table | ||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||
| 623 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||
| 625 | $text = $tab->asAsciiTable; | ||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||
| 627 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||
| 629 | Ascii-Table (String) | ||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||
| 631 | =head4 Description | ||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||
| 633 | Liefere die Tabelle in der Repräsentation der Klasse Quiq::AsciiTable. | ||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||
| 635 | =head4 Example | ||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||
| 637 | $tab = Quiq::Table->new(['Integer','String','Float'],[ | ||||||||||||||||||||||||||||||||||||||
| 638 | [1, 'A', 76.253], | ||||||||||||||||||||||||||||||||||||||
| 639 | [12, 'AB', 1.7 ], | ||||||||||||||||||||||||||||||||||||||
| 640 | [123,'ABC',9999 ], | ||||||||||||||||||||||||||||||||||||||
| 641 | ]); | ||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||
| 643 | $str = $tab->asAsciiTable; | ||||||||||||||||||||||||||||||||||||||
| 644 | ==> | ||||||||||||||||||||||||||||||||||||||
| 645 | %Table: | ||||||||||||||||||||||||||||||||||||||
| 646 | Integer String Float | ||||||||||||||||||||||||||||||||||||||
| 647 | ------- ------ -------- | ||||||||||||||||||||||||||||||||||||||
| 648 | 1 A 76.253 | ||||||||||||||||||||||||||||||||||||||
| 649 | 12 AB 1.700 | ||||||||||||||||||||||||||||||||||||||
| 650 | 123 ABC 9999.000 | ||||||||||||||||||||||||||||||||||||||
| 651 | . | ||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||
| 653 | =cut | ||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||
| 655 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||
| 657 | 1 | ▶ | sub asAsciiTable { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
asAsciiTable: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 658 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||
| 660 | 1 | my @columns = $self->columns(-sloppy=>1); | |||||||||||||||||||||||||||||||||||||
| 661 | 1 | my $withTitles = scalar @columns; | |||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||
| 663 | 1 | my @properties = map {$self->properties($_,-withTitles=>$withTitles)} | |||||||||||||||||||||||||||||||||||||
| 664 | 0 .. $self->width-1; | ||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||
| 666 | 1 | my $str = ''; | |||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||
| 668 | 1 | my @arr; | |||||||||||||||||||||||||||||||||||||
| 669 | 1 | ▶ | if ($withTitles) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 670 | 1 | ▶ | for (my $i = 0; $i < @properties; $i++) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 671 | 3 | my $prp = $properties[$i]; | |||||||||||||||||||||||||||||||||||||
| 672 | 3 | ▶ | CORE::push @arr,sprintf '%*s', | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 673 | ($prp->align eq 'r'? '': '-').$prp->width,$columns[$i]; | ||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||
| 675 | 1 | $str .= join(' ',@arr)."\n"; | |||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||
| 678 | 1 | @arr = (); | |||||||||||||||||||||||||||||||||||||
| 679 | 1 | ▶ | for (my $i = 0; $i < @properties; $i++) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 680 | 3 | CORE::push @arr,'-' x $properties[$i]->width; | |||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||
| 682 | 1 | $str .= join(' ',@arr)."\n"; | |||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||
| 684 | 1 | for my $row ($self->rows) { | |||||||||||||||||||||||||||||||||||||
| 685 | 3 | my @row; | |||||||||||||||||||||||||||||||||||||
| 686 | 3 | my $valueA = $row->values; | |||||||||||||||||||||||||||||||||||||
| 687 | 3 | ▶ | for (my $i = 0; $i < @$valueA; $i++) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 688 | 9 | my $val = sprintf $properties[$i]->format('text',$valueA->[$i]); | |||||||||||||||||||||||||||||||||||||
| 689 | 9 | CORE::push @row,$val; | |||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||
| 691 | 3 | $str .= join(' ',@row)."\n"; | |||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||
| 694 | 1 | return $str; | |||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||
| 697 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||
| 699 | =head3 asText() - Tabelle als Text | ||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||
| 701 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||
| 703 | $text = $tab->asText(@opt); | ||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||
| 705 | =head4 Options | ||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||
| 707 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||
| 709 | =item -colorize => $sub | ||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||
| 711 | Callback-Funktion, die für jede Zelle gerufen wird und eine Terminal-Farbe | ||||||||||||||||||||||||||||||||||||||
| 712 | für die jeweilige Zelle liefert. Die Funktion hat die Struktur: | ||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||
| 714 | sub { | ||||||||||||||||||||||||||||||||||||||
| 715 | my ($tab,$row,$pos,$val) = @_; | ||||||||||||||||||||||||||||||||||||||
| 716 | ... | ||||||||||||||||||||||||||||||||||||||
| 717 | return $color; | ||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||
| 720 | Die Terminal-Farbe ist eine Zeichenkette, wie sie Quiq::AnsiColor | ||||||||||||||||||||||||||||||||||||||
| 721 | erwartet. Anwendungsbeispiel siehe quiq-ls. | ||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||
| 723 | =back | ||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||
| 725 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||
| 727 | Text-Tabelle (String) | ||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||
| 729 | =head4 Example | ||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||
| 731 | $tab = Quiq::Table->new(3,[ | ||||||||||||||||||||||||||||||||||||||
| 732 | [1, 'A', 76.253], | ||||||||||||||||||||||||||||||||||||||
| 733 | [12, 'AB', 1.7 ], | ||||||||||||||||||||||||||||||||||||||
| 734 | [123,'ABC',9999 ], | ||||||||||||||||||||||||||||||||||||||
| 735 | ]); | ||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||
| 737 | $str = $tab->asText; | ||||||||||||||||||||||||||||||||||||||
| 738 | ==> | ||||||||||||||||||||||||||||||||||||||
| 739 | | 1 | A | 76.253 | | ||||||||||||||||||||||||||||||||||||||
| 740 | | 12 | AB | 1.700 | | ||||||||||||||||||||||||||||||||||||||
| 741 | | 123 | ABC | 9999.000 | | ||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||
| 743 | =cut | ||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||
| 745 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||
| 747 | 2 | ▶ | sub asText { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
asText: called CC=5 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 748 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||
| 750 | # Optionen | ||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||
| 752 | 2 | my $colorizeS = undef; | |||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||
| 754 | 2 | $self->parameters(\@_, | |||||||||||||||||||||||||||||||||||||
| 755 | -colorize => \$colorizeS, | ||||||||||||||||||||||||||||||||||||||
| 756 | ); | ||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||
| 758 | # Kolumneneigenschaften | ||||||||||||||||||||||||||||||||||||||
| 759 | 2 | my @properties = map {$self->properties($_)} 0 .. $self->width-1; | |||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||
| 761 | # Terminal-Farben | ||||||||||||||||||||||||||||||||||||||
| 762 | 2 | my $a = Quiq::AnsiColor->new; | |||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||
| 764 | # Erzeuge Tabellenzeile | ||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||
| 766 | 2 | my $str = ''; | |||||||||||||||||||||||||||||||||||||
| 767 | 2 | for my $row ($self->rows) { | |||||||||||||||||||||||||||||||||||||
| 768 | 6 | my @row; | |||||||||||||||||||||||||||||||||||||
| 769 | 6 | my $valueA = $row->values; | |||||||||||||||||||||||||||||||||||||
| 770 | 6 | ▶ | for (my $i = 0; $i < @$valueA; $i++) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 771 | 18 | my $val = sprintf $properties[$i]->format('text',$valueA->[$i]); | |||||||||||||||||||||||||||||||||||||
| 772 | 18 | ▶ | if ($colorizeS) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 773 | 0 | ▶ | if (my $color = $colorizeS->($self,$row,$i,$val)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 774 | 0 | $val = $a->str($color,$val); | |||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||
| 777 | 18 | CORE::push @row,$val; | |||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||
| 779 | 6 | $str .= '| '.join(' | ',@row)." |\n"; | |||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||
| 782 | 2 | return $str; | |||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||
| 785 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||
| 787 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||
| 789 | 1.240 | ||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||
| 791 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||
| 793 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||
| 795 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||
| 797 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||
| 799 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||
| 801 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||
| 802 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||
| 804 | =cut | ||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||
| 806 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||
| 808 | 2 | 1; | |||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||
| 810 | # eof | ||||||||||||||||||||||||||||||||||||||