line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::MirrorMerger; |
2
|
2
|
|
|
2
|
|
1458
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
58
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
91
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.07"; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
508
|
use Class::Accessor::Lite ro => [qw/mirrors/]; |
|
2
|
|
|
|
|
1232
|
|
|
2
|
|
|
|
|
14
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
171
|
use File::Spec; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
50
|
|
10
|
2
|
|
|
2
|
|
844
|
use Path::Tiny (); |
|
2
|
|
|
|
|
11647
|
|
|
2
|
|
|
|
|
51
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
1013
|
use CPAN::MirrorMerger::Agent; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
68
|
|
13
|
2
|
|
|
2
|
|
818
|
use CPAN::MirrorMerger::Mirror; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
68
|
|
14
|
2
|
|
|
2
|
|
926
|
use CPAN::MirrorMerger::MirrorCache; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
81
|
|
15
|
2
|
|
|
2
|
|
1214
|
use CPAN::MirrorMerger::RetryPolicy; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
67
|
|
16
|
2
|
|
|
2
|
|
14
|
use CPAN::MirrorMerger::Logger::Null; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
42
|
|
17
|
2
|
|
|
2
|
|
913
|
use CPAN::MirrorMerger::Algorithm::PreferLatestVersion; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
780
|
|
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
|
10787
|
my ($class, %args) = @_; |
31
|
1
|
|
|
|
|
7
|
bless { |
32
|
|
|
|
|
|
|
mirrors => [], |
33
|
|
|
|
|
|
|
} => $class; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub add_mirror { |
37
|
3
|
|
|
3
|
0
|
173
|
my ($self, $mirror_url) = @_; |
38
|
3
|
|
|
|
|
16
|
my $mirror = CPAN::MirrorMerger::Mirror->new($mirror_url); |
39
|
3
|
|
|
|
|
8
|
push @{ $self->{mirrors} } => $mirror; |
|
3
|
|
|
|
|
17
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub merge { |
43
|
1
|
|
|
1
|
0
|
616
|
my ($self, $algorithm) = @_; |
44
|
1
|
|
33
|
|
|
8
|
$algorithm ||= _get_default_algorithm(); |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
2
|
return $algorithm->merge(@{ $self->mirrors }); |
|
1
|
|
|
|
|
6
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _get_default_algorithm { |
50
|
1
|
|
|
1
|
|
4
|
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
|
|
14
|
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__ |