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!


In reply to Re^4: finding the absolute path to a module, from the module's, perspective by skazat
in thread finding the absolute path to a module, from the module's, perspective by skazat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.