in reply to Re: How to make a module aware of where it is installed?
in thread How to make a module aware of where it is installed?

Yes, the module structure is correct under blib/lib. The problem is the main module itself has to know what blib/lib expands to. For instance under perl 5.8 on Debian GNU/Linux,

INSTALLPRIVLIB='/usr/share/perl/5.8.0' INSTALLSITELIB='/usr/local/share/perl/5.8.0' INSTALLVENDORLIB='/usr/share/perl5'
The INSTALLDIRS variable in Makefile.PL determines which one gets used or it defaultes to site. It will translate instances of blib/lib in the Makefile itself but doesn't do that elsewhere without the PM_FILTER.

What I am doing for now is:

'PM_FILTER' => 'perl -pe \" if (\"$(INSTALLDIRS)\" eq \"perl\") { s|INST_LIBDIR|$(INSTALLPRIVLIB)|g; } elsif (\"$(INSTALLDIRS)\" eq \"vendor\") { s|INST_LIBDIR|$(INSTALLVENDORLIB)|g; } else { s|INST_LIBDIR|$(INSTALLSITELIB)|g; } \"'
but there has to be a better solution than this.

--
જલધર

Replies are listed 'Best First'.
(tye)Re: How to make a module aware of where it is installed?
by tye (Sage) on Dec 04, 2002 at 15:53 UTC

    chromatic said "lib" not "blib". Create a "lib" subdirectory at the top of your package and put any extra files to be installed in there with the proper directory structure.

    For example, if you are building your module in /home/tye/Foo-Bar then you could have something like the following files:

    /home/tye/Foo-Bar/MANIFEST /home/tye/Foo-Bar/Makefile.PL /home/tye/Foo-Bar/Bar.pm /home/tye/Foo-Bar/lib/Foo/blurp.pm /home/tye/Foo-Bar/lib/Foo/Bar/Baz.pm
    and "make" would create the following files:
    /home/tye/Foo-Bar/blib/lib/Foo/Bar.pm /home/tye/Foo-Bar/blib/lib/Foo/blurp.pm /home/tye/Foo-Bar/blib/lib/Foo/Bar/Baz.pm
    and "make install" would then put them in the correct final location.

            - tye

      Ah ok I misunderstood. This makes my Makefile.Pl marginally simpler, but still doesn't solve the problem of the module itself knowing where it is installed.

      --
      જલધર

        If your module is called Foo::Bar, then $INC{"Foo/Bar.pm"} will give you the full path to your Bar.pm file. Or you could use __FILE__ for the same thing. Then use File::Basename and/or File::Spec (see also File::Spec) to get the path of just the directory.

                - tye