Somewhat related is this Github issue, but it seems that WWW::Mechanize tries to retrieve the value of base from the HTTP headers instead of (also, and with priority) looking at the HTML base tag.
In vaguely related code, I've used the following to extract the value of the base tag:
# Check if we have a <base> tag which should replace the user-supp
+lied URL
if( $_[0] =~ s!<\s*\bbase\b[^>]+\bhref=([^>]+)>!!i ) {
# Extract the HREF:
my $href= $1;
if( $href =~ m!^(['"])(.*?)\1! ) {
# href="..." , with quotes
$href = $2;
} elsif( $href =~ m!^([^>"' ]+)! ) {
# href=... , without quotes
$href = $1;
} else {
die "Should not get here, weirdo href= tag: [$href]"
};
my $old_url = $url;
$url = relative_url( $url, $href );
#warn "base: $old_url / $href => $url";
};