In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (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                      [EMAIL PROTECTED]    http://pudge.net/
Open Source Development Network    [EMAIL PROTECTED]     http://osdn.com/

Reply via email to