Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Is it possible to use modules without installing them?

by Nemp (Pilgrim)
on Aug 31, 2002 at 15:16 UTC ( [id://194342] : perlquestion . print w/replies, xml ) Need Help??

Nemp has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I've been looking for a way to generate images on the fly and I found the rather helpful GD CPAN module.

Wonderful! I thought and downloaded it and played with it a little and then decided to run it online on my web-site. This is where my problem is... the distro of Perl on my website doesn't have GD installed and I am unable to install it there. Is there another way I can do this? Include the source for GD some other way than "use GD;"

I'm sorry if this is a rather basic question but I've been tearing my hair out for the last 2 hours searching with no luck so I thought I'd ask if anyone can tell me how or just point me to the relevant part of the FM :)

  • Comment on Is it possible to use modules without installing them?

Replies are listed 'Best First'.
Re: Is it possible to use modules without installing them?
by BrowserUk (Patriarch) on Aug 31, 2002 at 15:34 UTC

    In general, if the module concerned is a "pure perl" module, there is nothing (provided you take the copyrights etc with it) of including it into your script as source.

    However, many modules have XS and/or C components and they obviously won't work without their compiled bits.

    I'm not familiar with the internals of GD so don't know which is the case for it.

    Being a graphics module, it's quite likely that at least some of it has been optomised to C for speed?

    Well It's better than the Abottoire, but Yorkshire!
      Thanks for the reply!

      Unfortunately you've provided me with another question now, specifically for GD and for any other module generically, is there a way to find out if a module is "pure Perl"?

      I guess I could just go and look through the source code but I'm still pretty much a novice at Perl so I might skip parts I don't understand and not recognize them as being XS or C components. Maybe there is a module on CPAN that analyzes a given file to determine if it's pure Perl or not?

      Many thanks for any help and the help so far :)
        You can tell if a module is pure Perl or not by examining the dslip information.

        One module which does this is CPANPLUS (it also does a whole lot more, including module installation without root access, which I recommend over including the module source in your program*). The default shell includes the 'l' command which will give information, including the language used. might also give dslip info, but I don't know it well enough to say if it does or not.

        GD is C and Perl and a C compiler is needed. If your ISP allows you to use a compiler, you should still be able to install it without being root.

        [1] For instructions on how to do this with CPANPLUS, refer to the FAQ (available on the website).

Re: Is it possible to use modules without installing them?
by dws (Chancellor) on Aug 31, 2002 at 17:12 UTC
    ... the distro of Perl on my website doesn't have GD installed and I am unable to install it there.

    GD has been around for quite a while now. If you're ISP doesn't have it, or if you can't get them to install it for you, treat this as a big warning flag, and start looking around for a new, Perl-friendly ISP.

Re: Is it possible to use modules without installing them?
by zentara (Archbishop) on Aug 31, 2002 at 16:36 UTC
     I havn't tried it yet, but it may be possible to put the GD package 
    on your remote machine if they let you compile. You should
    be able to ssh to your homedir and do it. Here is an excerpt from
    the mod-perl-in-homedirs.html.
    8.1. Installing Perl Modules into a Directory of Choice
       Since without superuser permissions you aren't allowed to install
       modules into system directories like /usr/lib/perl5, you need to find
       out how to install the modules under your home directory. It's easy.
       First you have to decide where to install the modules. The simplest
       approach is to simulate the portion of the / file system relevant to
       Perl under your home directory. Actually we need only two directories:
       We don't have to create them, since that will be done automatically
       when the first module is installed. 99% of the files will go into the
       lib directory. Occasionally, when some module distribution comes with
       Perl scripts, these will go into the bin directory. This directory
       will be created if it doesn't exist.
       Let's install the package, which includes a few other CGI::*
       modules. As usual, download the package from the CPAN repository,
       unpack it and chdir to the newly-created directory.
       Now do a standard perl Makefile.PL to prepare a Makefile, but this
       time tell MakeMaker to use your Perl installation directories instead
       of the defaults.
    % perl Makefile.PL PREFIX=/home/stas
       PREFIX=/home/stas is the only part of the installation process which
       is different from usual. Note that if you don't like how MakeMaker
       chooses the rest of the directories, or if you are using an older
       version of it which requires an explicit declaration of all the target
       directories, you should do this:
    % perl Makefile.PL PREFIX=/home/stas \
      INSTALLPRIVLIB=/home/stas/lib/perl5 \
      INSTALLSCRIPT=/home/stas/bin \
      INSTALLSITELIB=/home/stas/lib/perl5/site_perl \
      INSTALLBIN=/home/stas/bin \
      INSTALLMAN1DIR=/home/stas/lib/perl5/man  \
       The rest is as usual:
    % make
    % make test
    % make install
Re: Is it possible to use modules without installing them?
by sharkey (Scribe) on Aug 31, 2002 at 19:22 UTC
    If you're only problem is being able to type 'make install', you can still easily use the module.

    Assuming you have a shell account on the ISP, do the usual:
    UPDATE: see the reply. Those steps work even better.

    tar -zxvf GD-1.41.tar.gz cd GD-1.41 perl Makefile.PL make make test
    (If you didn't make it this far because of missing libs, etc, you're out of luck, unless you can download and build those in your shell directory too. And yes, GD does use XS: notice the GD.xs file in the distribution.)

    Now, in the top of your scripts which want to use GD, do this:

    use lib '/home/neil/GD-1.41/blib/lib','/home/neil/GD-1.41/blib/arch'; use GD;
    You'll see a line like this at the top of the test file, since the tests have to run without the module being installed.

    BTW, use lib is like the following, but with more error-checking:

    BEGIN { unshift (@INC, 'directory'); }
    ~ John Williams
Re: Is it possible to use modules without installing them?
by gmpassos (Priest) on Aug 31, 2002 at 20:51 UTC
    You can put the module in the same directory of the script, in this case, I think, your cgi-bin.

    Let's use like a module, with a XS too. 1st get it, compile and install in some Perl interpreter that you have access, with the same OS of your server. They will be instaled at: (let's use Perl for Win32 like example (path more simple))

    To enable this module in the server just copy all the stuf from inside site/lib to your server, with the same path. In the cgi-bin will be like:

    This will work fine, because Perl use your local path like a lib directory too (see @INC). About the directory auto/FOO, copy everything inside to the server, not only the DLL. And if your module have other sub-modules you need to copy the directory site/lib/FOO too.

    Using this steps you don't need a shell acount to do that, just a FTP! Don't forget to send the .pm like ANSII and the DLL (or .so on linux) like binary!

    Graciliano M. P.

    "The creativity is the expression of the liberty".