Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #650 from metacpan/mickey/use_existing_ua
Use the existing ua object
  • Loading branch information
oalders committed May 15, 2017
2 parents 94f053f + 0cf97af commit c0e85c5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
2 changes: 2 additions & 0 deletions lib/MetaCPAN/Role/Script.pm
Expand Up @@ -148,6 +148,8 @@ sub _build_ua {
: $ua->proxy( [qw<http https>], $proxy );
}

$ua->agent('MetaCPAN');

return $ua;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/MetaCPAN/Script/CPANTesters.pm
Expand Up @@ -8,7 +8,6 @@ use File::Spec::Functions qw(catfile);
use File::Temp qw(tempdir);
use File::stat qw(stat);
use IO::Uncompress::Bunzip2 qw(bunzip2);
use LWP::UserAgent ();
use Log::Contextual qw( :log :dlog );
use MetaCPAN::Types qw( Bool File Uri );
use Moose;
Expand Down Expand Up @@ -75,12 +74,11 @@ sub index_reports {
my $self = shift;

my $es = $self->model->es;
my $ua = LWP::UserAgent->new;

log_info { 'Mirroring ' . $self->db };
my $db = $self->mirror_file;

$ua->mirror( $self->db, "$db.bz2" ) unless $self->skip_download;
$self->ua->mirror( $self->db, "$db.bz2" ) unless $self->skip_download;

if ( -e $db && stat($db)->mtime >= stat("$db.bz2")->mtime ) {
log_info {'DB hasn\'t been modified'};
Expand Down
2 changes: 0 additions & 2 deletions lib/MetaCPAN/Script/Mirrors.pm
Expand Up @@ -4,7 +4,6 @@ use strict;
use warnings;

use Cpanel::JSON::XS ();
use LWP::UserAgent;
use Log::Contextual qw( :log :dlog );
use MetaCPAN::Document::Mirror;
use Moose;
Expand All @@ -19,7 +18,6 @@ sub run {

sub index_mirrors {
my $self = shift;
my $ua = LWP::UserAgent->new;
log_info { 'Getting mirrors.json file from ' . $self->cpan };

my $json = $self->cpan->file( 'indices', 'mirrors.json' )->slurp;
Expand Down
12 changes: 4 additions & 8 deletions lib/MetaCPAN/Script/Release.pm
Expand Up @@ -10,7 +10,6 @@ BEGIN {
use CPAN::DistnameInfo ();
use File::Find::Rule;
use File::stat ();
use LWP::UserAgent;
use Log::Contextual qw( :log :dlog );
use MetaCPAN::Util;
use MetaCPAN::Model::Release;
Expand Down Expand Up @@ -112,15 +111,12 @@ sub run {
MetaCPAN::Util::author_dir( $d->cpanid ),
$d->filename,
);
my $ua = LWP::UserAgent->new(
parse_head => 0,
env_proxy => 1,
agent => 'metacpan',
timeout => 30,
);
$file->dir->mkpath;
log_info {"Downloading $_"};
$ua->mirror( $_, $file );

$self->ua->parse_head(0);
$self->ua->timeout(30);
$self->ua->mirror( $_, $file );
if ( -e $file ) {
push( @files, $file );
}
Expand Down
10 changes: 2 additions & 8 deletions lib/MetaCPAN/Script/River.pm
Expand Up @@ -5,7 +5,6 @@ use namespace::autoclean;

use Cpanel::JSON::XS qw( decode_json );
use Log::Contextual qw( :log :dlog );
use LWP::UserAgent ();
use MetaCPAN::Types qw( ArrayRef Str Uri);

with 'MetaCPAN::Role::Script', 'MooseX::Getopt';
Expand All @@ -18,12 +17,6 @@ has river_url => (
default => 'http://neilb.org/river-of-cpan.json.gz',
);

has _ua => (
is => 'ro',
isa => 'LWP::UserAgent',
default => sub { LWP::UserAgent->new( agent => 'MetaCPAN' ) },
);

sub run {
my $self = shift;
my $summaries = $self->retrieve_river_summaries;
Expand All @@ -49,7 +42,8 @@ sub index_river_summaries {

sub retrieve_river_summaries {
my $self = shift;
my $resp = $self->_ua->get( $self->river_url );

my $resp = $self->ua->get( $self->river_url );

$self->handle_error( $resp->status_line ) unless $resp->is_success;

Expand Down

0 comments on commit c0e85c5

Please sign in to comment.