Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to package a module with script so end user doesn't need to instal

Status
Not open for further replies.

mockler

Programmer
Aug 16, 2002
15
CA
Hello,

I've created some scripts that install an application on a Solaris box. In my perl scripts I use some modules to connect to the database.

The problem is this script must be run on multiple machines and I DON'T want the end user to have to install these modules before running the perl script.

Is there anyway I can package up the modules and scripts together so the end user can just run the perl script? (Obviously perl would be installed, but no non-default modules)

I've tried just having the *.pm file in the same directory as my perl script but that doesn't quite work.

Thanks,

Andrew
 
Putting the *.pm files in the same directory should work, since "." is normally included in @INC. The problem I could see with this is if the working directory isn't the same as the directory the script is in.

If the cwd is a problem, you can try using File::Basename to change the directory to the directory of the Perl script.

Code:
use File::Basename;
chdir (dirname($0));

You can also "use lib" to add a new directory to @INC. I always keep my local modules used by certain scripts in a local lib folder named "lib" relative to the script.

Code:
use lib "./lib";
 
Thanks for your response Kirsle.

I tried what you said and it seems to be picking up the module. But I still get an error. The module I'm trying to use is DBI. When I execute the script I get the following error:

"Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI"?) at Req-DB_Connect-Solaris.pl line 126"

I don't get this error on my development box, but that is the one that I actually installed the module on. That is why I thought that my script on this test box was not getting/reading the module properly.
 
I wish that it was that simple. But I don't think it is. I do have the "use DBI;" in my script.

Here is a portion of my script (not all is shown, like the variable assigment):

Code:
use DBI;

################################################################################# 
# Will have to start a JDBC server inorder to test the JDBC driver 
# connectivitiy.
 
# Must first set the Classpath so the server can be started.

$ENV{'CLASSPATH'} = "$script_dir/log4j-1.2.11.jar:$script_dir/ojdbc14.jar:$script_dir/dbd_jdbc.jar:$ENV{'CLASSPATH'}";

system "$java_dir/bin/java -Djdbc.drivers=oracle.jdbc.driver.OracleDriver -Ddbd.port=9001 -Ddbd.trace=tedious com.vizdom.dbd.jdbc.Server > JDBC_server.log 2>&1 &";
 
################################################################################# 
# Using the JDBC server that was just started, will now test connectivity with 
# the database using the JDBC driver 

$dbh = DBI->connect("dbi:JDBC:hostname=127.0.0.1;port=9001;url=jdbc:oracle:thin:\@$db_address:$db_port:$db_id", $db_username, $db_password);

# Will now look at the log file and ensure that the connection was made properly, otherwise return a failure.

open in_file, "<JDBC_server.log";

$db_connection_success = 0;

until ($db_connection_success != 0)
 {
    while (<in_file>)
      {
        if ($_ =~ /.*response: Connected.*/)
        {
          $db_connection_success = 1;
        }
        elsif ($_ =~ /.*error.*/)
        {
          $db_connection_success = 2;
        }
        elsif ($_ =~ /.*Exception.*/)
        {
          $db_connection_success = 2;
        }
      }
 }

close (in_file);

$dbh->disconnect;

Thanks for your help thus far.
 
DBI is a complex module which has other requirements. For example, the database driver for Oracle is DBD::Oracle which often needs to be installed separately.

Also, the DBI driver has some requirements which are C libraries. I don't know the details of how this works, but these C libraries have to be compiled for the specific platform. You won't be able to copy from a Linux box to a Solaris box, but it should work between two Solaris boxes.

If it's a Pure Perl module, without C libraries, just copying the files should be fine, but you might need more than just the .pm files. If it's a module with [tt]::[/tt] in the name, that usually means there's a subdirectory involved.

If it's an XS Module (the kind that uses compiled C libraries) it'll b harder to copy. It's probably possible if both platforms are the same, but it may be easier to install the CPAN module and use it to install the required module.

Looking at your code, I can tell some of the things that are missing that you need:
[URL unfurl="true" said:
http://search.cpan.org/src/VIZDOM/DBD-JDBC-0.69/README[/URL]]
PREREQUISITES

The following must be installed before attempting to install
this driver.

Perl 5.8 or higher
Convert::BER 1.31
DBI 1.48 or higher


In addition to Perl, the following must be available in order
to run this driver.

Java Virtual Machine compatible with JDK 1.3
JDBC driver for your database of choice

--
-- Ghodmode
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top