develooper Front page | perl.libwww | Postings from April 2001

HTTP::Request DIE error

Thread Next
Tim Allwine
April 11, 2001 15:04
HTTP::Request DIE error
Message ID:
Consider the following code:

use LWP;

$SIG{__DIE__} = \&myCode;

my $ua = LWP::UserAgent->new();
my $base = '';
my $path = '/pub';
my $uri = URI->new_abs($path,$base);
my $req = HTTP::Request->new(GET => $uri);
my $res = $ua->request($req);

print $res->status_line,"\n";

sub myCode {
    print "@_","\n";

When I run this I get the following from my DIE handler:
Missing base argument at
/usr/local/lib/perl5/site_perl/5.6.0/HTTP/ line 107
and then prints
    200 OK
as expected.

The offending lines read like this:

    # Argh!! Hate this... old LWP legacy!
    eval { $uri = $uri->abs; };
    die $@ if $@ && $@ !~ /Missing base argument/;

As far as I can tell $uri->abs should take an argument, shouldn't it?
Look in,
sub abs {
    my $self = shift;
    my $base = shift || Carp::croak("Missing base argument");

How about changing the eval to:
    eval{ $uri = $uri->abs($uri->host) };

If I leave out the die handler you would never see this but
I shouldn't have too.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About