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

I need to run the following code, but my ISP has so far declined to install User::Agent. Besides getting another ISP, what other alternatives do I have?
read (STDIN, $query, $ENV{'CONTENT_LENGTH'}); $query .= '&cmd=_notify-validate'; $ua = new LWP::UserAgent; $req = new HTTP::Request 'POST','http://www.webserver.com/cgi-bin/webs +cr'; $req->content_type('application/x-www-form-urlencoded'); $req->content($query); $res = $ua->request($req);

Replies are listed 'Best First'.
Re: Alternatives to User::Agent?
by liz (Monsignor) on Jul 20, 2003 at 13:56 UTC
    If you're not stuck to having to use POST (but instead use GET), then it could be as simple as:
    read (STDIN, $query, $ENV{'CONTENT_LENGTH'}); $query .= '&cmd=_notify-validate'; # set up connection and do the request my $socket = IO::Socket::INET->new( 'www.webserver.com:80' ) or die; print $socket "GET /cgi-bin/webscr?$query HTTP/1.0\n\n"; # check return status my $status = <$socket>; die "Unacceptable status: $status" unless $status =~ /200/; # lose the HTTP header while (<$socket>) { last if /^\s+$/s; } # get the body while (<$socket>) { $res .= $_; }
    Liz
      I would have to first load IO::Socket::INET, right? would this be:
      use IO::Socket::INET;
        use IO::Socket;
        should be enough, I believe.

        Liz

Re: Alternatives to User::Agent?
by bobn (Chaplain) on Jul 20, 2003 at 14:11 UTC

    From perldoc ExtUtils::MakeMaker:

    The quickest way to install a module in a non-standard place might be

       perl Makefile.PL PREFIX=~

    This will install all files in the module under your home directory, with man pages and libraries going into an appropriate place (usually ~/man and ~/lib).

    So if you have shell access, you can use whatever modules you like.

    --Bob Niederman, http://bob-n.com
      Even without shell access, you can often install modules. I frequently write short shell scripts, upload them into my Web hoster's cgi-bin directory, then use them to compile and install my Perl modules:
      #!/bin/bash -x
      
      printf "Content-type: text/plain\n\n"
      exec 2>&1
      
      H=/home/virtual/site199/fst/home/suspectclass
      export PERL5LIB=$H/lib/perl5
      MOD=Email-Valid-0.14
      
      cd $H/src
      tar xvzf "$MOD.tar.gz"
      cd "$MOD"
      make clean
      perl Makefile.PL LIB=$H/lib/perl5 && 
        make && 
        make test && 
        make install
      
      I just set H to my home directory (which I often get by running a shell script that just does pwd, since I may be chroot'd when I FTP in), then browse to the CGI script. On Mozilla at least, the lines come across in real time.

      Setting PREFIX may work even better than just setting LIB, but I haven't tried it (I will next time).

        Just be careful after you do so to remove them again. (Allowing people to run arbitrary shell scripts is a security hole.)

        UPDATE: bobn is right. The above script does not allow someone to run arbitrary code. This reply was just a knee-jerk response to seeing someone doing administration through running shell scripts in cgi-bin.

        I figured out that the module I need to LWP::UserAgent is libwww-perl-5.69.tar.gz

        Now, do I need to put anything into /lib/perl5 ?

      sorry, no shell access :-(