Modules and different paths

Discussion in 'Perl Misc' started by Mark Seger, Jun 28, 2004.

  1. Mark Seger

    Mark Seger Guest

    I'm trying to use Compress::Zlib in a script I'm trying to run on a
    number of platforms. Depending on which version of Compress and perl
    are being used, more often than not it seems Zlib gets installed in a
    direction not in the current @INC - the most common being ending up in a
    5.6 directory on a 5.8 system or visa-versa and it's driving me and the
    users of the script crazy.

    The thought I had was in the initialization section to look in specific
    known locations to figure out where Zlib ended up and then add that
    location to @INC. right? I thought I'd try to be clever and use the
    lib module to set INC but to do that at run vs compile time I have to do
    it in a require. No problem, or so I thought, but if I can't figure out
    the syntax! My thought was since the syntax for 'use' is

    use lib 'path';

    I could say

    require "lib 'path'";

    but that doesn't seem to do it. So I guess my multipart question is:
    - is this a reasonable way to deal with rpms that install into multiple
    locations?
    - is the correct way to set my path dynamically to 'require lib' and if
    so what is the correct syntax?
    - is there a way to get an rpm to install in a directory I want it to
    rather than the ones it wants to?

    -mark
    Mark Seger, Jun 28, 2004
    #1
    1. Advertising

  2. Mark Seger <> wrote in
    news::

    > I'm trying to use Compress::Zlib in a script I'm trying to run on a
    > number of platforms. Depending on which version of Compress and perl
    > are being used, more often than not it seems Zlib gets installed in a
    > direction not in the current @INC - the most common being ending up in
    > a 5.6 directory on a 5.8 system or visa-versa and it's driving me and
    > the users of the script crazy.
    >
    > The thought I had was in the initialization section to look in
    > specific known locations to figure out where Zlib ended up and then
    > add that location to @INC. right? I thought I'd try to be clever and
    > use the lib module to set INC but to do that at run vs compile time I
    > have to do it in a require. No problem, or so I thought, but if I
    > can't figure out the syntax! My thought was since the syntax for
    > 'use' is
    >
    > use lib 'path';
    >
    > I could say
    >
    > require "lib 'path'";


    Did you check:

    perldoc -q lib


    --
    A. Sinan Unur
    (reverse each component for email address)
    A. Sinan Unur, Jun 28, 2004
    #2
    1. Advertising

  3. Mark Seger

    Mark Seger Guest

    A. Sinan Unur wrote:
    > Mark Seger <> wrote in
    > news::
    >
    >
    >>I'm trying to use Compress::Zlib in a script I'm trying to run on a
    >>number of platforms. Depending on which version of Compress and perl
    >>are being used, more often than not it seems Zlib gets installed in a
    >>direction not in the current @INC - the most common being ending up in
    >>a 5.6 directory on a 5.8 system or visa-versa and it's driving me and
    >>the users of the script crazy.
    >>
    >>The thought I had was in the initialization section to look in
    >>specific known locations to figure out where Zlib ended up and then
    >>add that location to @INC. right? I thought I'd try to be clever and
    >>use the lib module to set INC but to do that at run vs compile time I
    >>have to do it in a require. No problem, or so I thought, but if I
    >>can't figure out the syntax! My thought was since the syntax for
    >>'use' is
    >>
    >>use lib 'path';
    >>
    >>I could say
    >>
    >>require "lib 'path'";

    >
    >
    > Did you check:
    >
    > perldoc -q lib
    >
    >


    no I didn't 8-( and it is very informative, but only if you're
    building from source. I probably should have been clearer that I'm
    trying to have people simply install prebuilt rpms and it's those very
    rpms that have specific places they stash their code in.
    -mark
    Mark Seger, Jun 28, 2004
    #3
  4. Mark Seger <> wrote in news:40e08909$1
    @usenet01.boi.hp.com:

    > A. Sinan Unur wrote:
    >> Mark Seger <> wrote in
    >> news::


    ....
    >>> I can't figure out the syntax! My thought was since the syntax
    >>> for 'use' is
    >>>
    >>>use lib 'path';
    >>>
    >>>I could say
    >>>
    >>>require "lib 'path'";

    >>
    >>
    >> Did you check:
    >>
    >> perldoc -q lib
    >>
    >>

    >
    > no I didn't 8-( and it is very informative, but only if you're
    > building from source. I probably should have been clearer that I'm
    > trying to have people simply install prebuilt rpms and it's those very
    > rpms that have specific places they stash their code in.


    I might be misunderstanding something here, but:

    use strict;
    use warnings;

    use File::Spec::Functions qw(catfile);

    BEGIN {
    sub find_my_lib {
    catfile($ENV{TEMP}, 'lib');
    }
    }

    use lib find_my_lib();

    use MyClass;

    my $t = MyClass->new('Hello World!');

    use Data::Dumper;
    print Dumper $t;

    __END__

    C:\Home> t
    $VAR1 = bless( do{\(my $o = 'Hello World!')}, 'MyClass' );

    Does this help?

    --
    A. Sinan Unur
    (reverse each component for email address)
    A. Sinan Unur, Jun 28, 2004
    #4
  5. Mark Seger

    Ben Morrow Guest

    Quoth Mark Seger <>:
    > I'm trying to use Compress::Zlib in a script I'm trying to run on a
    > number of platforms. Depending on which version of Compress and perl
    > are being used, more often than not it seems Zlib gets installed in a
    > direction not in the current @INC - the most common being ending up in a
    > 5.6 directory on a 5.8 system or visa-versa and it's driving me and the
    > users of the script crazy.


    NOTE that 5.6 and 5.8 are not binary-compatible, which is why the 5.6
    lib dir is not searched by default by 5.8. If your rpms are installing
    in a 5.6 dir, are they installing modules built for 5.6?

    > The thought I had was in the initialization section to look in specific
    > known locations to figure out where Zlib ended up and then add that
    > location to @INC. right? I thought I'd try to be clever and use the
    > lib module to set INC but to do that at run vs compile time I have to do
    > it in a require. No problem, or so I thought, but if I can't figure out
    > the syntax! My thought was since the syntax for 'use' is
    >
    > use lib 'path';
    >
    > I could say
    >
    > require "lib 'path'";
    >
    > but that doesn't seem to do it.


    Try

    require lib;
    import lib 'path';

    This *is* better than simply pushing onto @INC, as it will also find
    arch directories.

    > So I guess my multipart question is:
    > - is this a reasonable way to deal with rpms that install into multiple
    > locations?


    Err... I would say, no, fix the rpm or install from source (I manage all
    perl modules on my system with CPAN.pm, and don't use my package manager
    for them at all).

    > - is there a way to get an rpm to install in a directory I want it to
    > rather than the ones it wants to?


    Dunno, I'm afraid... I stay as far from rpms as possible :).

    Ben

    --
    don't get my sympathy hanging out the 15th floor. you've changed the locks 3
    times, he still comes reeling though the door, and soon he'll get to you, teach
    you how to get to purest hell. you do it to yourself and that's what really
    hurts is you do it to yourself just you, you and noone else **
    Ben Morrow, Jun 28, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noah
    Replies:
    5
    Views:
    752
  2. sashan
    Replies:
    0
    Views:
    246
    sashan
    Dec 8, 2003
  3. MrBlueSky

    Modules... paths... newbie confusion

    MrBlueSky, Aug 21, 2006, in forum: Python
    Replies:
    9
    Views:
    336
    Steve Holden
    Aug 25, 2006
  4. Brandon Mintern

    paths in modules

    Brandon Mintern, Feb 22, 2007, in forum: Python
    Replies:
    5
    Views:
    275
    Brandon Mintern
    Feb 22, 2007
  5. Ohad Lutzky

    Paths, gentleman, paths

    Ohad Lutzky, Nov 6, 2006, in forum: Ruby
    Replies:
    2
    Views:
    176
    David Vallner
    Nov 7, 2006
Loading...

Share This Page