I'm not sure why you need to 'reverse engineer' legacy Perl code (decipher, maybe ;^), but your right in thinking there's a better way ... well, simpler anyway.
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request::Common qw/ GET /;
my $url = shift;
my $browser = LWP::UserAgent->new;
my $response = $browser->request( GET $url );
print $response->code;
Personally, I think $response->is_success would be more beneficial as 200 isn't the only response indicating success, but that's your call...
One caveat, tho:- test against a known good site before anything else ... LWP::UserAgent returns a 500 error instead of undef if you don't have have the modules necessary to talk to SSL (aka https) servers.
--k.
| [reply] [d/l] |
You're correct, "is_success" is MUCH better (I'm catchin'
on.) Here's the rub: https, repeat 's'.
Beau
| [reply] |
Go to the link mentioned as "required modules",
i.e. Crypt::SSLeay: "OpenSSL glue that provides LWP https support"
| [reply] |
#!/usr/bin/perl -w
use strict;
use HTTP::WebTest;
my $url = shift;
my $wt = HTTP::WebTest->new;
# runs test and generates test report
$wt->run_tests([ { url => $url } ]);
Note that you still have to install Crypt::SSL to get 'https' to work.
--
Ilya Martynov
(http://martynov.org/)
| [reply] [d/l] |
I installed prerequisites TermReadKey-2.20, File-Temp-0.12,
and Time-HiRes-01.20, but make test fails at 50% (below).
Any ideas?
Thanks, Beau
% perl Makefile.PL
HTTP-WebTest requires installation of the http-webtest directory
for running local file tests. If you don't use local file tests you
can skip installation of this directory.
Install http-webtest directory? (y/n): y
Default directory to install the http-webtest directory in is /usr/l
+ocal/etc,
but you should probably use another location if MYSQL is installed.
Install http-webtest directory in /usr/local/etc? (y/n): y
WARNING: If your system does not have an HTTP connection to the Inte
+rnet or
your system requires a proxy HTTP server, the "make test" tests will
+ fail.
Writing Makefile for HTTP::WebTest
% make
mkdir blib
mkdir blib/lib
mkdir blib/lib/HTTP
mkdir blib/arch
mkdir blib/arch/auto
mkdir blib/arch/auto/HTTP
mkdir blib/arch/auto/HTTP/WebTest
mkdir blib/lib/auto
mkdir blib/lib/auto/HTTP
mkdir blib/lib/auto/HTTP/WebTest
mkdir blib/man1
mkdir blib/man3
cp WebTest.pm blib/lib/HTTP/WebTest.pm
mkdir blib/script
cp wt blib/script/wt
/usr/bin/perl -I/usr/local/lib/perl5/5.6.0/sun4-solaris -I/usr/local
+/lib/perl5/5.6.0 -MExtUtils::MakeMaker -e "MY->fixin(shift)" blib/sc
+ript/wt
Manifying blib/man3/HTTP::WebTest.3
Manifying blib/man1/wt.1
% make test
PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib -I/usr/local/
+lib/perl5/5.6.0/sun4-solaris -I/usr/local/lib/perl5/5.6.0 -e 'use Tes
+t::Harness qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t
t/404...............ok
t/cookie............NOK 1FAILED test 1
Failed 1/1 tests, 0.00% okay
t/form..............NOK 1FAILED test 1
Failed 1/1 tests, 0.00% okay
t/yahoo.............ok
Failed Test Status Wstat Total Fail Failed List of failed
--------------------------------------------------------------------
+-----------
t/cookie.t 1 1 100.00% 1
t/form.t 1 1 100.00% 1
Failed 2/4 test scripts, 50.00% okay. 2/4 subtests failed, 50.00% ok
+ay.
*** Error code 29
make: Fatal error: Command failed for target `test_dynamic'
| [reply] [d/l] |
| [reply] |