Modules and different paths

M

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.

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
 
A

A. Sinan Unur

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
 
M

Mark Seger

A. Sinan Unur said:
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
 
A

A. Sinan Unur

....

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?
 
B

Ben Morrow

Quoth Mark Seger said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top