Bio/Root/IO.pm

filter: Statementstmt 56.0% 212 / 378 Branchbran 34.6% 86 / 248 Conditioncond 28.0% 49 / 175 MC/DCmcdc 11.5% 11 / 95 Subroutinesub 90.6% 29 / 32 Podpod 100% 15 / 15 totaltotal 42.6% 402 / 943 CC 188 SCAR 60.6
CC
188
Cov
43%
rmtree
1892.0
_insert
210.0
BEGIN
158.3
CRAP 427.1
« Bio/OntologyIO/Handlers/InterProHandler.pm ↑ Summary Bio/AlignIO/proda.pm »
1 package Bio::Root::IO;
2 582 $Bio::Root::IO::VERSION = '1.7.8';
3 582 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 582 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 582 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 582 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 582 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 582 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # as of 2016, worked on most systems, but will test this in a RC
11 582 my %modes = ( 0 => 'r', 1 => 'w', 2 => 'rw' );
12  
13 =head1 NAME
14  
15 Bio::Root::IO - BioPerl base IO handling class
16  
17 =head1 SYNOPSIS
18  
19 # Use stream I/O in your module
20 $self->{'io'} = Bio::Root::IO->new(-file => "myfile");
21 $self->{'io'}->_print("some stuff");
22 my $line = $self->{'io'}->_readline();
23 $self->{'io'}->_pushback($line);
24 $self->{'io'}->close();
25  
26 # obtain platform-compatible filenames
27 $path = Bio::Root::IO->catfile($dir, $subdir, $filename);
28 # obtain a temporary file (created in $TEMPDIR)
29 ($handle) = $io->tempfile();
30  
31 =head1 DESCRIPTION
32  
33 This module provides methods that will usually be needed for any sort
34 of file- or stream-related input/output, e.g., keeping track of a file
35 handle, transient printing and reading from the file handle, a close
36 method, automatically closing the handle on garbage collection, etc.
37  
38 To use this for your own code you will either want to inherit from
39 this module, or instantiate an object for every file or stream you are
40 dealing with. In the first case this module will most likely not be
41 the first class off which your class inherits; therefore you need to
42 call _initialize_io() with the named parameters in order to set file
43 handle, open file, etc automatically.
44  
45 Most methods start with an underscore, indicating they are private. In
46 OO speak, they are not private but protected, that is, use them in
47 your module code, but a client code of your module will usually not
48 want to call them (except those not starting with an underscore).
49  
50 In addition this module contains a couple of convenience methods for
51 cross-platform safe tempfile creation and similar tasks. There are
52 some CPAN modules related that may not be available on all
53 platforms. At present, File::Spec and File::Temp are attempted. This
54 module defines $PATHSEP, $TEMPDIR, and $ROOTDIR, which will always be set,
55 and $OPENFLAGS, which will be set if either of File::Spec or File::Temp fails.
56  
57 The -noclose boolean (accessed via the noclose method) prevents a
58 filehandle from being closed when the IO object is cleaned up. This
59 is special behavior when a object like a parser might share a
60 filehandle with an object like an indexer where it is not proper to
61 close the filehandle as it will continue to be reused until the end of the
62 stream is reached. In general you won't want to play with this flag.
63  
64 =head1 AUTHOR Hilmar Lapp
65  
66 =cut
67  
68 582 our ($FILESPECLOADED, $FILETEMPLOADED,
69 $FILEPATHLOADED, $TEMPDIR,
70 $PATHSEP, $ROOTDIR,
71 $OPENFLAGS, $VERBOSE,
72 $ONMAC, $HAS_EOL, );
73  
74 582 my $TEMPCOUNTER;
75 582 my $HAS_WIN32 = 0;
76  
77 582 ▶BEGIN {
Subroutine BEGIN: called CC=21 SCAR=50.6
78 582 $TEMPCOUNTER = 0;
79 582 $FILESPECLOADED = 0;
80 582 $FILETEMPLOADED = 0;
81 582 $FILEPATHLOADED = 0;
82 582 $VERBOSE = 0;
83  
84 # try to load those modules that may cause trouble on some systems
85 582 eval {
86 582 require File::Path;
87 582 $FILEPATHLOADED = 1;
88 };
89 582 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 582 582
90 0 ▶ print STDERR "Cannot load File::Path: $@" if( $VERBOSE > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $Bio::Root::IO::VERBOSE > 0 0 0 0
91 # do nothing
92 }
93  
94 # If on Win32, attempt to find Win32 package
95 582 ▶ if($^O =~ /mswin/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /mswin/i) 0 582 582
96 0 eval {
97 0 require Win32;
98 0 $HAS_WIN32 = 1;
99 };
100 }
101  
102 # Try to provide a path separator. Why doesn't File::Spec export this,
103 # or did I miss it?
104 582 ▶ if ($^O =~ /mswin/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O =~ /mswin/i) { } 0 582 582
elsif ($^O =~ /macos/i) { } 0 582 582
105 0 $PATHSEP = "\\";
106 } elsif($^O =~ /macos/i) {
107 0 $PATHSEP = ":";
108 } else { # unix
109 582 $PATHSEP = "/";
110 }
111 582 eval {
112 582 require File::Spec;
113 582 $FILESPECLOADED = 1;
114 582 $TEMPDIR = File::Spec->tmpdir();
115 582 $ROOTDIR = File::Spec->rootdir();
116 582 require File::Temp; # tempfile creation
117 582 $FILETEMPLOADED = 1;
118 };
119 582 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 582 582
120 0 ▶ if(! defined($TEMPDIR)) { # File::Spec failed
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Bio::Root::IO::TEMPDIR) 0 0 0
121 # determine tempdir
122 0 ▶ if (defined $ENV{'TEMPDIR'} && -d $ENV{'TEMPDIR'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ENV{'TEMPDIR'} and -d $ENV{'TEMPDIR'}) { } 0 0 0
elsif (defined $ENV{'TMPDIR'} and -d $ENV{'TMPDIR'}) { } 0 0 0
Condition0%0/3
defined $ENV{"TEMPDIR"} and -d $ENV{"TEMPDIR"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"TEMPDIR"} and -d $ENV{"TEMPDIR"}
defined $ENV{"TEMPDIR"} -d $ENV{"TEMPDIR"}
Truth table0%0/3
A and B
A= defined $ENV{"TEMPDIR"}B= -d $ENV{"TEMPDIR"}
ABresult
0X0
100
111
123 0 $TEMPDIR = $ENV{'TEMPDIR'};
124 ▶ } elsif( defined $ENV{'TMPDIR'} && -d $ENV{'TMPDIR'} ) {
Condition0%0/3
defined $ENV{"TMPDIR"} and -d $ENV{"TMPDIR"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"TMPDIR"} and -d $ENV{"TMPDIR"}
defined $ENV{"TMPDIR"} -d $ENV{"TMPDIR"}
Truth table0%0/3
A and B
A= defined $ENV{"TMPDIR"}B= -d $ENV{"TMPDIR"}
ABresult
0X0
100
111
125 0 $TEMPDIR = $ENV{'TMPDIR'};
126 }
127 0 ▶ if($^O =~ /mswin/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O =~ /mswin/i) { } 0 0 0
elsif ($^O =~ /macos/i) { } 0 0 0
128 0 ▶ $TEMPDIR = 'C:\TEMP' unless $TEMPDIR;
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Root::IO::TEMPDIR 0 0 0
129 0 $ROOTDIR = 'C:';
130 } elsif($^O =~ /macos/i) {
131 0 ▶ $TEMPDIR = "" unless $TEMPDIR; # what is a reasonable default on Macs?
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Root::IO::TEMPDIR 0 0 0
132 0 $ROOTDIR = ""; # what is reasonable??
133 } else { # unix
134 0 ▶ $TEMPDIR = "/tmp" unless $TEMPDIR;
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Root::IO::TEMPDIR 0 0 0
135 0 $ROOTDIR = "/";
136 }
137 0 ▶ if (!( -d $TEMPDIR && -w $TEMPDIR )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $Bio::Root::IO::TEMPDIR and -w $Bio::Root::IO::TEMPDIR) 0 0 0
Condition0%0/3
-d $Bio::Root::IO::TEMPDIR and -w $Bio::Root::IO::TEMPDIR
!ll&&!rl&&r
000
MC/DC0%0/2
-d $Bio::Root::IO::TEMPDIR and -w $Bio::Root::IO::TEMPDIR
-d $Bio::Root::IO::TEMPDIR -w $Bio::Root::IO::TEMPDIR
Truth table0%0/3
A and B
A= -d $Bio::Root::IO::TEMPDIRB= -w $Bio::Root::IO::TEMPDIR
ABresult
0X0
100
111
138 0 $TEMPDIR = '.'; # last resort
139 }
140 }
141 # File::Temp failed (alone, or File::Spec already failed)
142 # determine open flags for tempfile creation using Fcntl
143 0 $OPENFLAGS = O_CREAT | O_EXCL | O_RDWR;
144 0 for my $oflag (qw/FOLLOW BINARY LARGEFILE EXLOCK NOINHERIT TEMPORARY/){
145 0 my ($bit, $func) = (0, "Fcntl::O_" . $oflag);
146 582 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
147 0 ▶ $OPENFLAGS |= $bit if eval { $bit = &$func(); 1 };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $bit = &$func(); 1 } } 0 0 0
148 }
149 }
150 582 $ONMAC = "\015" eq "\n";
151 }
152  
153  
154 =head2 new
155  
156 Title : new
157 Usage : my $io = Bio::Root::IO->new( -file => 'data.txt' );
158 Function: Create new class instance. It automatically calls C<_initialize_io>.
159 Args : Same named parameters as C<_initialize_io>.
160 Returns : A Bio::Root::IO object
161  
162 =cut
163  
164 3905 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
165 3905 my ($caller, @args) = @_;
166 3905 my $self = $caller->SUPER::new(@args);
167 3905 $self->_initialize_io(@args);
168 3905 return $self;
169 }
170  
171  
172 =head2 _initialize_io
173  
174 Title : _initialize_io
175 Usage : $io->_initialize_io(@params);
176 Function: Initializes filehandle and other properties from the parameters.
177 Args : The following named parameters are currently recognized:
178 -file name of file to read or write to
179 -fh file handle to read or write to (mutually exclusive
180 with -file and -string)
181 -input name of file, or filehandle (GLOB or IO::Handle object)
182 to read of write to
183 -string string to read from (will be converted to filehandle)
184 -url name of URL to open
185 -flush boolean flag to autoflush after each write
186 -noclose boolean flag, when set to true will not close a
187 filehandle (must explicitly call close($io->_fh)
188 -retries number of times to try a web fetch before failure
189 -ua_parms when using -url, hashref of key => value parameters
190 to pass to LWP::UserAgent->new(). A useful value might
191 be, for example, {timeout => 60 } (ua defaults to 180s)
192 Returns : True
193  
194 =cut
195  
196 5021 ▶sub _initialize_io {
Subroutine _initialize_io: called CC=35 SCAR=44.0
197 5021 my($self, @args) = @_;
198  
199 5021 $self->_register_for_cleanup(\&_io_cleanup);
200  
201 5021 my ($input, $noclose, $file, $fh, $string,
202 $flush, $url, $retries, $ua_parms) =
203 $self->_rearrange([qw(INPUT NOCLOSE FILE FH STRING FLUSH URL RETRIES UA_PARMS)],
204 @args);
205  
206 5021 my $mode;
207  
208 5021 ▶ if ($url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url) 3 5018 5021
209 3 ▶ $retries ||= 5;
Condition50%1/2
$retries ||= 5
l!l
03
MC/DC0%0/1
$retries ||= 5
$retries
Truth table50%1/2
A
A= $retries
Aresult
11
00
210  
211 3 require LWP::UserAgent;
212 3 my $ua = LWP::UserAgent->new(%$ua_parms);
213 3 my $http_result;
214 3 my ($handle, $tempfile) = $self->tempfile();
215 3 CORE::close($handle);
216  
217 3 ▶ for (my $try = 1 ; $try <= $retries ; $try++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($try <= $retries) 3 0 3
218 3 $http_result = $ua->get($url, ':content_file' => $tempfile);
219 3 ▶ $self->warn("[$try/$retries] tried to fetch $url, but server ".
Branch: 1 branch
BranchTrueFalseTotal
unless $http_result->is_success 0 3 3
220 "threw ". $http_result->code . ". retrying...")
221 if !$http_result->is_success;
222 3 ▶ last if $http_result->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $http_result->is_success 3 0 3
223 }
224 3 ▶ $self->throw("Failed to fetch $url, server threw ".$http_result->code)
Branch: 1 branch
BranchTrueFalseTotal
unless $http_result->is_success 0 3 3
225 if !$http_result->is_success;
226  
227 3 $file = $tempfile;
228 3 $mode = '>';
229 }
230  
231 5021 delete $self->{'_readbuffer'};
232 5021 delete $self->{'_filehandle'};
233 5021 ▶ $self->noclose( $noclose) if defined $noclose;
Branch: 1 branch
BranchTrueFalseTotal
if defined $noclose 33 4988 5021
234 # determine whether the input is a file(name) or a stream
235 5021 ▶ if ($input) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input) 18 5003 5021
236 18 ▶ if (ref(\$input) eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref \$input eq 'SCALAR') { } 18 0 18
elsif (ref $input and ref $input eq 'GLOB' || $input->isa('IO::Handle')) { } 0 0 0
237 # we assume that a scalar is a filename
238 18 ▶ if ($file && ($file ne $input)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and $file ne $input) 0 18 18
Condition33%1/3
$file and $file ne $input
!ll&&!rl&&r
1800
MC/DC0%0/2
$file and $file ne $input
$file $file ne $input
Truth table33%1/3
A and B
A= $fileB= $file ne $input
ABresult
0X0
100
111
239 0 $self->throw("Input file given twice: '$file' and '$input' disagree");
240 }
241 18 $file = $input;
242 ▶ } elsif (ref($input) &&
Condition0%0/6
ref $input and ref $input eq "GLOB" || $input->isa("IO::Handle")
!ll&&!rl&&r
000
ref $input eq "GLOB" or $input->isa("IO::Handle")
l!l&&r!l&&!r
000
MC/DC0%0/3
ref $input and ref $input eq "GLOB" || $input->isa("IO::Handle")
ref $input ref $input eq "GLOB" $input->isa("IO::Handle")
Truth table0%0/4
A and B or C
A= ref $inputB= ref $input eq "GLOB"C= $input->isa("IO::Handle")
ABCresult
0XX0
1000
11X1
1011
243 ((ref($input) eq 'GLOB') || $input->isa('IO::Handle'))) {
244 # input is a stream
245 0 $fh = $input;
246 } else {
247 # let's be strict for now
248 0 $self->throw("Unable to determine type of input $input: ".
249 "not string and not GLOB");
250 }
251 }
252  
253 5021 ▶ if (defined($file) && defined($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and defined $fh) 0 5021 5021
Condition66%2/3
defined $file and defined $fh
!ll&&!rl&&r
398910320
MC/DC0%0/2
defined $file and defined $fh
defined $file defined $fh
Truth table66%2/3
A and B
A= defined $fileB= defined $fh
ABresult
0X0
100
111
254 0 $self->throw("Providing both a file and a filehandle for reading - ".
255 "only one please!");
256 }
257  
258 5021 ▶ if ($string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string) 44 4977 5021
259 44 ▶ if (defined($file) || defined($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file or defined $fh) 0 44 44
Condition33%1/3
defined $file or defined $fh
l!l&&r!l&&!r
0044
MC/DC0%0/2
defined $file or defined $fh
defined $file defined $fh
Truth table33%1/3
A or B
A= defined $fileB= defined $fh
ABresult
1X1
011
000
260 0 $self->throw("File or filehandle provided with -string, ".
261 "please unset if you are using -string as a file");
262 }
263 44 ▶ open $fh, '<', \$string or $self->throw("Could not read string: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", \$string or $self->throw("Could not read string: $!") 44 0 44
264 }
265  
266 5021 ▶ if (defined($file) && ($file ne '')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and $file ne "") 1032 3989 5021
Condition66%2/3
defined $file and $file ne ""
!ll&&!rl&&r
398901032
MC/DC50%1/2
defined $file and $file ne ""
defined $file $file ne ""
Truth table66%2/3
A and B
A= defined $fileB= $file ne ""
ABresult
0X0
100
111
267 1032 $self->file($file);
268 1032 ($mode, $file) = $self->cleanfile;
269 1032 ▶ $mode ||= '<';
Condition100%2/2
$mode ||= "<"
l!l
249783
MC/DC100%1/1
$mode ||= "<"
$mode
Truth table100%2/2
A
A= $mode
Aresult
11
00
270 1032 ▶ my $action = ($mode =~ m/>/) ? 'write' : 'read';
Branch: 1 branch
BranchTrueFalseTotal
$mode =~ />/ ? : 245 787 1032
271 1032 $fh = Symbol::gensym();
272 1032 ▶ open $fh, $mode, $file or $self->throw("Could not $action file '$file': $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $mode, $file or $self->throw("Could not $action file '${file}': $!") 1032 0 1032
273 }
274  
275 5021 ▶ if (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh) 1224 3797 5021
276 # check filehandle to ensure it's one of:
277 # a GLOB reference, as in: open(my $fh, "myfile");
278 # an IO::Handle or IO::String object
279 # the UNIVERSAL::can added to fix Bug2863
280 1224 ▶ unless ( ( ref $fh and ( ref $fh eq 'GLOB' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fh and ref $fh eq "GLOB" or ref $fh and UNIVERSAL::can($fh, "can") and $fh->isa("IO::Handle") || $fh->isa("IO::String")) 0 1224 1224
Condition46%7/15
ref $fh and ref $fh eq "GLOB" or ref $fh and UNIVERSAL::can($fh, "can") and $fh->isa("IO::Handle") || $fh->isa("IO::String")
l!l&&r!l&&!r
1170540
ref $fh and ref $fh eq "GLOB"
!ll&&!rl&&r
0541170
ref $fh and UNIVERSAL::can($fh, "can") and $fh->isa("IO::Handle") || $fh->isa("IO::String")
!ll&&!rl&&r
0054
ref $fh and UNIVERSAL::can($fh, "can")
!ll&&!rl&&r
0054
$fh->isa("IO::Handle") or $fh->isa("IO::String")
l!l&&r!l&&!r
0540
MC/DC0%0/6
ref $fh and ref $fh eq "GLOB" or ref $fh and UNIVERSAL::can($fh, "can") and $fh->isa("IO::Handle") || $fh->isa("IO::String")
ref $fh ref $fh eq "GLOB" ref $fh UNIVERSAL::can($fh, "can") $fh->isa("IO::Handle") $fh->isa("IO::String")
Truth table18%2/11
A and B or C and D and E or F
A= ref $fhB= ref $fh eq "GLOB"C= ref $fhD= UNIVERSAL::can($fh, "can")E= $fh->isa("IO::Handle")F= $fh->isa("IO::String")
ABCDEFresult
11XXXX1
0X111X1
0X11011
10111X1
1011011
0X0XXX0
0X10XX0
0X11000
100XXX0
1010XX0
1011000
281 or ( ref $fh and ( UNIVERSAL::can( $fh, 'can' ) )
282 and ( $fh->isa('IO::Handle')
283 or $fh->isa('IO::String') ) )
284 ) {
285 0 $self->throw("Object $fh does not appear to be a file handle");
286 }
287 1224 ▶ if ($HAS_EOL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::Root::IO::HAS_EOL) 0 1224 1224
288 0 binmode $fh, ':raw:eol(LF-Native)';
289 }
290 1224 $self->_fh($fh); # if $fh not provided, defaults to STDIN and STDOUT
291 }
292  
293 5021 ▶ $self->_flush_on_write(defined $flush ? $flush : 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $flush ? : 0 5021 5021
294  
295 5021 return 1;
296 }
297  
298  
299 =head2 _fh
300  
301 Title : _fh
302 Usage : $io->_fh($newval);
303 Function: Get or set the file handle for the stream encapsulated.
304 Args : Optional filehandle to use
305 Returns : Filehandle for the stream
306  
307 =cut
308  
309 398743 ▶sub _fh {
Subroutine _fh: called CC=2 SCAR=6.9
310 398743 my ($self, $value) = @_;
311 398743 ▶ if ( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1254 397489 398743
312 1254 $self->{'_filehandle'} = $value;
313 }
314 398743 return $self->{'_filehandle'};
315 }
316  
317  
318 =head2 mode
319  
320 Title : mode
321 Usage : $io->mode();
322 $io->mode(-force => 1);
323 Function: Determine if the object was opened for reading or writing
324 Args : -force: Boolean. Once mode() has been called, the mode is cached for
325 further calls to mode(). Use this argument to override this
326 behavior and re-check the object's mode.
327 Returns : Mode of the object:
328 'r' for readable
329 'w' for writable
330 'rw' for readable and writable
331 '?' if mode could not be determined (e.g. for a -url)
332  
333 =cut
334  
335 58 ▶sub mode {
Subroutine mode: called CC=10 SCAR=29.4
Pod documented
336 58 my ($self, %arg) = @_;
337  
338 # Method 1: IO::Handle::fdopen
339 # my $iotest = new IO::Handle;
340 # $iotest->fdopen( dup(fileno($fh)) , 'r' );
341 # if ($iotest->error == 0) { ... }
342 # It did not actually seem to work under any platform, since there would no
343 # error if the filehandle had been opened writable only. It could not be
344 # hacked around when dealing with unseekable (piped) filehandles.
345  
346 # Method 2: readline, a.k.a. the <> operator
347 # no warnings "io";
348 # my $line = <$fh>;
349 # if (defined $line) {
350 # $self->{'_mode'} = 'r';
351 # ...
352 # It did not work well either because <> returns undef, i.e. querying the
353 # mode() after having read an entire file returned 'w'.
354  
355 58 ▶ if ( $arg{-force} || not exists $self->{'_mode'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg{"-force"} or not exists $self->{"_mode"}) 20 38 58
Condition66%2/3
$arg{"-force"} or not exists $self->{"_mode"}
l!l&&r!l&&!r
02038
MC/DC50%1/2
$arg{"-force"} or not exists $self->{"_mode"}
$arg{"-force"} not exists $self->{"_mode"}
Truth table66%2/3
A or not(B)
A= $arg{"-force"}B= not exists $self->{"_mode"}
ABresult
1X1
011
000
356 # Determine stream mode
357 20 my $mode;
358 20 my $fh = $self->_fh;
359 20 ▶ if (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh) { } 20 0 20
360 # use fcntl if not Windows-based
361 20 ▶ if ($^O !~ /MSWin32/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $^O =~ /MSWin32/) { } 20 0 20
362 20 ▶ my $m = fcntl($fh, F_GETFL, 0) || 0;
Condition50%1/2
fcntl($fh, 3, 0) || 0
l!l
200
MC/DC0%0/1
fcntl($fh, 3, 0) || 0
fcntl($fh, 3, 0)
Truth table50%1/2
A
A= fcntl($fh, 3, 0)
Aresult
11
00
363 20 ▶ $mode = exists $modes{$m & 3} ? $modes{$m & 3} : '?';
Branch: 1 branch
BranchTrueFalseTotal
exists $modes{$m & 3} ? : 20 0 20
364 } else {
365 # Determine read/write status of filehandle
366 582 ▶ no warnings 'io';
Subroutine BEGIN: called CC=1 SCAR=0.0
367 0 ▶ if ( defined( read $fh, my $content, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined read($fh, my $content, 0)) 0 0 0
368 # Successfully read 0 bytes
369 0 $mode = 'r'
370 }
371 0 ▶ if ( defined( syswrite $fh, '') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined syswrite($fh, "")) 0 0 0
372 # Successfully wrote 0 bytes
373 0 ▶ $mode ||= '';
Condition0%0/2
$mode ||= ""
l!l
00
MC/DC0%0/1
$mode ||= ""
$mode
Truth table0%0/2
A
A= $mode
Aresult
11
00
374 0 $mode .= 'w';
375 }
376 }
377 } else {
378 # Stream does not have a filehandle... cannot determine mode
379 0 $mode = '?';
380 }
381 # Save mode for future use
382 20 $self->{'_mode'} = $mode;
383 }
384 58 return $self->{'_mode'};
385 }
386  
387  
388 =head2 file
389  
390 Title : file
391 Usage : $io->file('>'.$file);
392 my $file = $io->file;
393 Function: Get or set the name of the file to read or write.
394 Args : Optional file name (including its mode, e.g. '<' for reading or '>'
395 for writing)
396 Returns : A string representing the filename and its mode.
397  
398 =cut
399  
400 1032 ▶sub file {
Subroutine file: called CC=2 SCAR=7.0
Pod documented
401 1032 my ($self, $value) = @_;
402 1032 ▶ if ( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1032 0 1032
403 1032 $self->{'_file'} = $value;
404 }
405 1032 return $self->{'_file'};
406 }
407  
408  
409 =head2 cleanfile
410  
411 Title : cleanfile
412 Usage : my ($mode, $file) = $io->cleanfile;
413 Function: Get the name of the file to read or write, stripped of its mode
414 ('>', '<', '+>', '>>', etc).
415 Args : None
416 Returns : In array context, an array of the mode and the clean filename.
417  
418 =cut
419  
420 1032 ▶sub cleanfile {
Subroutine cleanfile: called CC=1 SCAR=0.0
Pod documented
421 1032 my ($self) = @_;
422 1032 return ($self->{'_file'} =~ m/^ (\+?[><]{1,2})?\s*(.*) $/x);
423 }
424  
425  
426 =head2 format
427  
428 Title : format
429 Usage : $io->format($newval)
430 Function: Get the format of a Bio::Root::IO sequence file or filehandle. Every
431 object inheriting Bio::Root::IO is guaranteed to have a format.
432 Args : None
433 Returns : Format of the file or filehandle, e.g. fasta, fastq, genbank, embl.
434  
435 =cut
436  
437 12 ▶sub format {
Subroutine format: called CC=1 SCAR=0.0
Pod documented
438 12 my ($self) = @_;
439 12 my $format = (split '::', ref($self))[-1];
440 12 return $format;
441 }
442  
443  
444 =head2 variant
445  
446 Title : format
447 Usage : $io->format($newval)
448 Function: Get the variant of a Bio::Root::IO sequence file or filehandle.
449 The format variant depends on the specific format used. Note that
450 not all formats have variants. Also, the Bio::Root::IO-implementing
451 modules that require access to variants need to define a global hash
452 that has the allowed variants as its keys.
453 Args : None
454 Returns : Variant of the file or filehandle, e.g. sanger, solexa or illumina for
455 the fastq format, or undef for formats that do not have variants.
456  
457 =cut
458  
459 68633 ▶sub variant {
Subroutine variant: called CC=4 SCAR=14.4
Pod documented
460 68633 my ($self, $variant) = @_;
461 68633 ▶ if (defined $variant) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $variant) 47 68586 68633
462 47 $variant = lc $variant;
463 47 my $var_name = '%'.ref($self).'::variant';
464 47 my %ok_variants = eval $var_name; # e.g. %Bio::Assembly::IO::ace::variant
465 47 ▶ if (scalar keys %ok_variants == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %ok_variants == 0) 0 47 47
466 0 $self->throw("Could not validate variant because global variant ".
467 "$var_name was not set or was empty\n");
468 }
469 47 ▶ if (not exists $ok_variants{$variant}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ok_variants{$variant}) 0 47 47
470 0 $self->throw("$variant is not a valid variant of the " .
471 $self->format . ' format');
472 }
473 47 $self->{variant} = $variant;
474 }
475 68633 return $self->{variant};
476 }
477  
478  
479 =head2 _print
480  
481 Title : _print
482 Usage : $io->_print(@lines)
483 Function: Print lines of text to the IO stream object.
484 Args : List of strings to print
485 Returns : True on success, undef on failure
486  
487 =cut
488  
489 45585 ▶sub _print {
Subroutine _print: called CC=2 SCAR=7.0
490 45585 my $self = shift;
491 45585 ▶ my $fh = $self->_fh() || \*STDOUT;
Condition50%1/2
$self->_fh || \*STDOUT
l!l
455850
MC/DC0%0/1
$self->_fh || \*STDOUT
$self->_fh
Truth table50%1/2
A
A= $self->_fh
Aresult
11
00
492 45585 my $ret = print $fh @_;
493 45585 return $ret;
494 }
495  
496  
497 =head2 _insert
498  
499 Title : _insert
500 Usage : $io->_insert($string,1)
501 Function: Insert some text in a file at the given line number (1-based).
502 Args : * string to write in file
503 * line number to insert the string at
504 Returns : True
505  
506 =cut
507  
508 0 ▶sub _insert {
Subroutine _insert: not called CC=14 SCAR=53.5
509 0 my ($self, $string, $line_num) = @_;
510 # Line number check
511 0 ▶ if ($line_num < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_num < 1) 0 0 0
512 0 $self->throw("Could not insert text at line $line_num: the minimum ".
513 "line number possible is 1.");
514 }
515 # File check
516 0 my ($mode, $file) = $self->cleanfile;
517 0 ▶ if (not defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
518 0 $self->throw('Could not insert a line: IO object was initialized with '.
519 'something else than a file.');
520 }
521 # Everything that needs to be written is written before we read it
522 0 $self->flush;
523  
524 # Edit the file line by line (no slurping)
525 0 $self->close;
526 0 my $temp_file;
527 0 my $number = 0;
528 0 ▶ while (-e "$file.$number.temp") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$file.$number.temp") 0 0 0
529 0 $number++;
530 }
531 0 $temp_file = "$file.$number.temp";
532 0 copy($file, $temp_file);
533 0 ▶ open my $fh1, '<', $temp_file or $self->throw("Could not read temporary file '$temp_file': $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh1, "<", $temp_file or $self->throw("Could not read temporary file '${temp_file}': $!") 0 0 0
534 0 ▶ open my $fh2, '>', $file or $self->throw("Could not write file '$file': $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh2, ">", $file or $self->throw("Could not write file '${file}': $!") 0 0 0
535 0 ▶ while (my $line = <$fh1>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh1)) 0 0 0
536 0 ▶ if ($. == $line_num) { # right line for new data
Branch: 1 branch
BranchTrueFalseTotal
if ($. == $line_num) { } 0 0 0
537 0 print $fh2 $string . $line;
538 }
539 else {
540 0 print $fh2 $line;
541 }
542 }
543 0 CORE::close $fh1;
544 0 CORE::close $fh2;
545 0 ▶ unlink $temp_file or $self->throw("Could not delete temporary file '$temp_file': $!");
Branch: 1 branch
BranchTrueFalseTotal
unlink $temp_file or $self->throw("Could not delete temporary file '${temp_file}': $!") 0 0 0
546  
547 # Line number check (again)
548 0 ▶ if ( $. > 0 && $line_num > $. ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($. > 0 and $line_num > $.) 0 0 0
Condition0%0/3
$. > 0 and $line_num > $.
!ll&&!rl&&r
000
MC/DC0%0/2
$. > 0 and $line_num > $.
$. > 0 $line_num > $.
Truth table0%0/3
A and B
A= $. > 0B= $line_num > $.
ABresult
0X0
100
111
549 0 $self->throw("Could not insert text at line $line_num: there are only ".
550 "$. lines in file '$file'");
551 }
552 # Re-open the file in append mode to be ready to add text at the end of it
553 # when the next _print() statement comes
554 0 ▶ open my $new_fh, '>>', $file or $self->throw("Could not append to file '$file': $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $new_fh, ">>", $file or $self->throw("Could not append to file '${file}': $!") 0 0 0
555 0 $self->_fh($new_fh);
556 # If file is empty and we're inserting at line 1, simply append text to file
557 0 ▶ if ( $. == 0 && $line_num == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($. == 0 and $line_num == 1) 0 0 0
Condition0%0/3
$. == 0 and $line_num == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$. == 0 and $line_num == 1
$. == 0 $line_num == 1
Truth table0%0/3
A and B
A= $. == 0B= $line_num == 1
ABresult
0X0
100
111
558 0 $self->_print($string);
559 }
560 0 return 1;
561 }
562  
563  
564 =head2 _readline
565  
566 Title : _readline
567 Usage : local $Bio::Root::IO::HAS_EOL = 1;
568 my $io = Bio::Root::IO->new(-file => 'data.txt');
569 my $line = $io->_readline();
570 $io->close;
571 Function: Read a line of input and normalize all end of line characters.
572  
573 End of line characters are typically "\n" on Linux platforms, "\r\n"
574 on Windows and "\r" on older Mac OS. By default, the _readline()
575 method uses the value of $/, Perl's input record separator, to
576 detect the end of each line. This means that you will not get the
577 expected lines if your input has Mac-formatted end of line characters.
578 Also, note that the current implementation does not handle pushed
579 back input correctly unless the pushed back input ends with the
580 value of $/. For each line parsed, its line ending, e.g. "\r\n" is
581 converted to "\n", unless you provide the -raw argument.
582  
583 Altogether it is easier to let the PerlIO::eol module automatically
584 detect the proper end of line character and normalize it to "\n". Do
585 so by setting $Bio::Root::IO::HAS_EOL to 1.
586  
587 Args : -raw : Avoid converting end of line characters to "\n" This option
588 has no effect when using $Bio::Root::IO::HAS_EOL = 1.
589 Returns : Line of input, or undef when there is nothing to read anymore
590  
591 =cut
592  
593 338726 ▶sub _readline {
Subroutine _readline: called CC=8 SCAR=20.8
594 338726 my ($self, %param) = @_;
595 338726 ▶ my $fh = $self->_fh or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fh = $self->_fh or return 338716 10 338726
596 338716 my $line;
597  
598 # if the buffer been filled by _pushback then return the buffer
599 # contents, rather than read from the filehandle
600 338716 ▶ if( @{$self->{'_readbuffer'} || [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'_readbuffer'} or [];}) { } 929 337787 338716
Condition100%2/2
$self->{'_readbuffer'} || []
l!l
114609224107
MC/DC100%1/1
$self->{'_readbuffer'} || []
$self->{'_readbuffer'}
Truth table100%2/2
A
A= $self->{'_readbuffer'}
Aresult
11
00
601 929 $line = shift @{$self->{'_readbuffer'}};
602 } else {
603 337787 $line = <$fh>;
604 }
605  
606 # Note: In Windows the "-raw" parameter has no effect, because Perl already discards
607 # the '\r' from the line when reading in text mode from the filehandle
608 # ($line = <$fh>), and put it back automatically when printing
609 338716 ▶ if( !$HAS_EOL && !$param{-raw} && (defined $line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $Bio::Root::IO::HAS_EOL || $param{"-raw"} and defined $line) 338218 498 338716
Condition83%5/6
not $Bio::Root::IO::HAS_EOL || $param{"-raw"} and defined $line
!ll&&!rl&&r
6492338218
$Bio::Root::IO::HAS_EOL || $param{'-raw'}
l!l&&r!l&&!r
06338710
MC/DC66%2/3
not $Bio::Root::IO::HAS_EOL || $param{"-raw"} and defined $line
$Bio::Root::IO::HAS_EOL $param{'-raw'} defined $line
Truth table75%3/4
not(A || B) and C
A= $Bio::Root::IO::HAS_EOLB= $param{'-raw'}C= defined $line
ABCresult
1XX0
01X0
0000
0011
610 # don't strip line endings if -raw or $HAS_EOL is specified
611 338218 $line =~ s/\015\012/\012/g; # Change all CR/LF pairs to LF
612 338218 ▶ $line =~ tr/\015/\n/ unless $ONMAC; # Change all single CRs to NEWLINE
Branch: 1 branch
BranchTrueFalseTotal
unless $Bio::Root::IO::ONMAC 338218 0 338218
613 }
614 338716 return $line;
615 }
616  
617  
618 =head2 _pushback
619  
620 Title : _pushback
621 Usage : $io->_pushback($newvalue)
622 Function: Puts a line previously read with _readline back into a buffer.
623 buffer can hold as many lines as system memory permits.
624  
625 Note that this is only supported for pushing back data ending with
626 the current, localized value of $/. Using this method to push
627 modified data back onto the buffer stack is not supported; see bug
628 843.
629  
630 Args : newvalue
631 Returns : True
632  
633 =cut
634  
635 # fix for bug 843, this reveals some unsupported behavior
636  
637 #sub _pushback {
638 # my ($self, $value) = @_;
639 # if (index($value, $/) >= 0) {
640 # push @{$self->{'_readbuffer'}}, $value;
641 # } else {
642 # $self->throw("Pushing modifed data back not supported: $value");
643 # }
644 #}
645  
646 946 ▶sub _pushback {
Subroutine _pushback: called CC=2 SCAR=6.9
647 946 my ($self, $value) = @_;
648 946 ▶ return unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 2 944 946
649 944 unshift @{$self->{'_readbuffer'}}, $value;
650 944 return 1;
651 }
652  
653  
654 =head2 close
655  
656 Title : close
657 Usage : $io->close()
658 Function: Closes the file handle associated with this IO instance,
659 excepted if -noclose was specified.
660 Args : None
661 Returns : True
662  
663 =cut
664  
665 5464 ▶sub close {
Subroutine close: called CC=9 SCAR=22.1
Pod documented
666 5464 my ($self) = @_;
667  
668 # do not close if we explicitly asked not to
669 5464 ▶ return if $self->noclose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->noclose 49 5415 5464
670  
671 5415 ▶ if( defined( my $fh = $self->{'_filehandle'} )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $fh = $self->{"_filehandle"})) 1112 4303 5415
672 1112 $self->flush;
673 1112 ▶ return if ref $fh eq 'GLOB' && (
Branch: 1 branch
BranchTrueFalseTotal
if ref $fh eq "GLOB" and \*STDOUT == $fh || \*STDERR == $fh || \*STDIN == $fh 1 1111 1112
Condition77%7/9
ref $fh eq "GLOB" and \*STDOUT == $fh || \*STDERR == $fh || \*STDIN == $fh
!ll&&!rl&&r
5410571
\*STDOUT == $fh or \*STDERR == $fh or \*STDIN == $fh
l!l&&r!l&&!r
101057
\*STDOUT == $fh or \*STDERR == $fh
l!l&&r!l&&!r
101057
MC/DC50%2/4
ref $fh eq "GLOB" and \*STDOUT == $fh || \*STDERR == $fh || \*STDIN == $fh
ref $fh eq "GLOB" \*STDOUT == $fh \*STDERR == $fh \*STDIN == $fh
Truth table60%3/5
A and B or C or D
A= ref $fh eq "GLOB"B= \*STDOUT == $fhC= \*STDERR == $fhD= \*STDIN == $fh
ABCDresult
0XXX0
10000
11XX1
101X1
10011
674 \*STDOUT == $fh || \*STDERR == $fh || \*STDIN == $fh
675 );
676  
677 # don't close IO::Strings
678 1111 ▶ CORE::close $fh unless ref $fh && $fh->isa('IO::String');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fh and $fh->isa("IO::String") 1057 54 1111
Condition66%2/3
ref $fh and $fh->isa("IO::String")
!ll&&!rl&&r
0105754
MC/DC50%1/2
ref $fh and $fh->isa("IO::String")
ref $fh $fh->isa("IO::String")
Truth table66%2/3
A and B
A= ref $fhB= $fh->isa("IO::String")
ABresult
0X0
100
111
679 }
680 5414 $self->{'_filehandle'} = undef;
681 5414 delete $self->{'_readbuffer'};
682 5414 return 1;
683 }
684  
685  
686 =head2 flush
687  
688 Title : flush
689 Usage : $io->flush()
690 Function: Flushes the filehandle
691 Args : None
692 Returns : True
693  
694 =cut
695  
696 1299 ▶sub flush {
Subroutine flush: called CC=3 SCAR=11.1
Pod documented
697 1299 my ($self) = shift;
698  
699 1299 ▶ if( !defined $self->{'_filehandle'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_filehandle"}) 0 1299 1299
700 0 $self->throw("Flush failed: no filehandle was active");
701 }
702  
703 1299 ▶ if( ref($self->{'_filehandle'}) =~ /GLOB/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($self->{'_filehandle'}) =~ /GLOB/) { } 1234 65 1299
704 1234 my $oldh = select($self->{'_filehandle'});
705 1234 $| = 1;
706 1234 select($oldh);
707 } else {
708 65 $self->{'_filehandle'}->flush();
709 }
710 1299 return 1;
711 }
712  
713  
714 =head2 noclose
715  
716 Title : noclose
717 Usage : $io->noclose($newval)
718 Function: Get or set the NOCLOSE flag - setting this to true will prevent a
719 filehandle from being closed when an object is cleaned up or
720 explicitly closed.
721 Args : Optional new value (a scalar or undef)
722 Returns : Value of noclose (a scalar)
723  
724 =cut
725  
726 5497 ▶sub noclose {
Subroutine noclose: called CC=2 SCAR=6.9
Pod documented
727 5497 my $self = shift;
728 5497 ▶ return $self->{'_noclose'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 33 5464 5497
729 5464 return $self->{'_noclose'};
730 }
731  
732  
733 =head2 _io_cleanup
734  
735 =cut
736  
737 4093 ▶sub _io_cleanup {
Subroutine _io_cleanup: called CC=10 SCAR=30.7
738 4093 my ($self) = @_;
739 4093 $self->close();
740 4093 my $v = $self->verbose;
741  
742 # we are planning to cleanup temp files no matter what
743 4093 ▶ if ( exists($self->{'_rootio_tempfiles'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_rootio_tempfiles"} and ref($self->{"_rootio_tempfiles"}) =~ /array/i and not $self->save_tempfiles) 32 4061 4093
Condition66%4/6
exists $self->{"_rootio_tempfiles"} and ref($self->{"_rootio_tempfiles"}) =~ /array/i and not $self->save_tempfiles
!ll&&!rl&&r
4061032
exists $self->{"_rootio_tempfiles"} and ref($self->{"_rootio_tempfiles"}) =~ /array/i
!ll&&!rl&&r
4061032
MC/DC33%1/3
exists $self->{"_rootio_tempfiles"} and ref($self->{"_rootio_tempfiles"}) =~ /array/i and not $self->save_tempfiles
exists $self->{"_rootio_tempfiles"} ref($self->{"_rootio_tempfiles"}) =~ /array/i not $self->save_tempfiles
Truth table50%2/4
A and B and not(C)
A= exists $self->{"_rootio_tempfiles"}B= ref($self->{"_rootio_tempfiles"}) =~ /array/iC= not $self->save_tempfiles
ABCresult
0XX0
10X0
1100
1111
744 and ref($self->{'_rootio_tempfiles'}) =~ /array/i
745 and not $self->save_tempfiles
746 ) {
747 32 ▶ if( $v > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v > 0) 0 32 32
748 warn( "going to remove files ",
749 0 join(",", @{$self->{'_rootio_tempfiles'}}),
750 "\n");
751 }
752 32 unlink (@{$self->{'_rootio_tempfiles'}} );
753 }
754 # cleanup if we are not using File::Temp
755 4093 ▶ if ( $self->{'_cleanuptempdir'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_cleanuptempdir"} and exists $self->{"_rootio_tempdirs"} and ref($self->{"_rootio_tempdirs"}) =~ /array/i and not $self->save_tempfiles) 0 4093 4093
Condition33%3/9
$self->{"_cleanuptempdir"} and exists $self->{"_rootio_tempdirs"} and ref($self->{"_rootio_tempdirs"}) =~ /array/i and not $self->save_tempfiles
!ll&&!rl&&r
409300
$self->{"_cleanuptempdir"} and exists $self->{"_rootio_tempdirs"} and ref($self->{"_rootio_tempdirs"}) =~ /array/i
!ll&&!rl&&r
409300
$self->{"_cleanuptempdir"} and exists $self->{"_rootio_tempdirs"}
!ll&&!rl&&r
409300
MC/DC0%0/4
$self->{"_cleanuptempdir"} and exists $self->{"_rootio_tempdirs"} and ref($self->{"_rootio_tempdirs"}) =~ /array/i and not $self->save_tempfiles
$self->{"_cleanuptempdir"} exists $self->{"_rootio_tempdirs"} ref($self->{"_rootio_tempdirs"}) =~ /array/i not $self->save_tempfiles
Truth table20%1/5
A and B and C and not(D)
A= $self->{"_cleanuptempdir"}B= exists $self->{"_rootio_tempdirs"}C= ref($self->{"_rootio_tempdirs"}) =~ /array/iD= not $self->save_tempfiles
ABCDresult
0XXX0
10XX0
110X0
11100
11111
756 and exists($self->{'_rootio_tempdirs'})
757 and ref($self->{'_rootio_tempdirs'}) =~ /array/i
758 and not $self->save_tempfiles
759 ) {
760 0 ▶ if( $v > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v > 0) 0 0 0
761 warn( "going to remove dirs ",
762 0 join(",", @{$self->{'_rootio_tempdirs'}}),
763 "\n");
764 }
765 0 $self->rmtree( $self->{'_rootio_tempdirs'});
766 }
767 }
768  
769  
770 =head2 exists_exe
771  
772 Title : exists_exe
773 Usage : $exists = $io->exists_exe('clustalw');
774 $exists = Bio::Root::IO->exists_exe('clustalw')
775 $exists = Bio::Root::IO::exists_exe('clustalw')
776 Function: Determines whether the given executable exists either as file
777 or within the path environment. The latter requires File::Spec
778 to be installed.
779 On Win32-based system, .exe is automatically appended to the program
780 name unless the program name already ends in .exe.
781 Args : Name of the executable
782 Returns : 1 if the given program is callable as an executable, and 0 otherwise
783  
784 =cut
785  
786 0 ▶sub exists_exe {
Subroutine exists_exe: not called CC=12 SCAR=50.5
Pod documented
787 0 my ($self, $exe) = @_;
788 0 ▶ $self->throw("Must pass a defined value to exists_exe") unless defined $exe;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $exe 0 0 0
789 0 ▶ $exe = $self if (!(ref($self) || $exe));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self or $exe 0 0 0
Condition0%0/3
ref $self or $exe
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self or $exe
ref $self $exe
Truth table0%0/3
A or B
A= ref $selfB= $exe
ABresult
1X1
011
000
790 0 ▶ $exe .= '.exe' if(($^O =~ /mswin/i) && ($exe !~ /\.(exe|com|bat|cmd)$/i));
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /mswin/i and not $exe =~ /\.(exe|com|bat|cmd)$/i 0 0 0
Condition0%0/3
$^O =~ /mswin/i and not $exe =~ /\.(exe|com|bat|cmd)$/i
!ll&&!rl&&r
000
MC/DC0%0/2
$^O =~ /mswin/i and not $exe =~ /\.(exe|com|bat|cmd)$/i
$^O =~ /mswin/i not $exe =~ /\.(exe|com|bat|cmd)$/i
Truth table0%0/3
A and not(B)
A= $^O =~ /mswin/iB= not $exe =~ /\.(exe|com|bat|cmd)$/i
ABresult
0X0
100
111
791 0 ▶ return $exe if ( -f $exe && -x $exe ); # full path and exists
Branch: 1 branch
BranchTrueFalseTotal
if -f $exe and -x $exe 0 0 0
Condition0%0/3
-f $exe and -x $exe
!ll&&!rl&&r
000
MC/DC0%0/2
-f $exe and -x $exe
-f $exe -x $exe
Truth table0%0/3
A and B
A= -f $exeB= -x $exe
ABresult
0X0
100
111
792  
793 # Ewan's comment. I don't think we need this. People should not be
794 # asking for a program with a pathseparator starting it
795 # $exe =~ s/^$PATHSEP//;
796  
797 # Not a full path, or does not exist. Let's see whether it's in the path.
798 0 ▶ if($FILESPECLOADED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::Root::IO::FILESPECLOADED) 0 0 0
799 0 for my $dir (File::Spec->path()) {
800 0 my $f = Bio::Root::IO->catfile($dir, $exe);
801 0 ▶ return $f if( -f $f && -x $f );
Branch: 1 branch
BranchTrueFalseTotal
if -f $f and -x $f 0 0 0
Condition0%0/3
-f $f and -x $f
!ll&&!rl&&r
000
MC/DC0%0/2
-f $f and -x $f
-f $f -x $f
Truth table0%0/3
A and B
A= -f $fB= -x $f
ABresult
0X0
100
111
802 }
803 }
804 0 return 0;
805 }
806  
807  
808 =head2 tempfile
809  
810 Title : tempfile
811 Usage : my ($handle,$tempfile) = $io->tempfile();
812 Function: Create a temporary filename and a handle opened for reading and
813 writing.
814 Caveats: If you do not have File::Temp on your system you should
815 avoid specifying TEMPLATE and SUFFIX.
816 Args : Named parameters compatible with File::Temp: DIR (defaults to
817 $Bio::Root::IO::TEMPDIR), TEMPLATE, SUFFIX.
818 Returns : A 2-element array, consisting of temporary handle and temporary
819 file name.
820  
821 =cut
822  
823 37 ▶sub tempfile {
Subroutine tempfile: called CC=15 SCAR=34.3
Pod documented
824 37 my ($self, @args) = @_;
825 37 my ($tfh, $file);
826 37 my %params = @args;
827  
828 # map between naming with and without dash
829 37 for my $key (keys(%params)) {
830 48 ▶ if( $key =~ /^-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^-/) { } 0 48 48
831 0 my $v = $params{$key};
832 0 delete $params{$key};
833 0 $params{uc(substr($key,1))} = $v;
834 } else {
835 # this is to upper case
836 48 my $v = $params{$key};
837 48 delete $params{$key};
838 48 $params{uc($key)} = $v;
839 }
840 }
841 37 ▶ $params{'DIR'} = $TEMPDIR if(! exists($params{'DIR'}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"DIR"} 3 34 37
842 37 ▶ unless (exists $params{'UNLINK'} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{'UNLINK'} and defined $params{'UNLINK'} and not $params{'UNLINK'}) { } 4 33 37
Condition66%4/6
exists $params{"UNLINK"} and defined $params{"UNLINK"} and not $params{"UNLINK"}
!ll&&!rl&&r
3304
exists $params{"UNLINK"} and defined $params{"UNLINK"}
!ll&&!rl&&r
3304
MC/DC33%1/3
exists $params{"UNLINK"} and defined $params{"UNLINK"} and not $params{"UNLINK"}
exists $params{"UNLINK"} defined $params{"UNLINK"} not $params{"UNLINK"}
Truth table50%2/4
A and B and not(C)
A= exists $params{"UNLINK"}B= defined $params{"UNLINK"}C= not $params{"UNLINK"}
ABCresult
0XX0
10X0
1100
1111
843 defined $params{'UNLINK'} &&
844 ! $params{'UNLINK'} ) {
845 33 $params{'UNLINK'} = 1;
846 } else {
847 4 $params{'UNLINK'} = 0;
848 }
849  
850 37 ▶ if($FILETEMPLOADED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::Root::IO::FILETEMPLOADED) { } 37 0 37
851 37 ▶ if(exists($params{'TEMPLATE'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{'TEMPLATE'}) { } 4 33 37
852 4 my $template = $params{'TEMPLATE'};
853 4 delete $params{'TEMPLATE'};
854 4 ($tfh, $file) = File::Temp::tempfile($template, %params);
855 } else {
856 33 ($tfh, $file) = File::Temp::tempfile(%params);
857 }
858 } else {
859 0 my $dir = $params{'DIR'};
860 $file = $self->catfile(
861 $dir,
862 (exists($params{'TEMPLATE'}) ?
863 $params{'TEMPLATE'} :
864 0 ▶ sprintf( "%s.%s.%s", $ENV{USER} || 'unknown', $$, $TEMPCOUNTER++))
Branch: 1 branch
BranchTrueFalseTotal
exists $params{'TEMPLATE'} ? : 0 0 0
Condition0%0/2
$ENV{'USER'} || 'unknown'
l!l
00
MC/DC0%0/1
$ENV{'USER'} || 'unknown'
$ENV{'USER'}
Truth table0%0/2
A
A= $ENV{'USER'}
Aresult
11
00
865 );
866  
867 # sneakiness for getting around long filenames on Win32?
868 0 ▶ if( $HAS_WIN32 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HAS_WIN32) 0 0 0
869 0 $file = Win32::GetShortPathName($file);
870 }
871  
872 # Try to make sure this will be marked close-on-exec
873 # XXX: Win32 doesn't respect this, nor the proper fcntl,
874 # but may have O_NOINHERIT. This may or may not be in Fcntl.
875 0 local $^F = 2;
876 # Store callers umask
877 0 my $umask = umask();
878 # Set a known umaskr
879 0 umask(066);
880 # Attempt to open the file
881 0 ▶ if ( sysopen($tfh, $file, $OPENFLAGS, 0600) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysopen $tfh, $file, $Bio::Root::IO::OPENFLAGS, 384) { } 0 0 0
882 # Reset umask
883 0 umask($umask);
884 } else {
885 0 $self->throw("Could not write temporary file '$file': $!");
886 }
887 }
888  
889 37 ▶ if( $params{'UNLINK'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"UNLINK"}) 33 4 37
890 33 push @{$self->{'_rootio_tempfiles'}}, $file;
891 }
892  
893 37 ▶ return wantarray ? ($tfh,$file) : $tfh;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 37 0 37
894 }
895  
896  
897 =head2 tempdir
898  
899 Title : tempdir
900 Usage : my ($tempdir) = $io->tempdir(CLEANUP=>1);
901 Function: Creates and returns the name of a new temporary directory.
902  
903 Note that you should not use this function for obtaining "the"
904 temp directory. Use $Bio::Root::IO::TEMPDIR for that. Calling this
905 method will in fact create a new directory.
906  
907 Args : args - ( key CLEANUP ) indicates whether or not to cleanup
908 dir on object destruction, other keys as specified by File::Temp
909 Returns : The name of a new temporary directory.
910  
911 =cut
912  
913 30 ▶sub tempdir {
Subroutine tempdir: called CC=5 SCAR=27.8
Pod documented
914 30 my ($self, @args) = @_;
915 30 ▶ if ($FILETEMPLOADED && File::Temp->can('tempdir')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::Root::IO::FILETEMPLOADED and "File::Temp"->can("tempdir")) 30 0 30
Condition33%1/3
$Bio::Root::IO::FILETEMPLOADED and "File::Temp"->can("tempdir")
!ll&&!rl&&r
0030
MC/DC0%0/2
$Bio::Root::IO::FILETEMPLOADED and "File::Temp"->can("tempdir")
$Bio::Root::IO::FILETEMPLOADED "File::Temp"->can("tempdir")
Truth table33%1/3
A and B
A= $Bio::Root::IO::FILETEMPLOADEDB= "File::Temp"->can("tempdir")
ABresult
0X0
100
111
916 30 return File::Temp::tempdir(@args);
917 }
918  
919 # we have to do this ourselves, not good
920 # we are planning to cleanup temp files no matter what
921 0 my %params = @args;
922 0 print "cleanup is " . $params{CLEANUP} . "\n";
923 $self->{'_cleanuptempdir'} = ( defined $params{CLEANUP} &&
924 0 ▶ $params{CLEANUP} == 1);
Condition0%0/3
defined $params{'CLEANUP'} && $params{'CLEANUP'} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params{'CLEANUP'} && $params{'CLEANUP'} == 1
defined $params{'CLEANUP'} $params{'CLEANUP'} == 1
Truth table0%0/3
A && B
A= defined $params{'CLEANUP'}B= $params{'CLEANUP'} == 1
ABresult
0X0
100
111
925 my $tdir = $self->catfile( $TEMPDIR,
926 sprintf("dir_%s-%s-%s",
927 0 ▶ $ENV{USER} || 'unknown',
Condition0%0/2
$ENV{'USER'} || 'unknown'
l!l
00
MC/DC0%0/1
$ENV{'USER'} || 'unknown'
$ENV{'USER'}
Truth table0%0/2
A
A= $ENV{'USER'}
Aresult
11
00
928 $$,
929 $TEMPCOUNTER++));
930 0 mkdir($tdir, 0755);
931 0 push @{$self->{'_rootio_tempdirs'}}, $tdir;
932 0 return $tdir;
933 }
934  
935  
936 =head2 catfile
937  
938 Title : catfile
939 Usage : $path = Bio::Root::IO->catfile(@dirs, $filename);
940 Function: Constructs a full pathname in a cross-platform safe way.
941  
942 If File::Spec exists on your system, this routine will merely
943 delegate to it. Otherwise it tries to make a good guess.
944  
945 You should use this method whenever you construct a path name
946 from directory and filename. Otherwise you risk cross-platform
947 compatibility of your code.
948  
949 You can call this method both as a class and an instance method.
950  
951 Args : components of the pathname (directories and filename, NOT an
952 extension)
953 Returns : a string
954  
955 =cut
956  
957 3766 ▶sub catfile {
Subroutine catfile: called CC=3 SCAR=17.3
Pod documented
958 3766 my ($self, @args) = @_;
959  
960 3766 ▶ return File::Spec->catfile(@args) if $FILESPECLOADED;
Branch: 1 branch
BranchTrueFalseTotal
if $Bio::Root::IO::FILESPECLOADED 3766 0 3766
961 # this is clumsy and not very appealing, but how do we specify the
962 # root directory?
963 0 ▶ if($args[0] eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] eq "/") 0 0 0
964 0 $args[0] = $ROOTDIR;
965 }
966 0 return join($PATHSEP, @args);
967 }
968  
969  
970 =head2 rmtree
971  
972 Title : rmtree
973 Usage : Bio::Root::IO->rmtree($dirname );
974 Function: Remove a full directory tree
975  
976 If File::Path exists on your system, this routine will merely
977 delegate to it. Otherwise it runs a local version of that code.
978  
979 You should use this method to remove directories which contain
980 files.
981  
982 You can call this method both as a class and an instance method.
983  
984 Args : roots - rootdir to delete or reference to list of dirs
985  
986 verbose - a boolean value, which if TRUE will cause
987 C<rmtree> to print a message each time it
988 examines a file, giving the name of the file, and
989 indicating whether it's using C<rmdir> or
990 C<unlink> to remove it, or that it's skipping it.
991 (defaults to FALSE)
992  
993 safe - a boolean value, which if TRUE will cause C<rmtree>
994 to skip any files to which you do not have delete
995 access (if running under VMS) or write access (if
996 running under another OS). This will change in the
997 future when a criterion for 'delete permission'
998 under OSs other than VMS is settled. (defaults to
999 FALSE)
1000 Returns : number of files successfully deleted
1001  
1002 =cut
1003  
1004 # taken straight from File::Path VERSION = "1.0403"
1005 0 ▶sub rmtree {
Subroutine rmtree: not called CC=43 SCAR=75.5
Pod documented
1006 0 my ($self, $roots, $verbose, $safe) = @_;
1007 0 ▶ if ( $FILEPATHLOADED ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::Root::IO::FILEPATHLOADED) 0 0 0
1008 0 return File::Path::rmtree ($roots, $verbose, $safe);
1009 }
1010  
1011 0 ▶ my $force_writable = ($^O eq 'os2' || $^O eq 'dos' || $^O eq 'MSWin32' ||
Condition0%0/12
$^O eq 'os2' || $^O eq 'dos' || $^O eq 'MSWin32' || $^O eq 'amigaos' || $^O eq 'cygwin'
l!l&&r!l&&!r
000
$^O eq "os2" or $^O eq "dos" or $^O eq "MSWin32" or $^O eq "amigaos"
l!l&&r!l&&!r
000
$^O eq "os2" or $^O eq "dos" or $^O eq "MSWin32"
l!l&&r!l&&!r
000
$^O eq "os2" or $^O eq "dos"
l!l&&r!l&&!r
000
MC/DC0%0/5
$^O eq 'os2' || $^O eq 'dos' || $^O eq 'MSWin32' || $^O eq 'amigaos' || $^O eq 'cygwin'
$^O eq "os2" $^O eq "dos" $^O eq "MSWin32" $^O eq "amigaos" $^O eq 'cygwin'
Truth table0%0/6
A or B or C or D || E
A= $^O eq "os2"B= $^O eq "dos"C= $^O eq "MSWin32"D= $^O eq "amigaos"E= $^O eq 'cygwin'
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1012 $^O eq 'amigaos' || $^O eq 'cygwin');
1013 0 my $Is_VMS = $^O eq 'VMS';
1014  
1015 0 my @files;
1016 0 my $count = 0;
1017 0 ▶ $verbose ||= 0;
Condition0%0/2
$verbose ||= 0
l!l
00
MC/DC0%0/1
$verbose ||= 0
$verbose
Truth table0%0/2
A
A= $verbose
Aresult
11
00
1018 0 ▶ $safe ||= 0;
Condition0%0/2
$safe ||= 0
l!l
00
MC/DC0%0/1
$safe ||= 0
$safe
Truth table0%0/2
A
A= $safe
Aresult
11
00
1019 0 ▶ if ( defined($roots) && length($roots) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $roots and length $roots) { } 0 0 0
Condition0%0/3
defined $roots and length $roots
!ll&&!rl&&r
000
MC/DC0%0/2
defined $roots and length $roots
defined $roots length $roots
Truth table0%0/3
A and B
A= defined $rootsB= length $roots
ABresult
0X0
100
111
1020 0 ▶ $roots = [$roots] unless ref $roots;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $roots 0 0 0
1021 } else {
1022 0 $self->warn("No root path(s) specified\n");
1023 0 return 0;
1024 }
1025  
1026 0 my $root;
1027 0 for $root (@{$roots}) {
1028 0 $root =~ s#/\z##;
1029 0 ▶ (undef, undef, my $rp) = lstat $root or next;
Branch: 1 branch
BranchTrueFalseTotal
my(undef, undef, $rp) = lstat $root or next 0 0 0
1030 0 $rp &= 07777; # don't forget setuid, setgid, sticky bits
1031 0 ▶ if ( -d _ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d _) { } 0 0 0
1032 # notabene: 0777 is for making readable in the first place,
1033 # it's also intended to change it to writable in case we have
1034 # to recurse in which case we are better than rm -rf for
1035 # subtrees with strange permissions
1036 0 ▶ chmod(0777, ($Is_VMS ? VMS::Filespec::fileify($root) : $root))
Branch: 2 branches
BranchTrueFalseTotal
unless $safe 0 0 0
$Is_VMS ? : 0 0 0
Condition0%0/6
$safe || (chmod(0777, $Is_VMS ? VMS::Filespec::fileify($root) : $root) || $self->warn("Could not make directory '${root}' read+writable: $!"))
l!l&&r!l&&!r
000
chmod 0777, $Is_VMS ? VMS::Filespec::fileify($root) : $root or $self->warn("Could not make directory '${root}' read+writable: $!")
l!l&&r!l&&!r
000
MC/DC0%0/3
$safe || (chmod(0777, $Is_VMS ? VMS::Filespec::fileify($root) : $root) || $self->warn("Could not make directory '${root}' read+writable: $!"))
$safe chmod 0777, $Is_VMS ? VMS::Filespec::fileify($root) : $root $self->warn("Could not make directory '${root}' read+writable: $!")
Truth table0%0/4
A || B or C
A= $safeB= chmod 0777, $Is_VMS ? VMS::Filespec::fileify($root) : $rootC= $self->warn("Could not make directory '${root}' read+writable: $!")
ABCresult
1XX1
01X1
0011
0000
1037 or $self->warn("Could not make directory '$root' read+writable: $!")
1038 unless $safe;
1039 0 ▶ if (opendir DIR, $root){
Branch: 1 branch
BranchTrueFalseTotal
if (opendir DIR, $root) { } 0 0 0
1040 0 @files = readdir DIR;
1041 0 closedir DIR;
1042 } else {
1043 0 $self->warn("Could not read directory '$root': $!");
1044 0 @files = ();
1045 }
1046  
1047 # Deleting large numbers of files from VMS Files-11 filesystems
1048 # is faster if done in reverse ASCIIbetical order
1049 0 ▶ @files = reverse @files if $Is_VMS;
Branch: 1 branch
BranchTrueFalseTotal
if $Is_VMS 0 0 0
1050 0 ▶ ($root = VMS::Filespec::unixify($root)) =~ s#\.dir\z## if $Is_VMS;
Branch: 1 branch
BranchTrueFalseTotal
if $Is_VMS 0 0 0
1051 0 @files = map("$root/$_", grep $_!~/^\.{1,2}\z/s,@files);
1052 0 $count += $self->rmtree([@files],$verbose,$safe);
1053 0 ▶ if ($safe &&
Branch: 2 branches
BranchTrueFalseTotal
if ($safe and $Is_VMS ? !&VMS::Filespec::candelete($root) : !(-w $root)) 0 0 0
$Is_VMS ? : 0 0 0
Condition0%0/3
$safe and $Is_VMS ? !&VMS::Filespec::candelete($root) : !(-w $root)
!ll&&!rl&&r
000
MC/DC0%0/2
$safe and $Is_VMS ? !&VMS::Filespec::candelete($root) : !(-w $root)
$safe $Is_VMS ? !&VMS::Filespec::candelete($root) : !(-w $root)
Truth table0%0/3
A and B
A= $safeB= $Is_VMS ? !&VMS::Filespec::candelete($root) : !(-w $root)
ABresult
0X0
100
111
1054 ($Is_VMS ? !&VMS::Filespec::candelete($root) : !-w $root)) {
1055 0 ▶ print "skipped '$root'\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1056 0 next;
1057 }
1058 0 ▶ chmod 0777, $root
Branch: 1 branch
BranchTrueFalseTotal
if $force_writable 0 0 0
Condition0%0/6
$force_writable && (chmod(0777, $root) || $self->warn("Could not make directory '${root}' writable: $!"))
!ll&&!rl&&r
000
chmod 0777, $root or $self->warn("Could not make directory '${root}' writable: $!")
l!l&&r!l&&!r
000
MC/DC0%0/3
$force_writable && (chmod(0777, $root) || $self->warn("Could not make directory '${root}' writable: $!"))
$force_writable chmod 0777, $root $self->warn("Could not make directory '${root}' writable: $!")
Truth table0%0/4
A && B or C
A= $force_writableB= chmod 0777, $rootC= $self->warn("Could not make directory '${root}' writable: $!")
ABCresult
0XX0
1000
11X1
1011
1059 or $self->warn("Could not make directory '$root' writable: $!")
1060 if $force_writable;
1061 0 ▶ print "rmdir '$root'\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1062 0 ▶ if (rmdir $root) {
Branch: 1 branch
BranchTrueFalseTotal
if (rmdir $root) { } 0 0 0
1063 0 ++$count;
1064 }
1065 else {
1066 0 $self->warn("Could not remove directory '$root': $!");
1067 0 ▶ chmod($rp, ($Is_VMS ? VMS::Filespec::fileify($root) : $root))
Branch: 2 branches
BranchTrueFalseTotal
chmod $rp, $Is_VMS ? VMS::Filespec::fileify($root) : $root or $self->warn(q[and can't restore permissions to ] . sprintf("0%o", $rp) . "\n") 0 0 0
$Is_VMS ? : 0 0 0
1068 or $self->warn("and can't restore permissions to "
1069 . sprintf("0%o",$rp) . "\n");
1070 }
1071 }
1072 else {
1073 0 ▶ if ( $safe
Branch: 2 branches
BranchTrueFalseTotal
if ($safe and $Is_VMS ? !&VMS::Filespec::candelete($root) : !(-l $root || -w $root)) 0 0 0
$Is_VMS ? : 0 0 0
Condition0%0/6
$safe and $Is_VMS ? !&VMS::Filespec::candelete($root) : !(-l $root || -w $root)
!ll&&!rl&&r
000
-l $root || -w $root
l!l&&r!l&&!r
000
MC/DC0%0/2
$safe and $Is_VMS ? !&VMS::Filespec::candelete($root) : !(-l $root || -w $root)
$safe $Is_VMS ? !&VMS::Filespec::candelete($root) : !(-l $root || -w $root)
MC/DC0%0/2
-l $root || -w $root
-l $root -w $root
Truth table0%0/3
A and B
A= $safeB= $Is_VMS ? !&VMS::Filespec::candelete($root) : !(-l $root || -w $root)
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= -l $rootB= -w $root
ABresult
1X1
011
000
1074 and ($Is_VMS ? !&VMS::Filespec::candelete($root)
1075 : !(-l $root || -w $root))
1076 ) {
1077 0 ▶ print "skipped '$root'\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1078 0 next;
1079 }
1080 0 ▶ chmod 0666, $root
Branch: 1 branch
BranchTrueFalseTotal
if $force_writable 0 0 0
Condition0%0/6
$force_writable && (chmod(0666, $root) || $self->warn("Could not make file '${root}' writable: $!"))
!ll&&!rl&&r
000
chmod 0666, $root or $self->warn("Could not make file '${root}' writable: $!")
l!l&&r!l&&!r
000
MC/DC0%0/3
$force_writable && (chmod(0666, $root) || $self->warn("Could not make file '${root}' writable: $!"))
$force_writable chmod 0666, $root $self->warn("Could not make file '${root}' writable: $!")
Truth table0%0/4
A && B or C
A= $force_writableB= chmod 0666, $rootC= $self->warn("Could not make file '${root}' writable: $!")
ABCresult
0XX0
1000
11X1
1011
1081 or $self->warn( "Could not make file '$root' writable: $!")
1082 if $force_writable;
1083 0 ▶ warn "unlink '$root'\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1084 # delete all versions under VMS
1085 0 for (;;) {
1086 0 ▶ unless (unlink $root) {
Branch: 1 branch
BranchTrueFalseTotal
unless (unlink $root) 0 0 0
1087 0 $self->warn("Could not unlink file '$root': $!");
1088 0 ▶ if ($force_writable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($force_writable) 0 0 0
1089 0 ▶ chmod $rp, $root
Branch: 1 branch
BranchTrueFalseTotal
chmod $rp, $root or $self->warn(q[and can't restore permissions to ] . sprintf("0%o", $rp) . "\n") 0 0 0
1090 or $self->warn("and can't restore permissions to "
1091 . sprintf("0%o",$rp) . "\n");
1092 }
1093 0 last;
1094 }
1095 0 ++$count;
1096 0 ▶ last unless $Is_VMS && lstat $root;
Branch: 1 branch
BranchTrueFalseTotal
unless $Is_VMS and lstat $root 0 0 0
Condition0%0/3
$Is_VMS and lstat $root
!ll&&!rl&&r
000
MC/DC0%0/2
$Is_VMS and lstat $root
$Is_VMS lstat $root
Truth table0%0/3
A and B
A= $Is_VMSB= lstat $root
ABresult
0X0
100
111
1097 }
1098 }
1099 }
1100  
1101 0 return $count;
1102 }
1103  
1104  
1105 =head2 _flush_on_write
1106  
1107 Title : _flush_on_write
1108 Usage : $io->_flush_on_write($newval)
1109 Function: Boolean flag to indicate whether to flush
1110 the filehandle on writing when the end of
1111 a component is finished (Sequences, Alignments, etc)
1112 Args : Optional new value
1113 Returns : Value of _flush_on_write
1114  
1115 =cut
1116  
1117 5209 ▶sub _flush_on_write {
Subroutine _flush_on_write: called CC=2 SCAR=6.9
1118 5209 my ($self, $value) = @_;
1119 5209 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 5022 187 5209
1120 5022 $self->{'_flush_on_write'} = $value;
1121 }
1122 5209 return $self->{'_flush_on_write'};
1123 }
1124  
1125  
1126 =head2 save_tempfiles
1127  
1128 Title : save_tempfiles
1129 Usage : $io->save_tempfiles(1)
1130 Function: Boolean flag to indicate whether to retain tempfiles/tempdir
1131 Args : Value evaluating to TRUE or FALSE
1132 Returns : Boolean value : 1 = save tempfiles/tempdirs, 0 = remove (default)
1133  
1134 =cut
1135  
1136 32 ▶sub save_tempfiles {
Subroutine save_tempfiles: called CC=4 SCAR=18.9
Pod documented
1137 32 my $self = shift;
1138 32 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 32 32
1139 0 my $value = shift;
1140 0 ▶ $self->{save_tempfiles} = $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
1141 }
1142 32 ▶ return $self->{save_tempfiles} || 0;
Condition50%1/2
$self->{'save_tempfiles'} || 0
l!l
032
MC/DC0%0/1
$self->{'save_tempfiles'} || 0
$self->{'save_tempfiles'}
Truth table50%1/2
A
A= $self->{'save_tempfiles'}
Aresult
11
00
1143 }
1144  
1145  
1146 582 1;
« Bio/OntologyIO/Handlers/InterProHandler.pm ↑ Summary Bio/AlignIO/proda.pm »