| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::CPAN::Get; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
160229
|
use strict; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
187
|
|
|
4
|
4
|
|
|
4
|
|
31
|
use warnings; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
204
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
1989
|
use App::CPAN::Get::MetaCPAN; |
|
|
4
|
|
|
|
|
17
|
|
|
|
4
|
|
|
|
|
209
|
|
|
7
|
4
|
|
|
4
|
|
2272
|
use App::CPAN::Get::Utils qw(process_module_name_and_version); |
|
|
4
|
|
|
|
|
18
|
|
|
|
4
|
|
|
|
|
129
|
|
|
8
|
4
|
|
|
4
|
|
285
|
use Class::Utils qw(set_params); |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
229
|
|
|
9
|
4
|
|
|
4
|
|
22
|
use English; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
25
|
|
|
10
|
4
|
|
|
4
|
|
1817
|
use Error::Pure qw(err); |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
218
|
|
|
11
|
4
|
|
|
4
|
|
2074
|
use File::Spec::Functions qw(catfile); |
|
|
4
|
|
|
|
|
3791
|
|
|
|
4
|
|
|
|
|
305
|
|
|
12
|
4
|
|
|
4
|
|
2313
|
use Getopt::Std; |
|
|
4
|
|
|
|
|
9702
|
|
|
|
4
|
|
|
|
|
266
|
|
|
13
|
4
|
|
|
4
|
|
26
|
use LWP::UserAgent; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
111
|
|
|
14
|
4
|
|
|
4
|
|
20
|
use Scalar::Util qw(blessed); |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
3205
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 0.14; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Constructor. |
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
10
|
|
|
10
|
1
|
769495
|
my ($class, @params) = @_; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Create object. |
|
23
|
10
|
|
|
|
|
28
|
my $self = bless {}, $class; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# LWP::User agent object. |
|
26
|
10
|
|
|
|
|
38
|
$self->{'lwp_user_agent'} = undef; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Process parameters. |
|
29
|
10
|
|
|
|
|
80
|
set_params($self, @params); |
|
30
|
|
|
|
|
|
|
|
|
31
|
9
|
100
|
|
|
|
107
|
if (defined $self->{'lwp_user_agent'}) { |
|
32
|
5
|
100
|
100
|
|
|
54
|
if (! blessed($self->{'lwp_user_agent'}) |
|
33
|
|
|
|
|
|
|
|| ! $self->{'lwp_user_agent'}->isa('LWP::UserAgent')) { |
|
34
|
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
56
|
err "Parameter 'lwp_user_agent' must be a ". |
|
36
|
|
|
|
|
|
|
'LWP::UserAgent instance.'; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
} else { |
|
39
|
4
|
|
|
|
|
41
|
$self->{'lwp_user_agent'} = LWP::UserAgent->new; |
|
40
|
4
|
|
|
|
|
8776
|
$self->{'lwp_user_agent'}->agent(__PACKAGE__.'/'.$VERSION); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->{'_cpan'} = App::CPAN::Get::MetaCPAN->new( |
|
44
|
7
|
|
|
|
|
369
|
'lwp_user_agent' => $self->{'lwp_user_agent'}, |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Object. |
|
48
|
7
|
|
|
|
|
63
|
return $self; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Run. |
|
52
|
|
|
|
|
|
|
sub run { |
|
53
|
5
|
|
|
5
|
1
|
7
|
my $self = shift; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Process arguments. |
|
56
|
5
|
|
|
|
|
22
|
$self->{'_opts'} = { |
|
57
|
|
|
|
|
|
|
'f' => 0, |
|
58
|
|
|
|
|
|
|
'h' => 0, |
|
59
|
|
|
|
|
|
|
'o' => undef, |
|
60
|
|
|
|
|
|
|
}; |
|
61
|
5
|
100
|
100
|
|
|
27
|
if (! getopts('fho:', $self->{'_opts'}) |
|
|
|
|
100
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|| $self->{'_opts'}->{'h'} |
|
63
|
|
|
|
|
|
|
|| @ARGV < 1) { |
|
64
|
|
|
|
|
|
|
|
|
65
|
3
|
|
|
|
|
388
|
print STDERR "Usage: $0 [-f] [-h] [-o out_dir] [--version] module_name[module_version]\n"; |
|
66
|
3
|
|
|
|
|
63
|
print STDERR "\t-f\t\tForce download and rewrite of existing file.\n"; |
|
67
|
3
|
|
|
|
|
56
|
print STDERR "\t-h\t\tPrint help.\n"; |
|
68
|
3
|
|
|
|
|
25
|
print STDERR "\t-o out_dir\tOutput directory (default is actual).\n"; |
|
69
|
3
|
|
|
|
|
21
|
print STDERR "\t--version\tPrint version.\n"; |
|
70
|
3
|
|
|
|
|
21
|
print STDERR "\tmodule_name\tModule name. e.g. ". |
|
71
|
|
|
|
|
|
|
"App::Pod::Example\n"; |
|
72
|
3
|
|
|
|
|
21
|
print STDERR "\tmodule_version\tModule version. e.g. \@1.23, ~1.23 etc.\n"; |
|
73
|
3
|
|
|
|
|
14
|
return 1; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
2
|
|
|
|
|
57
|
$self->{'_module_name_and_version'} = shift @ARGV; |
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
50
|
|
|
|
8
|
if (defined $self->{'_opts'}->{'o'}) { |
|
78
|
0
|
0
|
|
|
|
0
|
if (! -d $self->{'_opts'}->{'o'}) { |
|
79
|
0
|
|
|
|
|
0
|
print STDERR "Directory '$self->{'_opts'}->{'o'}' doesn't exist.\n"; |
|
80
|
0
|
|
|
|
|
0
|
return 1; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Parse module name and version. |
|
85
|
|
|
|
|
|
|
($self->{'_module_name'}, $self->{'_module_version_range'}) |
|
86
|
2
|
|
|
|
|
13
|
= process_module_name_and_version($self->{'_module_name_and_version'}); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Search. |
|
89
|
|
|
|
|
|
|
my $search_hr = $self->{'_cpan'}->search({ |
|
90
|
|
|
|
|
|
|
'package' => $self->{'_module_name'}, |
|
91
|
2
|
|
|
|
|
18
|
'version_range' => $self->{'_module_version_range'}, |
|
92
|
|
|
|
|
|
|
}); |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Save. |
|
95
|
1
|
|
|
|
|
7
|
my $download_url = URI->new($search_hr->{'download_url'}); |
|
96
|
1
|
|
|
|
|
92
|
my $file_to_save = ($download_url->path_segments)[-1]; |
|
97
|
1
|
50
|
|
|
|
58
|
if ($self->{'_opts'}->{'o'}) { |
|
98
|
0
|
|
|
|
|
0
|
$file_to_save = catfile($self->{'_opts'}->{'o'}, $file_to_save); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
1
|
|
|
|
|
2
|
eval { |
|
101
|
1
|
|
|
|
|
4
|
$self->{'_cpan'}->save($search_hr->{'download_url'}, $file_to_save, $self->{'_opts'}); |
|
102
|
|
|
|
|
|
|
}; |
|
103
|
1
|
50
|
|
|
|
5
|
if ($EVAL_ERROR) { |
|
104
|
0
|
|
|
|
|
0
|
print $EVAL_ERROR; |
|
105
|
0
|
|
|
|
|
0
|
return 1; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
37
|
print "Package on '$search_hr->{'download_url'}' was downloaded.\n"; |
|
109
|
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
14
|
return 0; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |