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

I start out with this:

use vars qw($Pua $parsor $spp_Array);
$Pua = new LWP::UserAgent;
$spp_Array = 0;
$parsor = HTML::LinkExtor->new(\&callback);
my $res = $Pua->request(HTTP::Request->
          new(GET => $WebPage),sub {$parsor->parse($_[0])});
$Ubase = $res->base;

sub callback {
 my($tag, %attr) = @_ ;
 my $Urray = ($spp_Array)? \@main::morePicpages : \@main::Picpages;
 return if $tag ne 'a';
 push(@$Urray, values %attr);
}


This works great once. Then much further down into my code, based all sorts
of conditional stuff far too lengthy to post here, I try this:

my ($all_links, $response, $parser_agin);

$spp_Array = 1;

$parsor_agin = HTML::LinkExtor->new(\&callback);
$response = $Pua->request(
        HTTP::Request->new(
                GET => $all_links, sub {$parsor_agin->parse($_[0])})
                               );


This is how that code fails:
Can't call method "clone" on unblessed reference at D:\perl\site\lib/HTTP/Message.pm line 53.


Help. Cannot see why it worked once then will not work again, and there's a suspicion in my mind that some OO thing that I don't get is biting me. BTW, pls remember if you would reply that lots of perlers don't totally grasp OO, and this is not a pissing contest but each of us individually on a long-term path of seeking to improve our depth of understanding. In that spirit, and not merely out of individual thin-skinned-ness, flame-like replies will be ignored. Thanks

soren

  • Comment on HTTP::Message unblessed reference error? I don't get it.

Replies are listed 'Best First'.
Re: HTTP::Message unblessed reference error? I don't get it.
by tye (Sage) on Aug 06, 2000 at 08:44 UTC

    Your second call to HTTP::Request->new() is failing because you pass in too many arguments. In the first call, the "sub" is not passed to HTTP::Request->new(). Check your parentheses.

    Better yet, when you call a method that may fail, don't pass the return value off to another method without checking it first:

    my $req= HTTP::Request->new( GET=>$all_links ) or die "Can't request all links"; $response = $Pua->request( $req, sub {$parsor_agin->parse($_[0])} );
            - tye (but my friends call me "Tye")
Re: HTTP::Message unblessed reference error? I don't get it.
by Intrepid (Curate) on Aug 07, 2000 at 05:18 UTC

    Yes, in fact, absolutely, right. So right. YES! Humble thanks. Good grief, I have this thing working now. And good points, all.

    Wonderful <sigh of relief>.

    - soren