in reply to Re^2: finding the absolute path to a module, from the module's, perspective
in thread finding the absolute path to a module, from the module's, perspective

Well it works for me. File::Spec 0.88, Cwd 2.20.

What does it print for you from the commandline?

Are you sure what you think is getting loaded is in fact getting loaded. Try appending

print "$_\n" for %INC";
Also, try just printing __FILE__

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

  • Comment on Re^3: finding the absolute path to a module, from the module's, perspective
  • Download Code

Replies are listed 'Best First'.
Re^4: finding the absolute path to a module, from the module's, perspective
by skazat (Chaplain) on Sep 12, 2004 at 05:00 UTC

    This is pretty weird, but I think I've figured it out;

    doing a,

    print __FILE__;
    inside my module will return something like:
     
    /lib/Stuff/Template.pm
    
    File::Spec has a method called, file_name_is_absolute(), which basically on Unix, looks for a '/' as the first character ->
    sub file_name_is_absolute { my ($self,$file) = @_; return scalar($file =~ m:^/:s); }

    File::Spec will consult this method before it tries to piece together a absolute path; thus, File::Spec isn't even attempting to make an absolute path from the information from __FILE__

    The workaround I've done is simply to hack the first, '/' off.

    Changing my FOO.pm to something like:

    package FOO; use File::Spec; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(bar); sub bar { print __FILE__; print '<p>'; print File::Spec->rel2abs(__FILE__) . "\n"; } 1;
    Will print:

    lib/FOO.pm

    /usr/home/user/www/cgi-bin/lib/FOO.pm

    So, it doesn't look like it's *really* File::Spec's fault, but what would cause Perl to put a '/' at the beginning of the path in my module?

    Hmm...

     

    -justin simoni
    !skazat!

      what would cause Perl to put a '/' at the beginning of the path in my module?
      chroot? mod_perl?