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

Adds failing test to demonstrate that LWP::UserAgent is not currently supported. #15

Closed
wants to merge 1 commit into from

Conversation

oalders
Copy link
Member

@oalders oalders commented Jul 19, 2014

According to the docs, LWP::UserAgent classes should be supported, but that's currently not the case. The reason is that the code is now tightly coupled with HTTP::Tiny.

A typical error might look something like this:

First argument must be hashref
        at Carp::croak(<eval>:12)
        at MetaCPAN::Client::Request::_decode_result(/Users/olaf/perl5/lib/perl5/MetaCPAN/Client/Request.pm:96)
        at MetaCPAN::Client::Request::fetch(/Users/olaf/perl5/lib/perl5/MetaCPAN/Client/Request.pm:62)
        at MetaCPAN::Client::fetch(<eval>:12)
        at MetaCPAN::Client::_get(/Users/olaf/perl5/lib/perl5/MetaCPAN/Client.pm:167)
        at MetaCPAN::Client::_get_or_search(/Users/olaf/perl5/lib/perl5/MetaCPAN/Client.pm:209)
        at MetaCPAN::Client::author(/Users/olaf/perl5/lib/perl5/MetaCPAN/Client.pm:44)

HTTP::Tiny returns a HashRef, but LWP::UserAgent returns a response object.

I realize that this test introduces a dependency which you are likely trying to avoid, but I wanted to demonstrate the issue properly. :)

@xsawyerx
Copy link
Contributor

I understand the test, but I also know that HTTP::Tiny returns a hashref while LWP::UserAgent returns an object. That makes the test superfluous. Do you really want to add it anyway?

I don't know how that piece of docs was introduced, it's clearly wrong. Shouldn't we just fix that than add the test?

@tsibley
Copy link
Contributor

tsibley commented Jul 20, 2014

The docs here already pretty clearly state the need for HTTP::Tiny compat: https://metacpan.org/pod/MetaCPAN::Client::Request#ua

That said, I do think it's useful to support LWP::UserAgent. It has a lot more power than HTTP::Tiny and sometimes that is needed. I'm assuming a shim layer wrapping an LWP::UserAgent object could do most of the API translation work, and obviously could be outside of MetaCPAN::Client itself.

@oalders
Copy link
Member Author

oalders commented Jul 20, 2014

Yeah, but see the SYNOPSIS:

# simple usage
my $mcpan  = MetaCPAN::Client->new();
my $author = $mcpan->author('XSAWYERX');
my $dist   = $mcpan->distribuion('MetaCPAN-Client');

# advanced usage with cache (contributed by Kent Fredric)
use CHI;
use WWW::Mechanize::Cached;
use HTTP::Tiny::Mech;
use MetaCPAN::Client;

my $mcpan = MetaCPAN::Client->new(
  ua => HTTP::Tiny::Mech->new(
    mechua => WWW::Mechanize::Cached->new(
      cache => CHI->new(
        driver   => 'File',
        root_dir => '/tmp/metacpan-cache',
      ),
    ),
  ),
);

That contradicts the HTTP::Tiny compat and actually predates it, since the SYNOPSIS is from MetaCPAN::API. I was thinking of writing a HTTP::Any that would let you provide various UserAgents and would then "do the right thing". The problem here is that the very easy caching method which was previously supported is now broken.

@oalders
Copy link
Member Author

oalders commented Jul 20, 2014

@xsawyerx I'm not fussed about whether the test gets added. I just wanted to demonstrate the problem in a way that makes it easy to address.

@tsibley
Copy link
Contributor

tsibley commented Jul 20, 2014

@oalders Wait, what in the SYNOPSIS is giving LWP to MetaCPAN::Client? The ua is set to an HTTP::Tiny::Mech object which seems like it is supposed to do the ua wrapping.

@oalders
Copy link
Member Author

oalders commented Jul 20, 2014

@tsibley you're right. I stopped reading the SYNOPSIS at ua => ... so I didn't see HTTP::Tiny::Mech. So, I guess that solves it for me. :)

@oalders oalders closed this Jul 20, 2014
@xsawyerx
Copy link
Contributor

That makes more sense.

@tsibley++
@oalders++

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.

None yet

3 participants