Charlie Ordonez
Charlie Ordonez

Reputation: 23

Perl not including custom modules

I recently had to move from a shared account into a VPS, ever since I moved into the VPS I cannot get some Perl scripts that were not written by me to work anymore.

The main script starts like this:

#!/usr/bin/perl

BEGIN{ push @INC, '../'; }

use CGI qw/:standard *div *form *script/;  
use Vamp::Config qw/:site/;
use Vamp::Users;
use Vamp::Utils;
use Vamp::HTML;
use strict;
use warnings;

From my limited knowledge of Perl, I can tell that it is trying to use some custom Perl modules (Config, Users, Utils & HTML). However, there is something here that is not allowing them to be used.

The folder structure looks like this:

And this is how one of those modules is written:

package Vamp::Config;

BEGIN{ push @INC, '../' }

use Exporter;
use strict;
use warnings;

our @ISA = ("Exporter");
our @EXPORT_OK = qw/%DB $HOME_URL $ADMIN_URL $SITE_ROOT/;
our %EXPORT_TAGS = (
    database => [qw/%DB/],
    site    => [qw/$HOME_URL $SITE_ROOT/],
    admin   => [qw/$ADMIN_URL/]
);

our %DB = (
    LIVE    => {
        DATASOURCE  => 'DBI:mysql:vamplets:localhost',
        USERNAME    => 'example', 
        PASSWORD    => 'example'
    },
    DEV     => {
        DATASOURCE  => 'DBI:mysql:Vamplets:localhost',
        USERNAME    => 'example',
        PASSWORD    => 'example'
    },
    DEV_ADMIN   => {
        DATASOURCE  => 'DBI:mysql:VampletsAdmin:localhost',
        USERNAME    => 'example',
        PASSWORD    => 'example'
    },
    ADMIN   => {
        DATASOURCE  => 'DBI:mysql:vampletsadmin:localhost',
        USERNAME    => 'example',
        PASSWORD    => 'example'
    }
);

our $HOME_URL = 'http://www.vamplets.com';
#our $HOME_URL = 'http://localhost/vamplets';
#our $ADMIN_URL = 'http://localhost/vamplets/admin';
our $ADMIN_URL = 'http://www.vamplets.com/admin';
our $SITE_ROOT = "/home/content/13/5396413/html/";
#our $SITE_ROOT = "C:/xampp/htdocs/vamplets/";

I've tried so many different things I really just don't know what to do anymore.

I just keep getting a 500 Internal Server Error.

I know Perl is installed and working as I've used this to check: https://ip-50-63-189-142.ip.secureserver.net/cgi-bin/perldiver/perldiver.pl

Thank you in advanced!

Upvotes: 0

Views: 277

Answers (1)

ikegami
ikegami

Reputation: 385496

Problem #1

The package directive says

 package Vamp::Config;

so you are correctly using

 use Vamp::Config;

but that means the file MUST be named

 Vamp/Config.pm

You said it's named

 Vamps/Config.pm

Problem #2

For starters,

 BEGIN { push @INC, '../'; }

can be written more clearly as

 use lib '..';

It's also better because it puts the directories at the front of the path, and it adds corresponding arch directories if they exist.


Relative paths in @INC are treated just like relative paths almost everywhere else: relative to the current work directory. You want to look in a path relative to the directory in which the script resides (not in a path relative to the current work directory), so you need to provide an absolute path build from that directory.

Replace

 BEGIN { push @INC, '../'; }    # Buggy

with

use FindBin qw( $RealBin );
use lib "$RealBin/..";

If the library dircetory was more sensibly named ../lib (e.g. lib/Vamp/Config.pm), then you could simply use

use mylib;

Upvotes: 5

Related Questions