line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::MirrorMerger; |
2
|
2
|
|
|
2
|
|
1108
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
49
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
70
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.06"; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
399
|
use Class::Accessor::Lite ro => [qw/mirrors/]; |
|
2
|
|
|
|
|
1012
|
|
|
2
|
|
|
|
|
9
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
134
|
use File::Spec; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
101
|
|
10
|
2
|
|
|
2
|
|
672
|
use Path::Tiny (); |
|
2
|
|
|
|
|
9103
|
|
|
2
|
|
|
|
|
42
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
733
|
use CPAN::MirrorMerger::Agent; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
13
|
2
|
|
|
2
|
|
649
|
use CPAN::MirrorMerger::Mirror; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
80
|
|
14
|
2
|
|
|
2
|
|
711
|
use CPAN::MirrorMerger::MirrorCache; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
94
|
|
15
|
2
|
|
|
2
|
|
822
|
use CPAN::MirrorMerger::RetryPolicy; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
54
|
|
16
|
2
|
|
|
2
|
|
11
|
use CPAN::MirrorMerger::Logger::Null; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
34
|
|
17
|
2
|
|
|
2
|
|
742
|
use CPAN::MirrorMerger::Algorithm::PreferLatestVersion; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
640
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $DEFAULT_LOGGER = CPAN::MirrorMerger::Logger::Null->instance(); |
20
|
|
|
|
|
|
|
our $DEFAULT_RETRY_POLICY = CPAN::MirrorMerger::RetryPolicy->new( |
21
|
|
|
|
|
|
|
max_retries => 5, |
22
|
|
|
|
|
|
|
interval => 1, |
23
|
|
|
|
|
|
|
jitter_factor => 0.05, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
our $DEFAULT_REQUEST_TIMEOUT = 30; |
26
|
|
|
|
|
|
|
our $DEFAULT_MIRROR_CACHE_DIR = File::Spec->catdir(File::Spec->tmpdir(), 'CPAN-MirrorMerger'); |
27
|
|
|
|
|
|
|
our $DEFAULT_MIRROR_INDEX_CACHE_TIMEOUT = 300; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
1
|
|
|
1
|
0
|
8815
|
my ($class, %args) = @_; |
31
|
1
|
|
|
|
|
6
|
bless { |
32
|
|
|
|
|
|
|
mirrors => [], |
33
|
|
|
|
|
|
|
} => $class; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub add_mirror { |
37
|
3
|
|
|
3
|
0
|
141
|
my ($self, $mirror_url) = @_; |
38
|
3
|
|
|
|
|
13
|
my $mirror = CPAN::MirrorMerger::Mirror->new($mirror_url); |
39
|
3
|
|
|
|
|
6
|
push @{ $self->{mirrors} } => $mirror; |
|
3
|
|
|
|
|
13
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub merge { |
43
|
1
|
|
|
1
|
0
|
425
|
my ($self, $algorithm) = @_; |
44
|
1
|
|
33
|
|
|
6
|
$algorithm ||= _get_default_algorithm(); |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
2
|
return $algorithm->merge(@{ $self->mirrors }); |
|
1
|
|
|
|
|
4
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _get_default_algorithm { |
50
|
1
|
|
|
1
|
|
5
|
return CPAN::MirrorMerger::Algorithm::PreferLatestVersion->new( |
51
|
|
|
|
|
|
|
mirror_cache => _get_default_mirror_cache(), |
52
|
|
|
|
|
|
|
logger => $DEFAULT_LOGGER, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _get_default_mirror_cache { |
57
|
1
|
|
|
1
|
|
4
|
return CPAN::MirrorMerger::MirrorCache->new( |
58
|
|
|
|
|
|
|
cache_dir => $DEFAULT_MIRROR_CACHE_DIR, |
59
|
|
|
|
|
|
|
index_cache_timeout => $DEFAULT_MIRROR_INDEX_CACHE_TIMEOUT, |
60
|
|
|
|
|
|
|
agent => _get_default_agent(), |
61
|
|
|
|
|
|
|
logger => $DEFAULT_LOGGER, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _get_default_agent { |
66
|
1
|
|
|
1
|
|
11
|
return CPAN::MirrorMerger::Agent->new( |
67
|
|
|
|
|
|
|
agent => __PACKAGE__."/$VERSION", |
68
|
|
|
|
|
|
|
timeout => $DEFAULT_REQUEST_TIMEOUT, |
69
|
|
|
|
|
|
|
logger => $DEFAULT_LOGGER, |
70
|
|
|
|
|
|
|
retry_policy => $DEFAULT_RETRY_POLICY, |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
__END__ |