Quiq/TimeLapse/Filename.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 87.5% 7 / 8 Conditioncond 26.3% 5 / 19 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 72.0% 62 / 86 CC 13 SCAR 24.2
CC
13
Cov
76%
new
19.4
text
2.0
asString
2.0
CRAP 11.3
« Quiq/Cache.pm ↑ Summary Quiq/Config.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::TimeLapse::Filename - Bildsequenz-Dateiname
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 SYNOPSIS
14  
15 # Klasse laden
16 use Quiq::TimeLapse::Filename;
17
18 # Instantiiere Bildsequenz-Dateinamen
19 $nam = Quiq::TimeLapse::Filename->new('/my/image/dir/000219-3000x2250-G0080108.jpg');
20
21 # Nummer
22 $n = $nam->number; # 219
23
24 # Breite
25 $width = $nam->width; # 3000
26
27 # Höhe
28 $height = $nam->height; # 2250
29
30 # Extension
31 $extension = $nam->extension; # 'jpg'
32
33 # Name
34 $name = $nam->name; # 'G0080108'
35  
36 =head1 DESCRIPTION
37  
38 Ein Objekt der Klasse repräsentiert den Namen einer Bildsequenz-Datei.
39 Der Name einer Bildsequenz-Datei hat den Aufbau:
40  
41 NNNNNN-WIDTHxHEIGHT[-NAME].EXT
42  
43 =head1 ATTRIBUTES
44  
45 =over 4
46  
47 =item number
48  
49 Bildnummer
50  
51 =item width
52  
53 Breitenangabe
54  
55 =item heigth
56  
57 Höhenangabe
58  
59 =item text
60  
61 Text-Zusatz
62  
63 =item ext
64  
65 Extension
66  
67 =back
68  
69 =cut
70  
71 # -----------------------------------------------------------------------------
72  
73 package Quiq::TimeLapse::Filename;
74 5 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 5 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
78 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
79  
80 5 our $VERSION = '1.240';
81  
82 5 ▶use Quiq::Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 # -----------------------------------------------------------------------------
85  
86 =head1 METHODS
87  
88 =head2 Konstruktor
89  
90 =head3 new() - Instantiiere Bilddateinamen-Objekt
91  
92 =head4 Synopsis
93  
94 $nam = $class->new($file);
95 $nam = $class->new($n,$width,$height,$ext,@opt);
96  
97 =head4 Arguments
98  
99 =over 4
100  
101 =item $file
102  
103 Pfad der Bilddatei
104  
105 =item $n
106  
107 Bildnummer
108  
109 =item $width
110  
111 Breite des Bildes
112  
113 =item $heigth
114  
115 Höhe des Bildes
116  
117 =item $ext
118  
119 Extension der Bilddatei
120  
121 =back
122  
123 =head4 Options
124  
125 =over 4
126  
127 =item -text => $str
128  
129 Namenszusatz der Datei
130  
131 =back
132  
133 =head4 Returns
134  
135 Referenz auf das Bilddateinamen-Objekt
136  
137 =head4 Description
138  
139 Instantiiere Bilddateinamen-Objekt und liefere eine Referenz auf
140 dieses Objekt zurück.
141  
142 =cut
143  
144 # -----------------------------------------------------------------------------
145  
146 5 ▶sub new {
Subroutine new: called CC=11 SCAR=29.6
Pod documented
147 5 my $class = shift;
148 # @_: $file -or- $n,$width,$height,$ext,@opt
149  
150 5 my ($n,$width,$height,$ext,$text);
151 5 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 3 2 5
152 # Dateiname
153  
154 3 my $file = shift;
155 3 $file =~ s|.*/||; # Verzeichnisanteil entfernen
156  
157 3 ($n,my $size,$text) = split /-/,$file,3;
158 3 $n += 0;
159 3 ▶ if (defined $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text) { } 1 2 3
160 1 ($text,$ext) = $text =~ /^(.*)\.([^.]+)$/;
161 }
162 else {
163 2 ($size,$ext) = $size =~ /^(.*)\.([^.]+)$/;
164 }
165 3 ($width,$height) = split /x/,$size;
166 }
167 else {
168 # Einzelangaben
169  
170 2 Quiq::Option->extract(\@_,
171 -text => \$text,
172 );
173 2 ($n,$width,$height,$ext) = @_;
174 }
175  
176 # Angaben überprüfen
177  
178 5 ▶ if (!$n || !$width || !$height || !$ext) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n and $width and $height and $ext) 0 5 5
Condition33%3/9
$n and $width and $height and $ext
!ll&&!rl&&r
005
$n and $width and $height
!ll&&!rl&&r
005
$n and $width
!ll&&!rl&&r
005
MC/DC0%0/4
$n and $width and $height and $ext
$n $width $height $ext
Truth table20%1/5
A and B and C and D
A= $nB= $widthC= $heightD= $ext
ABCDresult
0XXX0
10XX0
110X0
11100
11111
179
180 0 ▶ $class->throw(
Condition0%0/8
$n // "undef"
l!l
00
$width // "undef"
l!l
00
$height // "undef"
l!l
00
$ext // "undef"
l!l
00
MC/DC0%0/1
$n // "undef"
$n
MC/DC0%0/1
$width // "undef"
$width
MC/DC0%0/1
$height // "undef"
$height
MC/DC0%0/1
$ext // "undef"
$ext
Truth table0%0/2
A
A= $n
Aresult
11
00
Truth table0%0/2
A
A= $width
Aresult
11
00
Truth table0%0/2
A
A= $height
Aresult
11
00
Truth table0%0/2
A
A= $ext
Aresult
11
00
181 'SEQ-00001: Illegal image sequence filename',
182 number => $n // 'undef',
183 width => $width // 'undef',
184 height => $height // 'undef',
185 extension => $ext // 'undef',
186 );
187 }
188
189 5 return $class->SUPER::new(
190 number => $n,
191 width => $width,
192 height => $height,
193 text => $text,
194 extension => $ext,
195 );
196 }
197  
198 # -----------------------------------------------------------------------------
199  
200 =head2 Akzessoren
201  
202 =head3 number() - Nummer der Bilddatei
203  
204 =head4 Synopsis
205  
206 $n = $nam->number;
207  
208 =head4 Returns
209  
210 Integer > 0
211  
212 =head4 Description
213  
214 Liefere die Nummer der Bilddatei.
215  
216 =head3 width() - Breite
217  
218 =head4 Synopsis
219  
220 $width = $nam->width;
221  
222 =head4 Returns
223  
224 Integer > 0
225  
226 =head4 Description
227  
228 Liefere die Breitenangabe aus dem Bilddateinamen.
229  
230 =head3 height() - Höhe
231  
232 =head4 Synopsis
233  
234 $height = $nam->height;
235  
236 =head4 Returns
237  
238 Integer > 0
239  
240 =head4 Description
241  
242 Liefere die Höhenangabe aus dem Bilddateinamen.
243  
244 =head3 text() - Text
245  
246 =head4 Synopsis
247  
248 $str = $nam->text;
249  
250 =head4 Returns
251  
252 String
253  
254 =head4 Description
255  
256 Liefere den (optionalen) Text aus dem Bilddateinamen. Ist kein
257 Text vorhanden, liefere einen Leerstring ('').
258  
259 =cut
260  
261 # -----------------------------------------------------------------------------
262  
263 8 ▶sub text {
Subroutine text: called CC=2 SCAR=6.9
Pod documented
264 8 ▶ shift->{'text'} // '';
Condition100%2/2
+(shift())->{"text"} // ""
l!l
44
MC/DC100%1/1
+(shift())->{"text"} // ""
+(shift())->{"text"}
Truth table100%2/2
A
A= +(shift())->{"text"}
Aresult
11
00
265 }
266  
267 # -----------------------------------------------------------------------------
268  
269 =head3 extension() - Extension
270  
271 =head4 Synopsis
272  
273 $extension = $nam->extension;
274  
275 =head4 Returns
276  
277 String
278  
279 =head4 Description
280  
281 Liefere die Extension des Bilddateinamens.
282  
283 =head2 Objektmethoden
284  
285 =head3 asString() - Liefere den Dateinamen
286  
287 =head4 Synopsis
288  
289 $filename = $nam->asString;
290  
291 =head4 Returns
292  
293 Bild-Dateiname (String)
294  
295 =head4 Description
296  
297 Bilde aus den Angaben Bildnummer (number), Bildbreite (width),
298 Bildhöhe (height), dem optionalen Beschreibungstext (text) und der
299 Deteiendung (extension) einen Bild-Dateinamen und liefere diesen
300 zurück.
301  
302 =cut
303  
304 # -----------------------------------------------------------------------------
305  
306 4 ▶sub asString {
Subroutine asString: called CC=2 SCAR=6.9
Pod documented
307 4 my $self = shift;
308
309 4 my $filename = sprintf '%06d-%sx%s',$self->number,
310 $self->width,$self->height;
311 4 ▶ if (my $text = $self->text) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $text = $self->text) 2 2 4
312 2 $filename .= "-$text";
313 }
314 4 $filename .= '.'.$self->extension;
315  
316 4 return $filename;
317 }
318  
319 # -----------------------------------------------------------------------------
320  
321 =head1 VERSION
322  
323 1.240
324  
325 =head1 AUTHOR
326  
327 Frank Seitz, L<http://fseitz.de/>
328  
329 =head1 COPYRIGHT
330  
331 Copyright (C) 2026 Frank Seitz
332  
333 =head1 LICENSE
334  
335 This code is free software; you can redistribute it and/or modify
336 it under the same terms as Perl itself.
337  
338 =cut
339  
340 # -----------------------------------------------------------------------------
341  
342 5 1;
343  
344 # eof
« Quiq/Cache.pm ↑ Summary Quiq/Config.pm »