line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyPAN::CLI; |
2
|
1
|
|
|
1
|
|
1154
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
|
|
6
|
use Class::Accessor::Lite new => 1, ro => [qw/ |
6
|
|
|
|
|
|
|
verbose |
7
|
|
|
|
|
|
|
with_packages |
8
|
|
|
|
|
|
|
source_cache_dir |
9
|
|
|
|
|
|
|
index_cache_timeout |
10
|
|
|
|
|
|
|
request_timeout |
11
|
|
|
|
|
|
|
max_retries |
12
|
|
|
|
|
|
|
retry_interval |
13
|
|
|
|
|
|
|
retry_jitter_factor |
14
|
|
|
|
|
|
|
source_urls |
15
|
1
|
|
|
1
|
|
5
|
/]; |
|
1
|
|
|
|
|
2
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
949
|
use Getopt::Long 2.36 (); |
|
1
|
|
|
|
|
10409
|
|
|
1
|
|
|
|
|
57
|
|
18
|
1
|
|
|
1
|
|
628
|
use Pod::Usage qw/pod2usage/; |
|
1
|
|
|
|
|
56137
|
|
|
1
|
|
|
|
|
114
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
10
|
use AnyPAN; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
21
|
1
|
|
|
1
|
|
679
|
use AnyPAN::Merger; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
22
|
1
|
|
|
1
|
|
6
|
use AnyPAN::Agent; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
23
|
1
|
|
|
1
|
|
5
|
use AnyPAN::Source; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
24
|
1
|
|
|
1
|
|
4
|
use AnyPAN::SourceCache; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
25
|
1
|
|
|
1
|
|
4
|
use AnyPAN::RetryPolicy::ExponentialBackoff; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
15
|
|
26
|
1
|
|
|
1
|
|
5
|
use AnyPAN::Merger::Algorithm::PreferLatestVersion; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
27
|
1
|
|
|
1
|
|
434
|
use AnyPAN::Logger::Stderr; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
866
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new_with_argv { |
30
|
0
|
|
|
0
|
0
|
|
my ($class, @argv) = @_; |
31
|
0
|
|
|
|
|
|
my $parser = $class->create_option_parser(); |
32
|
0
|
|
|
|
|
|
my @specs = $class->create_option_specs(); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my %opts; |
35
|
0
|
0
|
|
|
|
|
$parser->getoptionsfromarray(\@argv, \%opts, @specs) |
36
|
|
|
|
|
|
|
or pod2usage(1); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my %args = $class->convert_options(\%opts, \@argv); |
39
|
0
|
|
|
|
|
|
return $class->new(%args); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub create_option_parser { |
43
|
0
|
|
|
0
|
0
|
|
my $parser = Getopt::Long::Parser->new(); |
44
|
0
|
|
|
|
|
|
$parser->configure(qw/posix_default no_ignore_case bundling auto_help/); |
45
|
0
|
|
|
|
|
|
return $parser; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub create_option_specs { |
49
|
0
|
|
|
0
|
0
|
|
return qw/ |
50
|
|
|
|
|
|
|
verbose|v+ |
51
|
|
|
|
|
|
|
with-packages |
52
|
|
|
|
|
|
|
source-cache-dir=s |
53
|
|
|
|
|
|
|
index-cache-timeout=i |
54
|
|
|
|
|
|
|
request-timeout=i |
55
|
|
|
|
|
|
|
max-retries=i |
56
|
|
|
|
|
|
|
retry-interval=f |
57
|
|
|
|
|
|
|
retry-jitter-factor=f |
58
|
|
|
|
|
|
|
/; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub convert_options { |
62
|
0
|
|
|
0
|
0
|
|
my ($class, $opts, $argv) = @_; |
63
|
|
|
|
|
|
|
return ( |
64
|
|
|
|
|
|
|
verbose => $opts->{'verbose'} || 0, |
65
|
|
|
|
|
|
|
with_packages => $opts->{'with-packages'} || 0, |
66
|
|
|
|
|
|
|
source_cache_dir => $opts->{'source-cache-dir'} || $AnyPAN::Merger::DEFAULT_SOURCE_CACHE_DIR, |
67
|
|
|
|
|
|
|
index_cache_timeout => $opts->{'index-cache-timeout'} || $AnyPAN::Merger::DEFAULT_SOURCE_INDEX_CACHE_TIMEOUT, |
68
|
|
|
|
|
|
|
request_timeout => $opts->{'request-timeout'} || $AnyPAN::Merger::DEFAULT_REQUEST_TIMEOUT, |
69
|
|
|
|
|
|
|
max_retries => $opts->{'max-retries'} || $AnyPAN::Merger::DEFAULT_RETRY_POLICY->max_retries, |
70
|
|
|
|
|
|
|
retry_interval => $opts->{'retry-interval'} || $AnyPAN::Merger::DEFAULT_RETRY_POLICY->interval, |
71
|
0
|
|
0
|
|
|
|
retry_jitter_factor => $opts->{'retry-jitter-factor'} || $AnyPAN::Merger::DEFAULT_RETRY_POLICY->jitter_factor, |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
72
|
|
|
|
|
|
|
source_urls => $argv, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub run { |
77
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $logger = $self->create_logger(); |
80
|
0
|
|
|
|
|
|
my $retry_policy = $self->create_retry_policy(); |
81
|
0
|
|
|
|
|
|
my $agent = $self->create_agent(logger => $logger, retry_policy => $retry_policy); |
82
|
0
|
|
|
|
|
|
my $source_cache = $self->create_source_cache(logger => $logger, agent => $agent); |
83
|
0
|
|
|
|
|
|
my $algorithm = $self->create_algorithm(source_cache => $source_cache); |
84
|
0
|
|
|
|
|
|
my $storage = $self->create_storage(); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $merger = AnyPAN::Merger->new(); |
87
|
0
|
|
|
|
|
|
for my $source_url (@{ $self->source_urls }) { |
|
0
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$merger->add_source($source_url); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $index = $merger->merge($algorithm); |
92
|
0
|
0
|
|
|
|
|
if ($self->with_packages) { |
93
|
0
|
|
|
|
|
|
$index->save_with_included_packages($storage); |
94
|
|
|
|
|
|
|
} else { |
95
|
0
|
|
|
|
|
|
$index->save($storage); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub create_logger { |
100
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
my $logger = AnyPAN::Logger::Stderr->new( |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
103
|
|
|
|
|
|
|
level => $self->verbose == 0 ? 'warn' |
104
|
|
|
|
|
|
|
: $self->verbose == 1 ? 'info' |
105
|
|
|
|
|
|
|
: $self->verbose >= 2 ? 'debug' |
106
|
|
|
|
|
|
|
: 'warn' |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return $logger; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub create_retry_policy { |
113
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $retry_policy = AnyPAN::RetryPolicy::ExponentialBackoff->new( |
116
|
|
|
|
|
|
|
max_retries => $self->max_retries, |
117
|
|
|
|
|
|
|
interval => $self->retry_interval, |
118
|
|
|
|
|
|
|
jitter_factor => $self->retry_jitter_factor, |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return $retry_policy; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub create_agent { |
125
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $agent = AnyPAN::Agent->new( |
128
|
|
|
|
|
|
|
agent => "AnyPAN/$AnyPAN::VERSION", |
129
|
|
|
|
|
|
|
timeout => $self->request_timeout, |
130
|
|
|
|
|
|
|
logger => $args{logger}, |
131
|
|
|
|
|
|
|
retry_policy => $args{retry_policy}, |
132
|
0
|
|
|
|
|
|
); |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return $agent; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub create_source_cache { |
138
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my $source_cache = AnyPAN::SourceCache->new( |
141
|
|
|
|
|
|
|
cache_dir => $self->source_cache_dir, |
142
|
|
|
|
|
|
|
index_cache_timeout => $self->index_cache_timeout, |
143
|
|
|
|
|
|
|
agent => $args{agent}, |
144
|
|
|
|
|
|
|
logger => $args{logger}, |
145
|
0
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return $source_cache; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub create_algorithm { |
151
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $algorithm = AnyPAN::Merger::Algorithm::PreferLatestVersion->new(%args); |
154
|
0
|
|
|
|
|
|
return $algorithm; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
0
|
0
|
|
sub create_storage { require Carp; Carp::croak('abstruct method') } |
|
0
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
1; |
160
|
|
|
|
|
|
|
__END__ |