Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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 ( [id://390371]=note: print w/replies, xml ) Need Help??


in reply to Re^3: 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

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!

Replies are listed 'Best First'.
Re^5: finding the absolute path to a module, from the module's, perspective
by ysth (Canon) on Sep 12, 2004 at 06:55 UTC
    what would cause Perl to put a '/' at the beginning of the path in my module?
    chroot? mod_perl?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://390371]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (None)
    As of 2024-04-25 01:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found