Quiq/ImagePool/Sequence.pm

filter: Statementstmt 27.8% 22 / 79 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 43.7% 7 / 16 Podpod 100% 9 / 9 totaltotal 25.3% 38 / 150 CC 24 SCAR 38.3
CC
24
Cov
18%
specImages
132.0
new
30.0
images
20.0
CRAP 45.9
« Quiq/Confluence/Markup.pm ↑ Summary Quiq/Path.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::ImagePool::Sequence - Bild-Sequenz und -Ranges
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 ATTRIBUTES
14  
15 =over 4
16  
17 =item file
18  
19 Pfad der Datei.
20  
21 =item oHash
22  
23 Geordneter Hash der Schlüssel/Definitions-Paare.
24  
25 =item imageList
26  
27 Liste aller Bilder.
28  
29 =back
30  
31 =cut
32  
33 # -----------------------------------------------------------------------------
34  
35 package Quiq::ImagePool::Sequence;
36 3 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 3 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 3 our $VERSION = '1.240';
44  
45 3 ▶use Quiq::Hash::Ordered;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 3 ▶use Quiq::FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 # -----------------------------------------------------------------------------
49  
50 =head1 METHODS
51  
52 =head2 Konstruktor
53  
54 =head3 new() - Instantiiere Objekt aus Datei
55  
56 =head4 Synopsis
57  
58 $ims = $class->new($file,$lst);
59  
60 =head4 Arguments
61  
62 =over 4
63  
64 =item $file
65  
66 Pfad der Sequenz-Liste.
67  
68 =item $lst
69  
70 Liste aller Bilder.
71  
72 =back
73  
74 =head4 Description
75  
76 Instantiiere ein Sequenz-Objekt aus Datei $file, verknüpfe es mit
77 Bildliste $lst und liefere eine Referenz auf dieses Objekt zurück.
78  
79 =cut
80  
81 # -----------------------------------------------------------------------------
82  
83 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
84 0 my ($class,$file,$lst) = @_;
85  
86 # Leeres Objekt instantiieren
87  
88 0 my $oh = Quiq::Hash::Ordered->new;
89 0 my $self = $class->SUPER::new(
90 file => $file,
91 oHash => $oh,
92 imageList => $lst,
93 );
94  
95 # Sequenz-Definitionen einlesen.
96  
97 0 my $fh = Quiq::FileHandle->new('<',$file);
98 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
99 0 chomp;
100  
101 0 ▶ if (/^\s*#/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*#/) 0 0 0
102 # Kommentarzeile
103 0 next;
104 }
105  
106 # Sequenz-Definitionszeile hinzufügen
107  
108 0 my @arr = split /\s+/,$_;
109 0 ▶ if (@arr < 2 || @arr > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arr < 2 or @arr > 3) 0 0 0
Condition0%0/3
@arr < 2 or @arr > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@arr < 2 or @arr > 3
@arr < 2 @arr > 3
Truth table0%0/3
A or B
A= @arr < 2B= @arr > 3
ABresult
1X1
011
000
110 # Prüfe Dateiaufbau
111 0 $self->throw(
112 'SEQ-00001: Falsche Kolumnen-Anzahl',
113 File => $file,
114 Line => $.,
115 MaxColumns => 3,
116 Columns => scalar(@arr),
117 );
118 }
119 0 my $key = shift @arr;
120 0 $oh->set($key=>\@arr);
121 }
122 0 $fh->close;
123  
124 0 return $self;
125 }
126  
127 # -----------------------------------------------------------------------------
128  
129 =head2 Objektmethoden
130  
131 =head3 count() - Anzahl der Range-Definitionen
132  
133 =head4 Synopsis
134  
135 $n = $ims->count;
136  
137 =head4 Description
138  
139 Liefere die Anzahl der Range-Definitionen.
140  
141 =cut
142  
143 # -----------------------------------------------------------------------------
144  
145 0 ▶sub count {
Subroutine count: not called CC=1 SCAR=6.9
Pod documented
146 0 return shift->oHash->hashSize;
147 }
148  
149 # -----------------------------------------------------------------------------
150  
151 =head3 keys() - Array der Range-Namen
152  
153 =head4 Synopsis
154  
155 @keys|$keyA = $ims->keys;
156  
157 =head4 Description
158  
159 Liefere die Liste aller Range-Bezeichner. Im Skalarkontext liefere
160 eine Referenz auf die Liste.
161  
162 =cut
163  
164 # -----------------------------------------------------------------------------
165  
166 0 ▶sub keys {
Subroutine keys: not called CC=1 SCAR=6.9
Pod documented
167 0 return shift->oHash->keys;
168 }
169  
170 # -----------------------------------------------------------------------------
171  
172 =head3 exists() - Prüfe, ob Range existiert
173  
174 =head4 Synopsis
175  
176 $bool = $ims->exists($key);
177  
178 =head4 Description
179  
180 Prüfe, ob Range $key existiert. Wenn ja, liefere 1, sonst 0.
181  
182 =cut
183  
184 # -----------------------------------------------------------------------------
185  
186 0 ▶sub exists {
Subroutine exists: not called CC=2 SCAR=17.9
Pod documented
187 0 my ($self,$key) = @_;
188 0 ▶ return $self->oHash->get($key)? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->oHash->get($key) ? : 0 0 0
189 }
190  
191 # -----------------------------------------------------------------------------
192  
193 =head3 def() - Liefere Range-Definition
194  
195 =head4 Synopsis
196  
197 @def|$defA = $ims->def($key);
198  
199 =head4 Description
200  
201 Liefere die Definition ($spec,$modifier) des Range $key.
202  
203 =cut
204  
205 # -----------------------------------------------------------------------------
206  
207 0 ▶sub def {
Subroutine def: not called CC=3 SCAR=24.8
Pod documented
208 0 my ($self,$key) = @_;
209 0 ▶ my $arr = $self->oHash->get($key) || do {
Condition0%0/3
$self->oHash->get($key) || do { $self->throw("IMGSET-00002: Schl\374ssel existiert nicht", 'File', $self->file, 'Key', $key) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->oHash->get($key) || do { $self->throw("IMGSET-00002: Schl\374ssel existiert nicht", 'File', $self->file, 'Key', $key) }
$self->oHash->get($key) do { $self->throw("IMGSET-00002: Schl\374ssel existiert nicht", 'File', $self->file, 'Key', $key) }
Truth table0%0/3
A || B
A= $self->oHash->get($key)B= do { $self->throw("IMGSET-00002: Schl\374ssel existiert nicht", 'File', $self->file, 'Key', $key) }
ABresult
1X1
011
000
210 0 $self->throw(
211 'IMGSET-00002: Schlüssel existiert nicht',
212 File => $self->file,
213 Key => $key,
214 );
215 };
216 0 ▶ return wantarray? @$arr: $arr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
217 }
218  
219 # -----------------------------------------------------------------------------
220  
221 =head3 spec() - Liefere Range-Spezifikation
222  
223 =head4 Synopsis
224  
225 $range = $ims->spec($key);
226  
227 =head4 Description
228  
229 Liefere die Spezifikation (Aufzählung der Bildnummern) für Range $key.
230  
231 =cut
232  
233 # -----------------------------------------------------------------------------
234  
235 0 ▶sub spec {
Subroutine spec: not called CC=2 SCAR=17.9
Pod documented
236 0 my ($self,$key) = @_;
237 0 ▶ return $self->def($key)->[0] // '';
Condition0%0/2
$self->def($key)->[0] // ""
l!l
00
MC/DC0%0/1
$self->def($key)->[0] // ""
$self->def($key)->[0]
Truth table0%0/2
A
A= $self->def($key)->[0]
Aresult
11
00
238 }
239  
240 # -----------------------------------------------------------------------------
241  
242 =head3 specImages() - Liefere die Bilder eines Range
243  
244 =head4 Synopsis
245  
246 @images|$imageA = $ims->specImages($key);
247  
248 =head4 Arguments
249  
250 =over 4
251  
252 =item $key
253  
254 Range-Bezeichner.
255  
256 =back
257  
258 =head4 Description
259  
260 Liefere die Liste der Bilder des Range $key. Im Skalarkontext liefere
261 eine Referenz auf die Liste.
262  
263 =cut
264  
265 # -----------------------------------------------------------------------------
266  
267 0 ▶sub specImages {
Subroutine specImages: not called CC=11 SCAR=48.8
Pod documented
268 0 my ($self,$key) = @_;
269  
270 0 my $lst = $self->imageList;
271  
272 0 my @images;
273 0 for (split /,/,$self->spec($key)) {
274 0 push @images,$lst->images($_);
275 }
276  
277 # Bildsequenz modifizieren
278 # Operationen: pick-N, dup-N, reverse, shuffle
279  
280 0 for (split /,/,$self->modifier($key)) {
281 0 my ($cmd,$n) = split /-/;
282 0 ▶ if ($cmd eq 'pick') {
Branch: 4 branches
BranchTrueFalseTotal
if ($cmd eq 'pick') { } 0 0 0
elsif ($cmd eq 'dup') { } 0 0 0
elsif ($cmd eq 'reverse') { } 0 0 0
elsif ($cmd eq 'shuffle') { } 0 0 0
283 0 ▶ for (my $i = 0; $i < @images; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @images) 0 0 0
284 0 splice @images,$i+1,$n-1;
285 }
286 }
287 elsif ($cmd eq 'dup') {
288 0 my @tmp;
289 0 for my $img (@images) {
290 0 push @tmp,($img)x$n;
291 }
292 0 @images = @tmp;
293 }
294 elsif ($cmd eq 'reverse') {
295 0 @images = reverse @images;
296 }
297 elsif ($cmd eq 'shuffle') {
298 0 my @tmp;
299 0 ▶ while (@images) {
Branch: 1 branch
BranchTrueFalseTotal
if (@images) 0 0 0
300 0 push @tmp,splice @images,int(rand(scalar @images)),1;
301 }
302 0 @images = @tmp;
303 }
304 else {
305 0 $self->throw;
306 }
307 }
308  
309 0 ▶ return wantarray? @images: \@images;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
310 }
311  
312 # -----------------------------------------------------------------------------
313  
314 =head3 modifier() - Liefere/Setze Range-Modifier
315  
316 =head4 Synopsis
317  
318 $modifier = $ims->modifier($key);
319 $modifier = $ims->modifier($key=>$modifier);
320  
321 =head4 Description
322  
323 Liefere oder setze den Modifier für Range $key.
324  
325 =cut
326  
327 # -----------------------------------------------------------------------------
328  
329 0 ▶sub modifier {
Subroutine modifier: not called CC=3 SCAR=24.8
Pod documented
330 0 my $self = shift;
331 0 my $key = shift;
332 # @_: $modifier
333  
334 0 my $defA = $self->def($key);
335 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
336 0 $defA->[1] = shift;
337 }
338  
339 0 ▶ return $defA->[1] // '';
Condition0%0/2
$defA->[1] // ""
l!l
00
MC/DC0%0/1
$defA->[1] // ""
$defA->[1]
Truth table0%0/2
A
A= $defA->[1]
Aresult
11
00
340 }
341  
342 # -----------------------------------------------------------------------------
343  
344 =head2 Bilder
345  
346 =head3 images() - Liefere Bilder der Sequenz
347  
348 =head4 Synopsis
349  
350 @images|$imageA = $ims->images;
351 @images|$imageA = $ims->images($key);
352  
353 =head4 Arguments
354  
355 =over 4
356  
357 =item $key
358  
359 Range-Bezeichner.
360  
361 =back
362  
363 =head4 Description
364  
365 Liefere alle Bilder der Sequenz oder die Bilder des Range $key. Ist $key
366 undef oder ein Leerstring (''), werden ebenfalls alle Bilder geliefert.
367  
368 =cut
369  
370 # -----------------------------------------------------------------------------
371  
372 0 ▶sub images {
Subroutine images: not called CC=4 SCAR=30.0
Pod documented
373 0 my ($self,$key) = @_;
374  
375 0 my @images;
376 0 ▶ for my $key ($key? ($key): $self->keys) {
Branch: 1 branch
BranchTrueFalseTotal
$key ? : 0 0 0
377 0 push @images,$self->specImages($key);
378 }
379  
380 0 ▶ return wantarray? @images: \@images;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
381 }
382  
383 # -----------------------------------------------------------------------------
384  
385 =head1 VERSION
386  
387 1.240
388  
389 =head1 AUTHOR
390  
391 Frank Seitz, L<http://fseitz.de/>
392  
393 =head1 COPYRIGHT
394  
395 Copyright (C) 2026 Frank Seitz
396  
397 =head1 LICENSE
398  
399 This code is free software; you can redistribute it and/or modify
400 it under the same terms as Perl itself.
401  
402 =cut
403  
404 # -----------------------------------------------------------------------------
405  
406 3 1;
407  
408 # eof
« Quiq/Confluence/Markup.pm ↑ Summary Quiq/Path.pm »