line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::MirrorMerger; |
2
|
2
|
|
|
2
|
|
1122
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
48
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
71
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.08"; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
407
|
use Class::Accessor::Lite ro => [qw/mirrors/]; |
|
2
|
|
|
|
|
988
|
|
|
2
|
|
|
|
|
11
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
139
|
use File::Spec; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
42
|
|
10
|
2
|
|
|
2
|
|
671
|
use Path::Tiny (); |
|
2
|
|
|
|
|
9053
|
|
|
2
|
|
|
|
|
37
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
765
|
use CPAN::MirrorMerger::Agent; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
13
|
2
|
|
|
2
|
|
673
|
use CPAN::MirrorMerger::Mirror; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
64
|
|
14
|
2
|
|
|
2
|
|
733
|
use CPAN::MirrorMerger::MirrorCache; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
67
|
|
15
|
2
|
|
|
2
|
|
894
|
use CPAN::MirrorMerger::RetryPolicy; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
53
|
|
16
|
2
|
|
|
2
|
|
11
|
use CPAN::MirrorMerger::Logger::Null; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
34
|
|
17
|
2
|
|
|
2
|
|
743
|
use CPAN::MirrorMerger::Algorithm::PreferLatestVersion; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
633
|
|
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
|
8830
|
my ($class, %args) = @_; |
31
|
1
|
|
|
|
|
6
|
bless { |
32
|
|
|
|
|
|
|
mirrors => [], |
33
|
|
|
|
|
|
|
} => $class; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub add_mirror { |
37
|
3
|
|
|
3
|
0
|
152
|
my ($self, $mirror_url) = @_; |
38
|
3
|
|
|
|
|
13
|
my $mirror = CPAN::MirrorMerger::Mirror->new($mirror_url); |
39
|
3
|
|
|
|
|
7
|
push @{ $self->{mirrors} } => $mirror; |
|
3
|
|
|
|
|
13
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub merge { |
43
|
1
|
|
|
1
|
0
|
538
|
my ($self, $algorithm) = @_; |
44
|
1
|
|
33
|
|
|
5
|
$algorithm ||= _get_default_algorithm(); |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
2
|
return $algorithm->merge(@{ $self->mirrors }); |
|
1
|
|
|
|
|
5
|
|
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
|
|
12
|
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__ |