Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content(raw=>1) dies when there is no response #384

Open
mscha opened this issue Nov 22, 2024 · 3 comments
Open

content(raw=>1) dies when there is no response #384

mscha opened this issue Nov 22, 2024 · 3 comments

Comments

@mscha
Copy link

mscha commented Nov 22, 2024

$mech->content(raw=>1) dies when there is no current response, while $mech->content() simply returns undef.
Can you please make $mech->content(raw=>1) (and perhaps other variations that I haven't tested) return undef in such a case as well?

$ perl -MWWW::Mechanize -E 'my $mech = WWW::Mechanize->new; say $mech->content() // "(undef)";'
(undef)

$ perl -MWWW::Mechanize -E 'my $mech = WWW::Mechanize->new; say $mech->content(raw=>1) // "(undef)";'
Can't call method "content" on an undefined value at /opt/perl-5.38/lib/site_perl/5.38.0/WWW/Mechanize.pm line 335.
@oalders
Copy link
Member

oalders commented Nov 22, 2024

That sounds like a reasonable change. I'd be interested to hear from @petdance. My main concern is that even innocuous changes tend to break things in the wild.

The docs do say:

A fresh instance of WWW::Mechanize will return undef when $mech->content() is called, because no content is present before a request has been made.

I guess it's not 100% clear if that means just content() or also content(...).

@petdance
Copy link
Contributor

This looks entirely reasonable to throw in content

    if ( delete $params{raw} ) {
        $content = $self->response()->content();
    }

to

    if ( delete $params{raw} ) {
        my $res = $self->response();
        $content = $res->content() if $res;
    }

@oalders
Copy link
Member

oalders commented Nov 23, 2024

If someone wants to create a PR, I'm happy to release.

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

No branches or pull requests

3 participants