Skip to content

Commit

Permalink
Remove the duplicate "ua" attribute:
Browse files Browse the repository at this point in the history
Instead of having two attributes, the BUILDARGS introduced will
create a MetaCPAN::Client::Request *always*, and will optionally
use a "ua" parameter sent to ->new().

Also, the "ua" method from MetaCPAN::Client::Request will be curried
with 'handles' on the attribute, so it can be used as if it's an
actual attribute of the MetaCPAN::Client object.
  • Loading branch information
xsawyerx committed Apr 28, 2014
1 parent cd5212e commit 696bf5a
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/MetaCPAN/Client.pm
Expand Up @@ -18,26 +18,23 @@ use MetaCPAN::Client::ResultSet;

has request => (
is => 'ro',
lazy => 1,
handles => [qw<fetch post ssearch>],
default => sub {
my $self = shift;

return MetaCPAN::Client::Request->new(
( ua => $self->ua ) x !! $self->has_ua,
);
},
);

has ua => (
is => 'ro',
predicate => 'has_ua',
handles => [qw<ua fetch post ssearch>],
);

my @supported_searches = qw<
author distribution favorite module rating release
>;

sub BUILDARGS {
my ( $class, %args ) = @_;

$args{'request'} ||= MetaCPAN::Client::Request->new(
( ua => $args{'ua'} ) x !! $args{'ua'},
);

return \%args;
}

sub author {
my $self = shift;
my $arg = shift;
Expand Down Expand Up @@ -266,6 +263,9 @@ should you have any usage of it.
If provided, L<MetaCPAN::Client::Request> will use the user agent object
instead of the default, which is L<HTTP::Tiny>.
Then it can be used to fetch the user agent object used by
L<MetaCPAN::Client::Request>.
=head1 METHODS
=head2 author
Expand Down

0 comments on commit 696bf5a

Please sign in to comment.