using a module on cpanel when not root

G

Guest

I am trying to use a module I have already installed on cpanel theme v3,

I have installed it per the host's instructions, and have added the code
given by the host:
my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
if (-d $homedir . '/perl' . $INC[$i]) {
unshift(@INC,$homedir . '/perl' . $INC[$i]);
$n_inc++;
$i++;
}
}

However it says the module cannot be located even though I have tried it
with and without the library paths, i.e

use module;

or

use module '/path/to/module.pm';
 
B

Brian McCauley

I am trying to use a module I have already installed on cpanel theme v3,

I have installed it per the host's instructions, and have added the code
given by the host:
my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
if (-d $homedir . '/perl' . $INC[$i]) {
unshift(@INC,$homedir . '/perl' . $INC[$i]);
$n_inc++;
$i++;

}
}

Golly that's nasty code. What's with the $i and $n_inc stuff? I
strongly suspect that code was not written by a Perl programmer.

my $homedir = (getpwuid($>))[7];
unshift @INC, reverse grep { -d } map { "$homedir/perl/$_" } @INC;

Actually I'm not sure why the original code reversed the order so you
can probably omit the 'reverse'.
However it says the module cannot be located

I suspect you are attempting to load the module using the 'use'
function. Documentation of the use function can be viewed by entering

perldoc -f use

The important bit to note is where it says "...happen at compile
time".
even though I have tried it
with and without the library paths, i.e

use module;

That is a compile time operation. Loading of the module happens when
that line of is compiled and therefore before run-time operations even
if they appear earlier in the source. If you attempt to manipulate
@INC and runtime this won't help because information does not travel
backwards in time.

If you want to make your manipulations of @INC happen at compile time
you need to wrap them in BEGIN {}
or

use module '/path/to/module.pm';

That is trying to load module.pm from the usual @INC search path and
pass the string '/path/to/module.pm' as the argument to module-
import().

BTW: I'm having to make assumptions about what you are actually doing
because you didn't post a _minimal_ but _complete_ script to
illustrate your problem.

Please see the posting guidelines for this group.
 
B

Brian McCauley

I am trying to use a module I have already installed on cpanel theme v3,
I have installed it per the host's instructions, and have added the code
given by the host:
my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
if (-d $homedir . '/perl' . $INC[$i]) {
unshift(@INC,$homedir . '/perl' . $INC[$i]);
$n_inc++;
$i++;

Golly that's nasty code. What's with the $i and $n_inc stuff? I
strongly suspect that code was not written by a Perl programmer.

my $homedir = (getpwuid($>))[7];
unshift @INC, reverse grep { -d } map { "$homedir/perl/$_" } @INC;

But do you really want a ~/perl/usr/lib/perl/... structure?

I suspect you really just want to say:

use lib (getpwuid($>))[7] . '/perl';
 
A

anno4000

Nospam said:
I am trying to use a module I have already installed on cpanel theme v3,

cPanel is a proprietary product.
I have installed it per the host's instructions, and have added the code
given by the host:

Wouldn't the "host", whoever that is, be the first one to ask what may
be wrong?
my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
if (-d $homedir . '/perl' . $INC[$i]) {
unshift(@INC,$homedir . '/perl' . $INC[$i]);
$n_inc++;
$i++;
}
}

That snippet says a lot about the coder's (lack of) familiarity with
Perl (and C for that matter), but little about its intent and purpose.
Apparently you're supposed to put your module in one of a number of
specific subdirectories in your home directory. Have you done that?
Maybe the problem is that it only checks every other element of @INC,
who knows.
However it says the module cannot be located even though I have tried it
with and without the library paths, i.e

use module;

or

use module '/path/to/module.pm';

*shrug*

There's no way of knowing how these calls are supposed to work.
If the second form is meant to specify the module's location in
the use-statement, it would take some major voodoo to pull that
off.

Anno
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top