70
70
to one of the Bioperl mailing lists.
71
71
Your participation is much appreciated.
73
bioperl-l@bioperl.org - General discussion
74
http://bio.perl.org/MailList.html - About the mailing lists
73
bioperl-l@bioperl.org - General discussion
74
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
76
76
=head2 Reporting Bugs
78
78
Report bugs to the Bioperl bug tracking system to help us keep track
79
the bugs and their resolution.
80
Bug reports can be submitted via email or the web:
79
the bugs and their resolution. Bug reports can be submitted via the
82
bioperl-bugs@bio.perl.org
83
http://bugzilla.bioperl.org/
82
http://bugzilla.open-bio.org/
85
84
=head1 AUTHOR - Hilmar Lapp
87
86
Email hlapp@gmx.net
89
Describe contact details here
93
90
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
101
98
package Bio::Root::IO;
102
use vars qw(@ISA $FILESPECLOADED $FILETEMPLOADED $FILEPATHLOADED
103
$TEMPDIR $PATHSEP $ROOTDIR $OPENFLAGS $VERBOSE);
99
use vars qw($FILESPECLOADED $FILETEMPLOADED $FILEPATHLOADED
100
$TEMPDIR $PATHSEP $ROOTDIR $OPENFLAGS $VERBOSE $ONMAC
107
106
use POSIX qw(dup);
108
use Bio::Root::HTTPget;
111
@ISA = qw(Bio::Root::Root);
110
use base qw(Bio::Root::Root);
114
113
my $HAS_WIN32 = 0;
117
117
$TEMPCOUNTER = 0;
118
118
$FILESPECLOADED = 0;
119
119
$FILETEMPLOADED = 0;
120
120
$FILEPATHLOADED = 0;
123
123
# try to load those modules that may cause trouble on some systems
223
233
Currently recognizes the following named parameters:
224
234
-file name of file to open
235
-url name of URL to open
225
236
-input name of file, or GLOB, or IO::Handle object
226
237
-fh file handle (mutually exclusive with -file)
227
238
-flush boolean flag to autoflush after each write
239
250
$self->_register_for_cleanup(\&_io_cleanup);
241
my ($input, $noclose, $file, $fh, $flush) = $self->_rearrange([qw(INPUT
252
my ($input, $noclose, $file, $fh, $flush, $url) = $self->_rearrange([qw(INPUT
260
if($HAS_LWP){ #use LWP::Simple::getstore()
262
#$self->warn("has lwp");
264
my($handle,$tempfile) = $self->tempfile();
267
for(my $try = 1 ; $try <= $trymax ; $try++){
268
$http_result = LWP::Simple::getstore($url, $tempfile);
269
$self->warn("[$try/$trymax] tried to fetch $url, but server threw $http_result. retrying...") if $http_result != 200;
270
last if $http_result == 200;
272
$self->throw("failed to fetch $url, server threw $http_result") if $http_result != 200;
276
} else { #use Bio::Root::HTTPget
277
#$self->warn("no lwp");
279
$fh = Bio::Root::HTTPget->getFH($url);
246
283
delete $self->{'_readbuffer'};
247
284
delete $self->{'_filehandle'};
248
285
$self->noclose( $noclose) if defined $noclose;
322
359
my ($obj, @arg) = @_;
323
360
my %param = @arg;
324
361
return $obj->{'_mode'} if defined $obj->{'_mode'} and !$param{-force};
326
print STDERR "testing mode... " if $obj->verbose;
328
# we need to dup() the original filehandle because
329
# doing fdopen() calls on an already open handle causes
330
# the handle to go stale. is this going to work for non-unix
331
# filehandles? -allen
333
my $fh = Symbol::gensym();
335
my $iotest = new IO::Handle;
337
#test for a readable filehandle;
338
$iotest->fdopen( dup(fileno($obj->_fh)) , 'r' );
339
if($iotest->error == 0){
341
# note the hack here, we actually have to try to read the line
342
# and if we get something, pushback() it into the readbuffer.
343
# this is because solaris and windows xp (others?) don't set
344
# IO::Handle::error. for non-linux the r/w testing is done
345
# inside this read-test, instead of the write test below. ugh.
363
# Previous system of:
364
# my $iotest = new IO::Handle;
365
# $iotest->fdopen( dup(fileno($fh)) , 'r' );
366
# if ($iotest->error == 0) { ... }
367
# didn't actually seem to work under any platform, since there would no
368
# no error if the filehandle had been opened writable only. Couldn't be
369
# hacked around when dealing with unseekable (piped) filehandles.
371
# Just try and do a simple readline, turning io warnings off, instead:
373
my $fh = $obj->_fh || return '?';
375
no warnings "io"; # we expect a warning if this is writable only
378
$obj->_pushback($line);
348
379
$obj->{'_mode'} = 'r';
349
my $line = $iotest->getline;
350
$obj->_pushback($line) if defined $line;
351
$obj->{'_mode'} = defined $line ? 'r' : 'w';
352
return $obj->{'_mode'};
354
my $line = $iotest->getline;
355
$obj->_pushback($line) if defined $line;
356
$obj->{'_mode'} = defined $line ? 'r' : 'w';
357
return $obj->{'_mode'};
362
#test for a writeable filehandle;
363
$iotest->fdopen( dup(fileno($obj->_fh)) , 'w' );
364
if($iotest->error == 0){
365
$obj->{'_mode'} = 'w';
366
# return $obj->{'_mode'};
369
#wtf type of filehandle is this?
370
# $obj->{'_mode'} = '?';
382
$obj->{'_mode'} = 'w';
371
385
return $obj->{'_mode'};
438
453
# if the buffer been filled by _pushback then return the buffer
439
454
# contents, rather than read from the filehandle
440
$line = shift @{$self->{'_readbuffer'}} || <$fh>;
455
if( @{$self->{'_readbuffer'} || [] } ) {
456
$line = shift @{$self->{'_readbuffer'}};
442
461
#don't strip line endings if -raw is specified
443
$line =~ s/\r\n/\n/g if( (!$param{-raw}) && (defined $line) );
462
# $line =~ s/\r\n/\n/g if( (!$param{-raw}) && (defined $line) );
464
if( (!$param{-raw}) && (defined $line) ) {
465
$line =~ s/\015\012/\012/g; # Change all CR/LF pairs to LF
466
$line =~ tr/\015/\n/ unless $ONMAC; # Change all single CRs to NEWLINE