[Bioperl-l] hardcoded paths in test scripts (II)

Hilmar Lapp lapp@gnf.org
Tue, 27 Feb 2001 19:04:02 -0800

Todd Richmond wrote:
> Rooting around in the Root::IO.pm ...
>     eval {
>     require File::Spec;
>     $TEMPDIR = File::Spec->tmpdir();
>     $ROOTDIR = File::Spec->rootdir();
>     require File::Temp; # tempfile creation
>     };
> This is a bad idea for now. File::Spec works just fine on MacOS so $TEMPDIR
> and $ROOTDIR are set properly. File::Temp on the other hand, doesn't work
> and so probably shouldn't be lumped into this eval.

Shouldn't be a problem because exceptions are caught afterwards. So,
if the last require fails, the settings obtained from File::Spec
should be active and fine. The exception catch code checks what
actually failed. It's like a try {} catch, but maybe I was erroneously
assuming that it works the same way in perl as it does in C++ or Java.

> Meanwhile the fix for cross-compatibility completely broke things on a Mac
> :)
> Here's a fix for Bio::Root::IO->catfile
> sub catfile {
>     my ($self, @args) = @_;
>     if ($^O =~ /macos/i) {
>         my $file = ':'. File::Spec->catfile(@args);

So this means that even File::Spec is doing it wrong. What's the
meaning of the initial ':'? The root dir? (I somewhere read that there
is no such thing as a root dir on Macs ... :o )

>         return $file;
>     }
>     return File::Spec->catfile(@args) if(exists($INC{"File/Spec.pm"}));
>     # this is clumsy and not very appealing, but how do we specify the
>     # root directory?
>     if($args[0] eq '/') {
>     $args[0] = $ROOTDIR;
>     }
>     return join($PATHSEP, @args);
> }
> By the way, does if(exists($INC{"File/Spec.pm"})) actually work on Unix? In

It does. I actually took this from the Perl POD for 'require'. The
claim there was that this is what 'require' internally does. Maybe not
on Macs ...

> certainly doesn't work on Macs - even if you change the '/' to ':' or '::'
> I didn't worry about it because I'm pretty sure File::Spec is standard on
> MacOS.

Well, then we simply add a second variable ($FILETEMPLOADED) to
Bio::Root::IO.pm. I thought $FILESPECLOADED was already redundant, but
now I see that it's not on Macs.

Man, this beast is reluctant, but not much longer.

The nice thing about all this is that now we have a single place in
the code where all this is done. So, it should be fairly safe to even
change the code for catfile() completely (provided it works :)

As for your second mail, your code sample there actually suggests that
IO::File might be the better bet for creating tempfiles than
File::Temp. An issue might be the specification of parameters, like in
which directory to create the tempfile; and does IO::File also have a
method for creating a tempdir?

Hilmar Lapp                            email: lapp@gnf.org
GNF, San Diego, Ca. 92121              phone: +1-858-812-1757