develooper Front page | perl.macperl.porters | Postings from December 2002

Re: Mac::MoreFiles breaks @INC (MacPerl 5.6.1)

From:
Chris Nandor
Date:
December 1, 2002 18:50
Subject:
Re: Mac::MoreFiles breaks @INC (MacPerl 5.6.1)
Message ID:
pudge-7D52AD.21501101122002@onion.valueclick.com
In article <3C21526B-0456-11D7-8C39-003065F6D85A@mathforum.org>,
 ken@mathforum.org (Ken Williams) wrote:

> Using MacPerl 5.6.1 under Classic (not Mac OS X perl), I've noticed that 
> loading Mac::MoreFiles alters @INC, as the following script demonstrates:
> 
> ----------- script ------------
>    use lib qw(lib);
>    print "Before, \@INC:\n", map " * $ \n", @INC;
>    eval 'use Mac::MoreFiles';
>    print "After, \@INC:\n", map " * $ \n", @INC;

It really could be any module that uses DynaLoader, it has nothing to do 
with Mac::MoreFiles (and as such, I've set followups to macperl-porters).

> ----------- output ------------
>    Before, @INC:
>     * lib
>     * Junior:Applications (Mac OS 9):MacPerl Ÿ:lib:MacPPC:
>     * Junior:Applications (Mac OS 9):MacPerl Ÿ:lib:
>     * Junior:Applications (Mac OS 9):MacPerl Ÿ:site perl:
>     * :
>     * Dev:Pseudo:
>    After, @INC:
>     * lib:
>     * Junior:Applications (Mac OS 9):MacPerl Ÿ:lib:MacPPC:
>     * Junior:Applications (Mac OS 9):MacPerl Ÿ:lib:
>     * Junior:Applications (Mac OS 9):MacPerl Ÿ:site perl:
>     * :
>     * Dev:Pseudo:
> -------------------------------
> 
> That "lib:" is a problem, because it refers to the root level directory 
> of a volume called "lib", not a directory called "lib" relative to the 
> current directory.

Then you really should use lib ':lib' or ':lib:', not 'lib'.  Here's the 
offending code of DynaLoader.pm:

    foreach (@INC) {
      # ...
      my $dir;
      if ($Is_MacOS) {
          $_ .= ":"  unless /:$/;
          $dir = "${_}auto:$modpname";
      }

This demonstrates the problem with using "lib".  You would end up with a 
$dir like "lib:auto:Mac:MoreFiles:", which is an illegal path unless lib 
*is* a volume name.

In 5.8, it is different:

    foreach (@INC) {
      # ...
      my $dir;
      if ($Is_MacOS) {
          my $path = $_;
          if ($Mac_FS && ! -d $path) {
            $path = Mac::FileSpec::Unixish::nativize($path);
          }
          $path .= ":"  unless /:$/;
          $dir = "${path}auto:$modpname";
      }

So there are a few changes here.  One is that we don't modify @INC, and the 
other is that we try to handle Unix paths if the existing path doesn't 
exist.  This would also change "lib" to ":lib" if "lib" didn't exist (which 
I suppose isn't very useful, but it's an interesting side note).

There are also other changes for lib.pm (similar to the change to 
DynaLoader.pm) and path handling in perl.c, for perl 5.8.


> What I really need is a way to do "use lib qw(:lib:);" in a 
> cross-platform way, and apparently "use lib qw(lib);" isn't going to 
> work as well as I'd hoped with 5.6.  As a workaround, I'm doing "use lib 
> File::Spec->catdir('lib');", which seems to work.

Yes, that is the "workaround" (really, the proper approach :-) I'd 
recommend.  Of course, it fails miserably if you can't find File/Spec.pm, 
but really, if that's the case, you probably can't find lib.pm either.  You 
could also try "./lib", but that is only working in 5.8, I believe.

In any event, I'd recommend the File::Spec method, but I will consider the 
DynaLoader.pm change for 5.6.1r2 (I need to go back and see what else it 
might break, what other changes accompany it, etc.).

-- 
Chris Nandor                      pudge@pobox.com    http://pudge.net/
Open Source Development Network    pudge@osdn.com     http://osdn.com/



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About