I ran your code and there was no indication in the output that any errors occurred.

200 200 Back 1 OK 200 Back 2 OK 200 Back 1 OK 200 Back 2 OK

I improved your test so we can actually see the problem:

#!perl use strict; use warnings; use WWW::Mechanize qw( ); my $mech = WWW::Mechanize->new(); #$mech->proxy(['http', 'ftp'], 'http://localhost:8080/'); my $url = 'http://www.vitoco.cl/test-ref'; #my $url = 'http://www.vitoco.cl/test-ref/index2.html'; $mech->get($url)->is_success() or die; @ARGV or die; for my $img ($mech->images) { if ($ARGV[0]) { $mech->head($img->url_abs())->is_success() or die; $mech->back() or die; } my $response = $mech->get($img->url_abs()); print($mech->status(), "\n"); print( ( $response->redirects() )[0]->request()->referer(), "\n"); $mech->back() or die; print("\n"); }
$ perl a.pl 0 200 http://www.vitoco.cl/test-ref 200 http://www.vitoco.cl/test-ref $ perl a.pl 1 200 http://www.vitoco.cl/test-ref/img1 200 http://www.vitoco.cl/test-ref/img1

When I upgraded WWW::Mechanize, the back returned false after a head.

$ perl a.pl 0 200 http://www.vitoco.cl/test-ref 200 http://www.vitoco.cl/test-ref $ perl a.pl 1 Died at a.pl line 22.

So yes, WWW::Mechanize is buggy.

if ( $request->method eq 'GET' || $request->method eq 'POST' ) { $self->_push_page_stack(); }

should be changed to

$self->_push_page_stack();

Please file a bug report.


In reply to Re: Referer and HEAD using WWW::Mechanize by ikegami
in thread Referer and HEAD using WWW::Mechanize by vitoco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.