Skip to content

Conversation

Copy link

Copilot AI commented Oct 24, 2025

Fixes rt.cpan.org #76714

Problem

Two examples in WWW::Mechanize::Examples.pod were creating WWW::Mechanize objects without explicitly setting autocheck => 0, then attempting to check $mech->success for success/failure. Since autocheck is enabled by default in standalone WWW::Mechanize instances, these examples would die immediately on failed requests and never reach the success check, making the manual check pointless.

Changes

Fixed two examples that had this issue:

1. pb-upload example

# Before
my $mech = WWW::Mechanize->new();
$mech->get($url);
$mech->submit_form(...);
die unless ($mech->success);  # Never reached on failure due to autocheck

# After
my $mech = WWW::Mechanize->new( autocheck => 0 );
$mech->get($url);
$mech->submit_form(...);
die unless ($mech->success);  # Now properly checked

2. quotes.pl example

# Before
my $mech = WWW::Mechanize->new;
$mech->get( "http://www.imdb.com/search" );
$mech->success or die "Can't get the search page";  # Never reached on failure

# After
my $mech = WWW::Mechanize->new( autocheck => 0 );
$mech->get( "http://www.imdb.com/search" );
$mech->success or die "Can't get the search page";  # Now properly checked

Verification

All other examples in the file were reviewed and found to be correctly written:

  • Examples without success checks properly rely on autocheck to die on errors (correct behavior)
  • Examples that explicitly set autocheck => 1 are already correct
  • Examples that check $response->is_success on HTTP::Response objects (not Mechanize objects) are correct

POD syntax validated with Pod::Simple::Checker.

Original prompt

This section details on the original issue you should resolve

<issue_title>WWW::Mechanize::Examples and autocheck [rt.cpan.org #76714]</issue_title>
<issue_description>Migrated from rt.cpan.org#76714 (status was 'new')

Requestors:

From [email protected] on 2012-04-20 01:12:24:

The examples still use new() without autocheck=>0, and then check $mech->success for 
success/failure. Without autocheck=>0, these examples will simply die and never get to the 
test.

</issue_description>

Comments on the Issue (you are @copilot in this section)

@oalders This seems to refer to `Examples.pod`, which probably could use a thorough audit.

Fixes #83


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Update WWW::Mechanize examples for autocheck usage Fix autocheck usage in Examples.pod to prevent premature death Oct 24, 2025
Copilot finished work on behalf of oalders October 24, 2025 04:15
Copilot AI requested a review from oalders October 24, 2025 04:15
@haarg
Copy link
Member

haarg commented Oct 24, 2025

Seems like it would be better to just remove the ->success check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WWW::Mechanize::Examples and autocheck [rt.cpan.org #76714]

3 participants