Quiq/ImagePool.pm

filter: Statementstmt 37.8% 25 / 66 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 61.5% 8 / 13 Podpod 100% 5 / 5 totaltotal 35.1% 38 / 108 CC 10 SCAR 26.8
CC
10
Cov
29%
images
42.0
directory
12.0
root
6.0
CRAP 14.6
« Quiq/ModelCache.pm ↑ Summary Quiq/ExampleCode.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::ImagePool - Speicher für Bild-Dateien
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =cut
14  
15 # -----------------------------------------------------------------------------
16  
17 package Quiq::ImagePool;
18 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 our $VERSION = '1.240';
25  
26 1 ▶use Quiq::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Quiq::ImagePool::Directory;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Quiq::Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use Quiq::FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 # -----------------------------------------------------------------------------
32  
33 =head1 METHODS
34  
35 =head2 Konstruktor
36  
37 =head3 new() - Instantiiere Pool-Objekt
38  
39 =head4 Synopsis
40  
41 $ipl = $class->new($path);
42  
43 =head4 Arguments
44  
45 =over 4
46  
47 =item $path
48  
49 Pfad zum Pool-Verzeichnises.
50  
51 =back
52  
53 =cut
54  
55 # -----------------------------------------------------------------------------
56  
57 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
58 0 my ($class,$path) = @_;
59  
60 # Objekt instantiieren
61  
62 0 return $class->SUPER::new(
63 root => $path,
64 directoryH => {},
65 );
66 }
67  
68 # -----------------------------------------------------------------------------
69  
70 =head2 Eigenschaften
71  
72 =head3 root() - Wurzelverzeichnis des Image-Pool
73  
74 =head4 Synopsis
75  
76 $path = $ipl->root;
77 $path = $ipl->root($subPath);
78  
79 =head4 Description
80  
81 Liefere den Pfad des Wurzelverzeichnissess des Image-Pool. Ist
82 Argument $subPath angegeben, füge diesen Pfad zum Wurzelverzeichnis
83 hinzu.
84  
85 =head4 Example
86  
87 Mit Subpfad:
88  
89 $ipl->root('cache');
90 =>
91 <POOLDIR>/cache
92  
93 =cut
94  
95 # -----------------------------------------------------------------------------
96  
97 0 ▶sub root {
Subroutine root: not called CC=2 SCAR=17.9
Pod documented
98 0 my $self = shift;
99 # @_: $subPath
100  
101 0 my $path = $self->{'root'};
102 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
103 0 $path .= '/'.shift;
104 }
105  
106 0 return $path;
107 }
108  
109 # -----------------------------------------------------------------------------
110  
111 =head2 Verzeichnisse
112  
113 =head3 directory() - Lookup Directory-Objekt nach Name
114  
115 =head4 Synopsis
116  
117 $dir = $ipl->directory($name);
118  
119 =head4 Arguments
120  
121 =over 4
122  
123 =item $name
124  
125 Name des Bild-Verzeichnisses
126  
127 =back
128  
129 =head4 Description
130  
131 Liefere das Bild-Verzeichnis-Objekt mit Name $name. Das Objekt
132 wird gecached. Existiert das Verzeichnis nicht, wird eine
133 Exception geworfen.
134  
135 =cut
136  
137 # -----------------------------------------------------------------------------
138  
139 0 ▶sub directory {
Subroutine directory: not called CC=3 SCAR=24.8
Pod documented
140 0 my ($self,$name) = @_;
141  
142 # Directory-Namen auf den Anfang 'YYYY-MM-DD-X' reduzieren
143  
144 0 ($name) = $name =~ /^(\d{4}-\d{2}-\d{2}-[A-Z])/;
145 0 ▶ if (!$name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 0 0 0
146 0 $self->throw;
147 }
148  
149 0 ▶ return $self->{'directoryH'}->{$name} //= do {
Condition0%0/3
$self->{"directoryH"}{$name} //= do { my $pattern = sprintf("%s/dir/%s*", $self->root, $name); my $path = "Quiq::Path"->glob($pattern); "Quiq::ImagePool::Directory"->new($path) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"directoryH"}{$name} //= do { my $pattern = sprintf("%s/dir/%s*", $self->root, $name); my $path = "Quiq::Path"->glob($pattern); "Quiq::ImagePool::Directory"->new($path) }
$self->{"directoryH"}{$name} do { my $pattern = sprintf("%s/dir/%s*", $self->root, $name); my $path = "Quiq::Path"->glob($pattern); "Quiq::ImagePool::Directory"->new($path) }
Truth table0%0/3
A //= B
A= $self->{"directoryH"}{$name}B= do { my $pattern = sprintf("%s/dir/%s*", $self->root, $name); my $path = "Quiq::Path"->glob($pattern); "Quiq::ImagePool::Directory"->new($path) }
ABresult
1X1
011
000
150 0 my $pattern = sprintf '%s/dir/%s*',$self->root,$name;
151 0 my $path = Quiq::Path->glob($pattern);
152 0 Quiq::ImagePool::Directory->new($path);
153 };
154 }
155  
156 # -----------------------------------------------------------------------------
157  
158 =head2 Cache
159  
160 =head3 cacheFile() - Generiere Pfad einer Cache-Datei
161  
162 =head4 Synopsis
163  
164 $path = $ipl->cacheFile($img,$op,@args);
165  
166 =head4 Arguments
167  
168 =over 4
169  
170 =item $op
171  
172 Bezeichner für die angewendete Bild-Operation.
173  
174 =item @args
175  
176 Argumente für die Bild-Operation.
177  
178 =back
179  
180 =head4 Description
181  
182 Generiere einen Cache-Pfad für Bild $img und Bild-Operation $op
183 mit den Argumenten @args und liefere diesen zurück.
184  
185 =cut
186  
187 # -----------------------------------------------------------------------------
188  
189 0 ▶sub cacheFile {
Subroutine cacheFile: not called CC=2 SCAR=17.9
Pod documented
190 0 my $self = shift;
191 0 my $img = shift;
192 # @_: @args
193  
194 0 my $cacheId;
195 0 my $basename = $img->basename;
196 0 my @path = split m|/|,$self->path;
197 0 ▶ if ($path[-2] eq 'img') {
Branch: 1 branch
BranchTrueFalseTotal
if ($path[-2] eq 'img') { } 0 0 0
198 0 $cacheId = "$path[-3]/$basename"; # Subdirectoy-Path
199 }
200 else {
201 0 $cacheId = "$path[-2]/$basename"; # Cache-Path
202 }
203
204 0 my $file = $self->root('cache/img');
205 0 $file .= sprintf '/%s,%s.%s',$cacheId,join('-',@_),$img->type;
206  
207 0 return $file;
208 }
209  
210 # -----------------------------------------------------------------------------
211  
212 =head2 Bilder
213  
214 =head3 images() - Bilder gemäß Suchkriterium
215  
216 =head4 Synopsis
217  
218 @images|$imageA = $ipl->images($key,@opt);
219  
220 =head4 Arguments
221  
222 =over 4
223  
224 =item $key
225  
226 Bezeichner Bild-Sequenz.
227  
228 =back
229  
230 =head4 Options
231  
232 =over 4
233  
234 =item -count => $n (Default: 0 = keine Beschränkung)
235  
236 Liefere maximal $n Bilder.
237  
238 =back
239  
240 =cut
241  
242 # -----------------------------------------------------------------------------
243  
244 0 ▶sub images {
Subroutine images: not called CC=6 SCAR=37.4
Pod documented
245 0 my ($self,$key) = @_;
246  
247 # Optionen
248  
249 0 my $count = 0;
250  
251 0 Quiq::Option->extract(\@_,
252 -count => \$count,
253 );
254  
255 0 my @images;
256  
257 0 ▶ if ($key =~ s|^(\d{4}-\d{2}-\d{2}-[A-Z])[^/]*/?||s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ s[^(\d{4}-\d{2}-\d{2}-[A-Z])[^/]*/?][]s) { } 0 0 0
258 # Bilder aus Verzeichnis
259 0 @images = $self->directory($1)->images($key);
260 }
261 else {
262 # Bilder gemäß Pool-Sequenz-Datei
263  
264 0 my $file = sprintf '%s/seq/%s.def',$self->root,$key;
265 0 my $fh = Quiq::FileHandle->new('<',$file);
266 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
267 0 chomp;
268 0 push @images,$self->images($_);
269 }
270 0 $fh->close;
271 }
272  
273 0 ▶ if ($count && $count < @images) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count and $count < @images) 0 0 0
Condition0%0/3
$count and $count < @images
!ll&&!rl&&r
000
MC/DC0%0/2
$count and $count < @images
$count $count < @images
Truth table0%0/3
A and B
A= $countB= $count < @images
ABresult
0X0
100
111
274 0 $#images = $count-1;
275 }
276  
277 0 ▶ return wantarray? @images: \@images;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
278 }
279  
280 # -----------------------------------------------------------------------------
281  
282 =head1 VERSION
283  
284 1.240
285  
286 =head1 AUTHOR
287  
288 Frank Seitz, L<http://fseitz.de/>
289  
290 =head1 COPYRIGHT
291  
292 Copyright (C) 2026 Frank Seitz
293  
294 =head1 LICENSE
295  
296 This code is free software; you can redistribute it and/or modify
297 it under the same terms as Perl itself.
298  
299 =cut
300  
301 # -----------------------------------------------------------------------------
302  
303 1 1;
304  
305 # eof
« Quiq/ModelCache.pm ↑ Summary Quiq/ExampleCode.pm »