Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Modules that get along with use lib

by earthboundmisfit (Chaplain)
on Oct 24, 2001 at 19:07 UTC ( [id://121136]=perlquestion: print w/replies, xml ) Need Help??

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

Brothers and sisters,
I am involved in several sites that are hosted by lame ISPs who offer nothing in the way of useful Perl modules. (I had to beg them to install CGI.pm) What's worse, they only allow FTP access to the Linux boxes on which the sites run. Trust me, if I could, I would switch ISPs in a heart beat.

I'm fully aware that I can install my own modules by uploading the *.pm file(s) and using use lib '[path to pm file]' in my scripts.

The wisdom I seek is in knowing which modules are safe for this method and which require true installation in /Perl/lib or /Perl/site/lib

If you know specific modules that won't work, that would help, but in a more general vein, what types of things should I look for when assessing how they will react with use lib?

I did a Super Search on this topic and couldn't come up with much, but sometimes I can be dense when it comes to search criteria....

Your help is much appreciated.

Edit: chipmunk 2001-10-24

Replies are listed 'Best First'.
Re: Modules that get along with use lib
by chipmunk (Parson) on Oct 24, 2001 at 20:21 UTC
    All modules will work fine with use lib. The only thing use lib does is add directories to @INC. It doesn't matter to the module whether it is in one of the "standard" library directories or in a library directory that is specific to your script.

    The real question is which modules can simply be 'installed' by copying over the .pm files, and which require actually being compiled on the machine in question.

    Some modules use AutoSplit, and so have .al files, in addition to the .pm files. Some modules have XS components and need to be built with a C compiler, and the binary .so (or whatever) files from one machine may not be compatible with another machine. There are other factors that could make it necessary to build and install the module the regular way.

    Fortunately, it's ridiculously simple to install a module, in the standard way, into any directory you want:

    perl Makefile.PL PREFIX=/path/to/my/lib/directory make make test make install
    You could even set up a CGI script to do it!

      You could even set up a CGI script to do it!

      I do this sort of thing all of the time on FTP-only ISPs. I have a RIDICULOUSLY simple barebones template of a CGI script which I modify to run arbitrary commands and display their output.

      #!/usr/bin/perl -w use strict; use CGI qw(:all); use CGI::Carp qw( fatalsToBrowser ); my $v = `arbitrary command 2>&1`; print join( "\n", header, start_html("Arbitrary Command"), strong(h1("Arbitrary Command:")), pre( $v ), end_html ),"\n";

      Just customize 'arbitrary command' and save the result as, say, 'arbitrary command.cgi' using FTP and Bob's your uncle.

      dmm

      
      You can give a man a fish and feed him for a day ...
      Or, you can teach him to fish and feed him for a lifetime
      
      That won't, sadly, answer this monk's enquiry, since said monk specifically mentioned that he is limited to FTP access. I ran into this myself just the other day (:twitch: CGI.pm is at version 2.36 there).

      On the other hand, the idea of writing a CGI script to do it, could work... insane, twisted, wrong, but it could work.

        I noticed that the monk said only FTP access was allowed. That is specifically why I said it could be done through a CGI script. Here's an example of what I meant.
        #!/usr/local/bin/perl use CGI; my $cgi = new CGI; print $cgi->header('text/plain'); my $source_dir = "/home/me/source"; my $lib_dir = "/home/me/lib"; my $module = $cgi->param('module'); chdir($source_dir) or die "Can't chdir to $source_dir: $!\n"; system("/bin/gunzip $module.tar.gz") and die "Can't gunzip $module.tar +.gz\n"; system("/bin/tar xf $module.tar") and die "Can't untar $module.tar\n"; chdir("$source_dir/$module") or die "Can't chdir to $source_dir/$modul +e: $!\n"; system("/usr/local/bin/perl Makefile.PL PREFIX=$lib_dir") and die "Error running Makefile.PL\n"; system("/usr/bin/make") and die "Error executing make\n"; system("/usr/bin/make test") and die "Error executing make test\n"; system("/usr/bin/make install") and die "Error executing make install. +\n";
        So, all one has to do is upload this script, upload the .tar.gz file to the source directory, and hit the script from the browser with the name of the module in the module parameter. All possible simply with FTP and CGI.

        Obviously, the script needs better error checking and reporting, and it should capture STDERR from the system calls and send it to the browser along with STDOUT. (Calling a single shell script to handle all the unpacking and building might be an improvement.) I've just written this as a quick hack to get the general idea across.

        Update: Please see DrManhattan's important addendum below; using this script as is would be a huge security risk! An improved script would use taint-checking and restrict the module name to a limited set of characters.

Re: Modules that get along with use lib
by joealba (Hermit) on Oct 24, 2001 at 19:29 UTC
    There's almost always a way. The methods just get more interesting with certain modules.

    Modules like Image::Magick (which is just an interface to some C programs, image libraries, and whatnot) will get *quite* interesting.

    Most straight Perl modules should work just fine with the 'use lib' directive. If the module needs to load other modules, the @INC array is globally prepended by your 'use lib' line, right Monks? So as long as all the required modules live in your own personal module directory, you're fine.

      ...the @INC array is globally prepended by your 'use lib' line, right Monks?

      I honestly don't know, but otherwise the following should do it:

      BEGIN{unshift(@INC,'.');}

      f--k the world!!!!
      /dev/world has reached maximal mount count, check forced.

      Modules like Image::Magick (which is just an interface to some C programs, image libraries, and whatnot) will get *quite* interesting.
      I would imagine that the C libs wouldn't be there, and that you'd have to build imagemagick with
      ./configure --prefix=$HOME make make install
      Then of course, the system doesn't know where to find your libs...
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/lib ldconfig
      Then you'd need to build the Perl interface...
      cd /path/to/Image_Magick perl Makefile.pl PREFIX=${HOME}/lib/perl5 make make install
      Of course then when the webserver (probably user nobody) tries to run it... might not find the libs... depending...

      So the CGI might start:

      #!/usr/bin/perl -t use strict; use lib '/home/myhome/lib/perl5'; $ENV{LD_LIBRARY_PATH} = $ENV{LD_LIBRARY_PATH}.'/home/myhome/lib'; use Image::Magick;
      Yeah, that might be... "interesting."
      --
      Snazzy tagline here
Re: Modules that get along with use lib
by Chrisf (Friar) on Oct 25, 2001 at 00:26 UTC
    I have the exact same problem actually. The module I want to install is Mime::Lite and I am restricted to ftp access. I tried running the scripts shown in this thread but I received an internal server error and unfortunately I do not have access to the error logs. Any suggestions would be appreciated.

    Thanks :)

      So is there hope that HTML::Mason could work even though it requires yet even more packages that are not on the system by default?
        My understanding is that you would have to install all of those Modules that it uses into your local lib directory specified in your use lib statement. This is only for modules that are not already in the normal @INC path.

        I used to run on eHost (let's not go there) and it was the same kind of FTP and no ssh or telnet type <stuff>. Very limiting. As to faking command line access through a script: Most likely any cgi script you write that opens a system pipe and tries to run commands will fail because the script will most likely run as either your user or as 'nobody'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://121136]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-28 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found