Quiq/TempFile.pm

filter: Statementstmt 91.3% 42 / 46 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 89.8% 62 / 69 CC 7 SCAR 13.5
CC
7
Cov
88%
new
7.5
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
« Quiq/Html/Resources.pm ↑ Summary Quiq/ContentProcessor/Type.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::TempFile - Temporäre Datei
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Object>
12  
13 =head1 DESCRIPTION
14  
15 Der Konstruktor der Klasse erzeugt eine temporäre Datei.
16 Geht die letzte Objekt-Referenz aus dem Scope, wird die Datei
17 automatisch gelöscht. Das Datei-Objekt stringifiziert sich
18 im String-Kontext automatisch zum Datei-Pfad.
19  
20 =cut
21  
22 # -----------------------------------------------------------------------------
23  
24 package Quiq::TempFile;
25 270 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 270 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 270 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 270 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 270 our $VERSION = '1.240';
32  
33 270 ▶use overload '""' => sub {${$_[0]}}, 'cmp' => sub{${$_[0]} cmp $_[1]};
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
34 270 ▶use Quiq::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 270 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 # -----------------------------------------------------------------------------
38  
39 =head1 METHODS
40  
41 =head2 Konstruktor
42  
43 =head3 new() - Instantiiere Objekt
44  
45 =head4 Synopsis
46  
47 $file = $class->new(@opt);
48 $file = $class->new($data,@opt);
49  
50 =head4 Arguments
51  
52 =over 4
53  
54 =item $data
55  
56 Daten, die in die temporäre Datei geschrieben werden.
57  
58 =back
59  
60 =head4 Options
61  
62 =over 4
63  
64 =item -dir => $dir (Default: '/tmp')
65  
66 Verzeichnis, in dem die temporäre Datei erzeugt wird.
67  
68 =item -pathOnly => $bool
69  
70 Erzeuge nur den Pfad, lösche die Datei sofort.
71  
72 =item -suffix => $suffix
73  
74 Dateienendung, z.B. '.dat'.
75  
76 =item -template => $template
77  
78 Dateinamen-Template, z.B. 'tmpfileXXXXX'.
79  
80 =item -unlink => $bool (Default: 1)
81  
82 Lösche die Datei, wenn das Objekt aus dem Scope geht.
83  
84 =back
85  
86 =head4 Returns
87  
88 Tempdatei-Objekt
89  
90 =head4 Description
91  
92 Instantiiere ein Objekt der Klasse und liefere eine Referenz auf
93 dieses Objekt zurück.
94  
95 =cut
96  
97 # -----------------------------------------------------------------------------
98  
99 12 ▶sub new {
Subroutine new: called CC=7 SCAR=20.2
Pod documented
100 12 my $class = shift;
101 # @_: @opt
102  
103 # Optionen und Argumente
104  
105 12 my ($dir,$pathOnly,$suffix,$template,$unlink);
106  
107 12 my $argA = $class->parameters(0,1,\@_,
108 -dir => \$dir,
109 -pathOnly => \$pathOnly,
110 -suffix => \$suffix,
111 -template => \$template,
112 -unlink => \$unlink,
113 );
114 12 my $data = shift @$argA;
115  
116 # Wir setzen unsere Optionen in die Optionen von File::Temp um
117  
118 12 my @args;
119 12 ▶ if (defined $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir) 0 12 12
120 0 $dir = Quiq::Path->expandTilde($dir);
121 0 push @args,'DIR',$dir;
122 }
123 12 ▶ if (defined $suffix) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $suffix) 1 11 12
124 1 push @args,'SUFFIX',$suffix;
125 }
126 12 ▶ if (defined $template) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $template) 0 12 12
127 0 push @args,'TEMPLATE',$template;
128 }
129 12 ▶ if (defined $unlink) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $unlink) 0 12 12
130 0 push @args,'UNLINK',$unlink;
131 }
132  
133 12 my $self = bless \File::Temp->new(@args),$class;
134 12 ▶ if (defined $data) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data) 4 8 12
135 4 Quiq::Path->write($self,$data);
136 }
137 12 ▶ if ($pathOnly) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pathOnly) 1 11 12
138 1 Quiq::Path->delete("$self");
139 }
140  
141 12 return $self;
142 }
143  
144 # -----------------------------------------------------------------------------
145  
146 =head1 VERSION
147  
148 1.240
149  
150 =head1 AUTHOR
151  
152 Frank Seitz, L<http://fseitz.de/>
153  
154 =head1 COPYRIGHT
155  
156 Copyright (C) 2026 Frank Seitz
157  
158 =head1 LICENSE
159  
160 This code is free software; you can redistribute it and/or modify
161 it under the same terms as Perl itself.
162  
163 =cut
164  
165 # -----------------------------------------------------------------------------
166  
167 270 1;
168  
169 # eof
« Quiq/Html/Resources.pm ↑ Summary Quiq/ContentProcessor/Type.pm »