Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Question about inheritance of WWW::Mechanize

by runrig (Abbot)
on May 22, 2013 at 17:35 UTC ( #1034794=note: print w/ replies, xml ) Need Help??


in reply to Question about inheritance of WWW::Mechanize

See the docs regarding the autocheck option.


Comment on Re: Question about inheritance of WWW::Mechanize
Re^2: Question about inheritance of WWW::Mechanize
by ryo0ka (Novice) on May 22, 2013 at 19:25 UTC

    Thanks for replying guys,

    >See the docs regarding the autocheck option.

    I just checked the doc and modified my code to turn it on, but it still does not work:

    package MyMech; use base qw(WWW::Mechanize); sub new { my $class = shift or die $!; my $self = $class->SUPER::new( autocheck => 1, ); return bless $self, $class; } sub get { my $self = shift or die $!; $self->SUPER::get(@_); }

    >Does the superclass die on error?

    Yeah, it dies when the server is not responding:

    Error GETing (URL): Can't connect to (URL) (Bad hostname) at ***.pl line **

    >Have you tried the $self->success() method?

    Oh God it works... I changed the tester code from:

    my $mech = MyMech->new; $mech->get("http://google.com/"); print $mech->title."\n";

    to:

    my $mech = MyMech->new; $mech->get("http://google.com/"); print $mech->title."\n" if $mech->success;

    Now it displays the error code. Thank you so much...

    But I don't get why it came to work by putting the if statement. In addition now it works only with 'autocheck' even though it didn't work before i put the if statement.

    Anyway... Thank you guys so much, now I can move on :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1034794]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-12-28 14:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls