Dpkg/Compression/FileHandle.pm

filter: Statementstmt 76.0% 114 / 150 Branchbran 55.5% 40 / 72 Conditioncond 31.8% 7 / 22 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 79.3% 23 / 29 Podpod 100% 8 / 8 totaltotal 65.8% 193 / 293 CC 45 SCAR 16.0
CC
45
Cov
66%
set_compression
12.0
new
8.3
get_filename
8.3
CRAP 4.9
« Dpkg/Substvars.pm ↑ Summary Dpkg/Deps/Multiple.pm »
1 # Copyright © 2008-2010 Raphaël Hertzog <hertzog@debian.org>
2 # Copyright © 2012-2014 Guillem Jover <guillem@debian.org>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16  
17 =encoding utf8
18  
19 =head1 NAME
20  
21 Dpkg::Compression::FileHandle - class dealing transparently with file compression
22  
23 =head1 SYNOPSIS
24  
25 use Dpkg::Compression::FileHandle;
26  
27 my ($fh, @lines);
28  
29 $fh = Dpkg::Compression::FileHandle->new(filename => 'sample.gz');
30 print $fh "Something\n";
31 close $fh;
32  
33 $fh = Dpkg::Compression::FileHandle->new();
34 open($fh, '>', 'sample.bz2');
35 print $fh "Something\n";
36 close $fh;
37  
38 $fh = Dpkg::Compression::FileHandle->new();
39 $fh->open('sample.xz', 'w');
40 $fh->print("Something\n");
41 $fh->close();
42  
43 $fh = Dpkg::Compression::FileHandle->new(filename => 'sample.gz');
44 @lines = <$fh>;
45 close $fh;
46  
47 $fh = Dpkg::Compression::FileHandle->new();
48 open($fh, '<', 'sample.bz2');
49 @lines = <$fh>;
50 close $fh;
51  
52 $fh = Dpkg::Compression::FileHandle->new();
53 $fh->open('sample.xz', 'r');
54 @lines = $fh->getlines();
55 $fh->close();
56  
57 =head1 DESCRIPTION
58  
59 Dpkg::Compression::FileHandle is a class that can be used
60 like any filehandle and that deals transparently with compressed
61 files. By default, the compression scheme is guessed from the filename
62 but you can override this behavior with the method set_compression().
63  
64 If you don't open the file explicitly, it will be auto-opened on the
65 first read or write operation based on the filename set at creation time
66 (or later with the set_filename() method).
67  
68 Once a file has been opened, the filehandle must be closed before being
69 able to open another file.
70  
71 =cut
72  
73 package Dpkg::Compression::FileHandle 1.02;
74  
75 23 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
76  
77 23 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 23 ▶use Dpkg::Compression;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 23 ▶use Dpkg::Compression::Process;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 23 ▶use Dpkg::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 23 ▶use Dpkg::ErrorHandling;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 23 ▶use parent qw(IO::File Tie::Handle);
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 # Useful reference to understand some kludges required to have the class
87 # behave like a filehandle:
88 # <http://blog.woobling.org/2009/10/are-filehandles-objects.html>
89  
90 =head1 STANDARD FUNCTIONS
91  
92 The standard functions acting on filehandles should accept a
93 Dpkg::Compression::FileHandle object transparently including
94 open() (only when using the variant with 3 parameters), close(),
95 binmode(), eof(), fileno(), getc(), print(), printf(), read(),
96 sysread(), say(), write(), syswrite(), seek(), sysseek(), tell().
97  
98 Note however that seek() and sysseek() will only work on uncompressed
99 files as compressed files are really pipes to the compressor programs
100 and you can't seek on a pipe.
101  
102 =head1 FileHandle METHODS
103  
104 The class inherits from L<IO::File> so all methods that work on this
105 class should work for Dpkg::Compression::FileHandle too. There
106 may be exceptions though.
107  
108 =head1 PUBLIC METHODS
109  
110 =over 4
111  
112 =item $fh = Dpkg::Compression::FileHandle->new(%opts)
113  
114 Creates a new filehandle supporting on-the-fly compression/decompression.
115  
116 Options:
117  
118 =over
119  
120 =item B<filename>
121  
122 See $fh->set_filename().
123  
124 =item B<compression>
125  
126 See $fh->set_compression().
127  
128 =item B<compression_level>
129  
130 See $fh->set_compression_level().
131  
132 =item B<add_comp_ext>
133  
134 If set to true, then the extension corresponding to the selected
135 compression scheme is automatically added to the recorded filename.
136 It is incompatible with automatic detection of the compression method.
137  
138 =back
139  
140 =cut
141  
142 ## Class methods.
143  
144 183 ▶sub new {
Subroutine new: called CC=7 SCAR=21.2
Pod documented
145 183 my ($this, %opts) = @_;
146 183 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
01830
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
147 183 my $self = IO::File->new();
148 # Tying is required to overload the open functions and to auto-open
149 # the file on first read/write operation.
150 183 tie *$self, $class, $self; ## no critic (Miscellanea::ProhibitTies)
151 183 bless $self, $class;
152 # Initializations.
153 183 *$self->{compression} = 'auto';
154 183 *$self->{compressor} = Dpkg::Compression::Process->new();
155 *$self->{add_comp_ext} = $opts{add_compression_extension} ||
156 183 ▶ $opts{add_comp_ext} || 0;
Condition40%2/5
$opts{'add_compression_extension'} || $opts{'add_comp_ext'} || 0
l!l
0183
$opts{"add_compression_extension"} or $opts{"add_comp_ext"}
l!l&&r!l&&!r
00183
MC/DC0%0/2
$opts{'add_compression_extension'} || $opts{'add_comp_ext'} || 0
$opts{"add_compression_extension"} $opts{"add_comp_ext"}
Truth table33%1/3
A or B
A= $opts{"add_compression_extension"}B= $opts{"add_comp_ext"}
ABresult
1X1
011
000
157 183 *$self->{allow_sigpipe} = 0;
158 183 ▶ if (exists $opts{filename}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"filename"}) 39 144 183
159 39 $self->set_filename($opts{filename});
160 }
161 183 ▶ if (exists $opts{compression}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"compression"}) 0 183 183
162 0 $self->set_compression($opts{compression});
163 }
164 183 ▶ if (exists $opts{compression_level}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"compression_level"}) 0 183 183
165 0 $self->set_compression_level($opts{compression_level});
166 }
167 183 return $self;
168 }
169  
170 =item $fh->ensure_open($mode, %opts)
171  
172 Ensure the file is opened in the requested mode ("r" for read and "w" for
173 write). The options are passed down to the compressor's spawn() call, if one
174 is used. Opens the file with the recorded filename if needed. If the file
175 is already open but not in the requested mode, then it errors out.
176  
177 =cut
178  
179 14390 ▶sub ensure_open {
Subroutine ensure_open: called CC=5 SCAR=17.4
Pod documented
180 14390 my ($self, $mode, %opts) = @_;
181 14390 ▶ if (exists *$self->{mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists *$self->{'mode'}) { } 14343 47 14390
182 14343 ▶ return if *$self->{mode} eq $mode;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"mode"} eq $mode 14343 0 14343
183 0 croak "ensure_open requested incompatible mode: $mode";
184 } else {
185 # Sanitize options.
186 47 delete $opts{from_pipe};
187 47 delete $opts{from_file};
188 47 delete $opts{to_pipe};
189 47 delete $opts{to_file};
190  
191 47 ▶ if ($mode eq 'w') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'w') { } 0 47 47
elsif ($mode eq 'r') { } 47 0 47
192 0 $self->_open_for_write(%opts);
193 } elsif ($mode eq 'r') {
194 47 $self->_open_for_read(%opts);
195 } else {
196 0 croak "invalid mode in ensure_open: $mode";
197 }
198 }
199 }
200  
201 ## Tied handle methods.
202  
203 183 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
204 183 my ($class, $self) = @_;
205 183 return $self;
206 }
207  
208 4683 ▶sub WRITE {
Subroutine WRITE: called CC=1 SCAR=0.0
209 4683 my ($self, $scalar, $length, $offset) = @_;
210 4683 $self->ensure_open('w');
211 4683 return *$self->{file}->write($scalar, $length, $offset);
212 }
213  
214 0 ▶sub READ {
Subroutine READ: not called CC=1 SCAR=6.9
215 0 my ($self, $scalar, $length, $offset) = @_;
216 0 $self->ensure_open('r');
217 0 return *$self->{file}->read($scalar, $length, $offset);
218 }
219  
220 9697 ▶sub READLINE {
Subroutine READLINE: called CC=2 SCAR=6.9
221 9697 my $self = shift;
222 9697 $self->ensure_open('r');
223 9694 ▶ return *$self->{file}->getlines() if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 9 9685 9694
224 9685 return *$self->{file}->getline();
225 }
226  
227 144 ▶sub OPEN {
Subroutine OPEN: called CC=4 SCAR=14.5
228 144 my ($self, @args) = @_;
229  
230 144 ▶ if (scalar @args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args == 2) { } 144 0 144
231 144 my ($mode, $filename) = @args;
232 144 $self->set_filename($filename);
233 144 ▶ if ($mode eq '>') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq '>') { } 25 119 144
elsif ($mode eq '<') { } 119 0 119
234 25 $self->_open_for_write();
235 } elsif ($mode eq '<') {
236 119 $self->_open_for_read();
237 } else {
238 0 croak 'Dpkg::Compression::FileHandle does not support ' .
239 "open() mode $mode";
240 }
241 } else {
242 0 croak 'Dpkg::Compression::FileHandle only supports open() ' .
243 'with 3 parameters';
244 }
245 # Always works (otherwise errors out).
246 140 return 1;
247 }
248  
249 146 ▶sub CLOSE {
Subroutine CLOSE: called CC=3 SCAR=11.2
250 146 my ($self, @args) = @_;
251 146 my $ret = 1;
252 146 ▶ if (defined *$self->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{'file'}) { } 146 0 146
253 146 ▶ $ret = *$self->{file}->close(@args) if *$self->{file}->opened();
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"file"}->opened 141 5 146
254 } else {
255 0 $ret = 0;
256 }
257 146 $self->_cleanup();
258 146 return $ret;
259 }
260  
261 0 ▶sub FILENO {
Subroutine FILENO: not called CC=2 SCAR=17.9
262 0 my ($self, @args) = @_;
263  
264 0 ▶ return *$self->{file}->fileno(@args) if defined *$self->{file};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"file"} 0 0 0
265 0 return;
266 }
267  
268 8 ▶sub EOF {
Subroutine EOF: called CC=2 SCAR=8.1
269 # Since perl 5.12, an integer parameter is passed describing how the
270 # function got called, just ignore it.
271 8 my ($self, $param, @args) = @_;
272  
273 8 ▶ return *$self->{file}->eof(@args) if defined *$self->{file};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"file"} 8 0 8
274 0 return 1;
275 }
276  
277 0 ▶sub SEEK {
Subroutine SEEK: not called CC=2 SCAR=17.9
278 0 my ($self, @args) = @_;
279  
280 0 ▶ return *$self->{file}->seek(@args) if defined *$self->{file};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"file"} 0 0 0
281 0 return 0;
282 }
283  
284 0 ▶sub TELL {
Subroutine TELL: not called CC=2 SCAR=17.9
285 0 my ($self, @args) = @_;
286  
287 0 ▶ return *$self->{file}->tell(@args) if defined *$self->{file};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"file"} 0 0 0
288 0 return -1;
289 }
290  
291 13 ▶sub BINMODE {
Subroutine BINMODE: called CC=2 SCAR=8.1
292 13 my ($self, @args) = @_;
293  
294 13 ▶ return *$self->{file}->binmode(@args) if defined *$self->{file};
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"file"} 13 0 13
295 0 return;
296 }
297  
298 ## Normal methods.
299  
300 =item $fh->set_compression($comp)
301  
302 Defines the compression method used. $comp should one of the methods supported by
303 L<Dpkg::Compression> or "none" or "auto". "none" indicates that the file is
304 uncompressed and "auto" indicates that the method must be guessed based
305 on the filename extension used.
306  
307 =cut
308  
309 0 ▶sub set_compression {
Subroutine set_compression: not called CC=3 SCAR=24.8
Pod documented
310 0 my ($self, $method) = @_;
311 0 ▶ if ($method ne 'none' and $method ne 'auto') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method ne "none" and $method ne "auto") 0 0 0
Condition0%0/3
$method ne "none" and $method ne "auto"
!ll&&!rl&&r
000
MC/DC0%0/2
$method ne "none" and $method ne "auto"
$method ne "none" $method ne "auto"
Truth table0%0/3
A and B
A= $method ne "none"B= $method ne "auto"
ABresult
0X0
100
111
312 0 *$self->{compressor}->set_compression($method);
313 }
314 0 *$self->{compression} = $method;
315 }
316  
317 =item $fh->set_compression_level($level)
318  
319 Indicate the desired compression level. It should be a value accepted
320 by the function compression_is_valid_level() of L<Dpkg::Compression>.
321  
322 =cut
323  
324 0 ▶sub set_compression_level {
Subroutine set_compression_level: not called CC=1 SCAR=6.9
Pod documented
325 0 my ($self, $level) = @_;
326 0 *$self->{compressor}->set_compression_level($level);
327 }
328  
329 =item $fh->set_filename($name, [$add_comp_ext])
330  
331 Use $name as filename when the file must be opened/created. If
332 $add_comp_ext is passed, it indicates whether the default extension
333 of the compression method must be automatically added to the filename
334 (or not).
335  
336 =cut
337  
338 183 ▶sub set_filename {
Subroutine set_filename: called CC=4 SCAR=16.6
Pod documented
339 183 my ($self, $filename, $add_comp_ext) = @_;
340 183 *$self->{filename} = $filename;
341 # Automatically add compression extension to filename.
342 183 ▶ if (defined($add_comp_ext)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $add_comp_ext) 0 183 183
343 0 *$self->{add_comp_ext} = $add_comp_ext;
344 }
345 183 my $comp_ext_regex = compression_get_file_extension_regex();
346 183 ▶ if (*$self->{add_comp_ext} and $filename =~ /\.$comp_ext_regex$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"add_comp_ext"} and $filename =~ /\.$comp_ext_regex$/u) 0 183 183
Condition33%1/3
*$self->{"add_comp_ext"} and $filename =~ /\.$comp_ext_regex$/u
!ll&&!rl&&r
18300
MC/DC0%0/2
*$self->{"add_comp_ext"} and $filename =~ /\.$comp_ext_regex$/u
*$self->{"add_comp_ext"} $filename =~ /\.$comp_ext_regex$/u
Truth table33%1/3
A and B
A= *$self->{"add_comp_ext"}B= $filename =~ /\.$comp_ext_regex$/u
ABresult
0X0
100
111
347 0 croak "filename $filename already has an extension of a compressed " .
348 'file and add_comp_ext is active';
349 }
350 }
351  
352 =item $file = $fh->get_filename()
353  
354 Returns the filename that would be used when the filehandle must
355 be opened (both in read and write mode). This function errors out
356 if "add_comp_ext" is enabled while the compression method is set
357 to "auto". The returned filename includes the extension of the compression
358 method if "add_comp_ext" is enabled.
359  
360 =cut
361  
362 424 ▶sub get_filename {
Subroutine get_filename: called CC=4 SCAR=21.1
Pod documented
363 424 my $self = shift;
364 424 my $comp = *$self->{compression};
365 424 ▶ if (*$self->{add_comp_ext}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'add_comp_ext'}) { } 0 424 424
366 0 ▶ if ($comp eq 'auto') {
Branch: 2 branches
BranchTrueFalseTotal
if ($comp eq 'auto') { } 0 0 0
elsif ($comp eq 'none') { } 0 0 0
367 0 croak 'automatic detection of compression is ' .
368 'incompatible with add_comp_ext';
369 } elsif ($comp eq 'none') {
370 0 return *$self->{filename};
371 } else {
372 0 return *$self->{filename} . '.' .
373 compression_get_file_extension($comp);
374 }
375 } else {
376 424 return *$self->{filename};
377 }
378 }
379  
380 =item $ret = $fh->use_compression()
381  
382 Returns "0" if no compression is used and the compression method used
383 otherwise. If the compression is set to "auto", the value returned
384 depends on the extension of the filename obtained with the get_filename()
385 method.
386  
387 =cut
388  
389 191 ▶sub use_compression {
Subroutine use_compression: called CC=4 SCAR=14.3
Pod documented
390 191 my $self = shift;
391 191 my $comp = *$self->{compression};
392 191 ▶ if ($comp eq 'none') {
Branch: 2 branches
BranchTrueFalseTotal
if ($comp eq 'none') { } 0 191 191
elsif ($comp eq 'auto') { } 191 0 191
393 0 return 0;
394 } elsif ($comp eq 'auto') {
395 191 $comp = compression_guess_from_filename($self->get_filename());
396 191 ▶ *$self->{compressor}->set_compression($comp) if $comp;
Branch: 1 branch
BranchTrueFalseTotal
if $comp 14 177 191
397 }
398 191 return $comp;
399 }
400  
401 =item $real_fh = $fh->get_filehandle()
402  
403 Returns the real underlying filehandle. Useful if you want to pass it
404 along in a derived class.
405  
406 =cut
407  
408 10 ▶sub get_filehandle {
Subroutine get_filehandle: called CC=2 SCAR=7.2
Pod documented
409 10 my $self = shift;
410 10 ▶ return *$self->{file} if exists *$self->{file};
Branch: 1 branch
BranchTrueFalseTotal
if exists *$self->{"file"} 10 0 10
411 }
412  
413 ## Internal methods.
414  
415 25 ▶sub _open_for_write {
Subroutine _open_for_write: called CC=4 SCAR=14.0
416 25 my ($self, %opts) = @_;
417 25 my $filehandle;
418  
419 croak 'cannot reopen an already opened compressed file'
420 25 ▶ if exists *$self->{mode};
Branch: 1 branch
BranchTrueFalseTotal
if exists *$self->{"mode"} 0 25 25
421  
422 25 ▶ if ($self->use_compression()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_compression) { } 9 16 25
423 *$self->{compressor}->compress(
424 9 from_pipe => \$filehandle,
425 to_file => $self->get_filename(),
426 %opts,
427 );
428 } else {
429 16 ▶ CORE::open($filehandle, '>', $self->get_filename)
Branch: 1 branch
BranchTrueFalseTotal
open $filehandle, ">", $self->get_filename or syserr(g_("cannot write %s"), $self->get_filename) 16 0 16
430 or syserr(g_('cannot write %s'), $self->get_filename());
431 }
432 23 *$self->{mode} = 'w';
433 23 *$self->{file} = $filehandle;
434 }
435  
436 166 ▶sub _open_for_read {
Subroutine _open_for_read: called CC=4 SCAR=13.9
437 166 my ($self, %opts) = @_;
438 166 my $filehandle;
439  
440 croak 'cannot reopen an already opened compressed file'
441 166 ▶ if exists *$self->{mode};
Branch: 1 branch
BranchTrueFalseTotal
if exists *$self->{"mode"} 0 166 166
442  
443 166 ▶ if ($self->use_compression()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_compression) { } 5 161 166
444 *$self->{compressor}->uncompress(
445 5 to_pipe => \$filehandle,
446 from_file => $self->get_filename(),
447 %opts,
448 );
449 3 *$self->{allow_sigpipe} = 1;
450 } else {
451 161 ▶ CORE::open($filehandle, '<', $self->get_filename)
Branch: 1 branch
BranchTrueFalseTotal
open $filehandle, "<", $self->get_filename or syserr(g_("cannot read %s"), $self->get_filename) 158 3 161
452 or syserr(g_('cannot read %s'), $self->get_filename());
453 }
454 161 *$self->{mode} = 'r';
455 161 *$self->{file} = $filehandle;
456 }
457  
458 146 ▶sub _cleanup {
Subroutine _cleanup: called CC=6 SCAR=19.7
459 146 my $self = shift;
460 146 ▶ my $cmdline = *$self->{compressor}{cmdline} // '';
Condition100%2/2
*$self->{"compressor"}{"cmdline"} // ""
l!l
10136
MC/DC100%1/1
*$self->{"compressor"}{"cmdline"} // ""
*$self->{"compressor"}{"cmdline"}
Truth table100%2/2
A
A= *$self->{"compressor"}{"cmdline"}
Aresult
11
00
461 *$self->{compressor}->wait_end_process(
462 no_check => *$self->{allow_sigpipe},
463 146 );
464 146 ▶ if (*$self->{allow_sigpipe}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"allow_sigpipe"}) 3 143 146
465 3 require POSIX;
466 3 ▶ unless (($? == 0) || (POSIX::WIFSIGNALED($?) &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($? == 0 or POSIX::WIFSIGNALED($?) and POSIX::WTERMSIG($?) == 13) 0 3 3
Condition16%1/6
$? == 0 or POSIX::WIFSIGNALED($?) and POSIX::WTERMSIG($?) == 13
l!l&&r!l&&!r
300
POSIX::WIFSIGNALED($?) and POSIX::WTERMSIG($?) == 13
!ll&&!rl&&r
000
MC/DC0%0/3
$? == 0 or POSIX::WIFSIGNALED($?) and POSIX::WTERMSIG($?) == 13
$? == 0 POSIX::WIFSIGNALED($?) POSIX::WTERMSIG($?) == 13
Truth table25%1/4
A or B and C
A= $? == 0B= POSIX::WIFSIGNALED($?)C= POSIX::WTERMSIG($?) == 13
ABCresult
1XX1
0111
00X0
0100
467 (POSIX::WTERMSIG($?) == POSIX::SIGPIPE()))) {
468 0 subprocerr($cmdline);
469 }
470 3 *$self->{allow_sigpipe} = 0;
471 }
472 146 delete *$self->{mode};
473 146 delete *$self->{file};
474 }
475  
476 =back
477  
478 =head1 DERIVED CLASSES
479  
480 If you want to create a class that inherits from
481 Dpkg::Compression::FileHandle you must be aware that
482 the object is a reference to a GLOB that is returned by Symbol::gensym()
483 and as such it's not a HASH.
484  
485 You can store internal data in a hash but you have to use
486 C<*$self->{...}> to access the associated hash like in the example below:
487  
488 sub set_option {
489 my ($self, $value) = @_;
490 *$self->{option} = $value;
491 }
492  
493 =head1 CHANGES
494  
495 =head2 Version 1.02 (dpkg 1.23.8)
496  
497 Change behavior: Change $fh->set_filename() to croak instead of warn on
498 'add_comp_ext' with a $filename with a compression extension.
499  
500 =head2 Version 1.01 (dpkg 1.17.11)
501  
502 New argument: $fh->ensure_open() accepts an %opts argument.
503  
504 =head2 Version 1.00 (dpkg 1.15.6)
505  
506 Mark the module as public.
507  
508 =cut
509 21 1;
« Dpkg/Substvars.pm ↑ Summary Dpkg/Deps/Multiple.pm »