line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Extract packages provided/required by a distribution archive |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Pinto::PackageExtractor; |
4
|
|
|
|
|
|
|
|
5
|
51
|
|
|
51
|
|
344
|
use Moose; |
|
51
|
|
|
|
|
113
|
|
|
51
|
|
|
|
|
399
|
|
6
|
51
|
|
|
51
|
|
328811
|
use MooseX::StrictConstructor; |
|
51
|
|
|
|
|
120
|
|
|
51
|
|
|
|
|
466
|
|
7
|
51
|
|
|
51
|
|
153745
|
use MooseX::MarkAsMethods ( autoclean => 1 ); |
|
51
|
|
|
|
|
120
|
|
|
51
|
|
|
|
|
454
|
|
8
|
|
|
|
|
|
|
|
9
|
51
|
|
|
51
|
|
171869
|
use Try::Tiny; |
|
51
|
|
|
|
|
132
|
|
|
51
|
|
|
|
|
3521
|
|
10
|
51
|
|
|
51
|
|
18788
|
use Dist::Metadata; |
|
51
|
|
|
|
|
77941
|
|
|
51
|
|
|
|
|
1451
|
|
11
|
|
|
|
|
|
|
|
12
|
51
|
|
|
51
|
|
358
|
use Pinto::Types qw(File Dir); |
|
51
|
|
|
|
|
117
|
|
|
51
|
|
|
|
|
484
|
|
13
|
51
|
|
|
51
|
|
310486
|
use Pinto::Util qw(debug throw whine); |
|
51
|
|
|
|
|
115
|
|
|
51
|
|
|
|
|
3158
|
|
14
|
51
|
|
|
51
|
|
17322
|
use Pinto::ArchiveUnpacker; |
|
51
|
|
|
|
|
188
|
|
|
51
|
|
|
|
|
51066
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.13'; # VERSION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has archive => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => File, |
25
|
|
|
|
|
|
|
required => 1, |
26
|
|
|
|
|
|
|
coerce => 1, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has unpacker => ( |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
isa => 'Pinto::ArchiveUnpacker', |
32
|
|
|
|
|
|
|
default => sub { Pinto::ArchiveUnpacker->new( archive => $_[0]->archive ) }, |
33
|
|
|
|
|
|
|
init_arg => undef, |
34
|
|
|
|
|
|
|
lazy => 1, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has work_dir => ( |
38
|
|
|
|
|
|
|
is => 'ro', |
39
|
|
|
|
|
|
|
isa => Dir, |
40
|
|
|
|
|
|
|
default => sub { $_[0]->unpacker->unpack }, |
41
|
|
|
|
|
|
|
init_arg => undef, |
42
|
|
|
|
|
|
|
lazy => 1, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has dm => ( |
46
|
|
|
|
|
|
|
is => 'ro', |
47
|
|
|
|
|
|
|
isa => 'Dist::Metadata', |
48
|
|
|
|
|
|
|
default => sub { Dist::Metadata->new( dir => $_[0]->work_dir, include_inner_packages => 1 ) }, |
49
|
|
|
|
|
|
|
init_arg => undef, |
50
|
|
|
|
|
|
|
lazy => 1, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub provides { |
56
|
161
|
|
|
161
|
0
|
512
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
161
|
|
|
|
|
5238
|
my $archive = $self->archive; |
59
|
161
|
|
|
|
|
643
|
my $basename = $archive->basename; |
60
|
161
|
|
|
|
|
1626
|
debug "Extracting packages provided by archive $basename"; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $mod_info = try { |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Some modules get their VERSION by loading some other |
65
|
|
|
|
|
|
|
# module from lib/. So make sure that lib/ is in @INC |
66
|
161
|
|
|
161
|
|
13371
|
my $lib_dir = $self->work_dir->subdir('lib'); |
67
|
161
|
|
|
|
|
9486
|
local @INC = ( $lib_dir->stringify, @INC ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# TODO: Run this under Safe to protect ourselves |
70
|
|
|
|
|
|
|
# from evil. See ANDK/pause/pmfile.pm for example |
71
|
161
|
|
|
|
|
12943
|
$self->dm->module_info; # returned from try{} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
catch { |
74
|
0
|
|
|
0
|
|
0
|
throw "Unable to extract packages from $basename: $_"; |
75
|
161
|
|
|
|
|
2086
|
}; |
76
|
|
|
|
|
|
|
|
77
|
161
|
|
|
|
|
2062835
|
my @provides; |
78
|
161
|
|
|
|
|
704
|
for my $package ( sort keys %{$mod_info} ) { |
|
161
|
|
|
|
|
1309
|
|
79
|
|
|
|
|
|
|
|
80
|
194
|
|
|
|
|
766
|
my $info = $mod_info->{$package}; |
81
|
194
|
|
|
|
|
2008
|
my $version = version->parse( $info->{version} ); |
82
|
194
|
|
|
|
|
5119
|
debug "Archive $basename provides: $package-$version"; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
push @provides, { |
85
|
|
|
|
|
|
|
name => $package, |
86
|
|
|
|
|
|
|
version => $version, |
87
|
|
|
|
|
|
|
file => $info->{file}, |
88
|
194
|
|
|
|
|
1570
|
}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
161
|
|
|
|
|
1512
|
@provides = $self->__apply_workarounds(@provides); |
92
|
|
|
|
|
|
|
|
93
|
161
|
50
|
|
|
|
777
|
whine "$basename contains no packages and will not be in the index" |
94
|
|
|
|
|
|
|
if not @provides; |
95
|
|
|
|
|
|
|
|
96
|
161
|
|
|
|
|
1692
|
return @provides; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub requires { |
102
|
161
|
|
|
161
|
0
|
685
|
my ($self) = @_; |
103
|
|
|
|
|
|
|
|
104
|
161
|
|
|
|
|
5025
|
my $archive = $self->archive; |
105
|
161
|
|
|
|
|
1152
|
debug "Extracting packages required by archive $archive"; |
106
|
|
|
|
|
|
|
|
107
|
161
|
|
|
161
|
|
19423
|
my $prereqs_meta = try { $self->dm->meta->prereqs } |
108
|
161
|
|
|
0
|
|
3413
|
catch { throw "Unable to extract prereqs from $archive: $_" }; |
|
0
|
|
|
|
|
0
|
|
109
|
|
|
|
|
|
|
|
110
|
161
|
|
|
|
|
9646
|
my @prereqs; |
111
|
161
|
|
|
|
|
463
|
for my $phase ( keys %{$prereqs_meta} ) { |
|
161
|
|
|
|
|
1124
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# TODO: Also capture the relation (suggested, requires, recomends, etc.) |
114
|
|
|
|
|
|
|
# But that will require a schema change to add another column to the table. |
115
|
|
|
|
|
|
|
|
116
|
58
|
|
50
|
|
|
381
|
my $prereqs_for_phase = $prereqs_meta->{$phase} || {}; |
117
|
58
|
|
50
|
|
|
360
|
my $required_prereqs = $prereqs_for_phase->{requires} || {}; |
118
|
|
|
|
|
|
|
|
119
|
58
|
|
|
|
|
181
|
for my $package ( sort keys %{$required_prereqs} ) { |
|
58
|
|
|
|
|
345
|
|
120
|
|
|
|
|
|
|
|
121
|
68
|
|
|
|
|
284
|
my $version = $required_prereqs->{$package}; |
122
|
68
|
|
|
|
|
417
|
debug "Archive $archive requires ($phase): $package~$version"; |
123
|
|
|
|
|
|
|
|
124
|
68
|
|
|
|
|
670
|
push @prereqs, { |
125
|
|
|
|
|
|
|
name => $package, |
126
|
|
|
|
|
|
|
version => $version, |
127
|
|
|
|
|
|
|
phase => $phase, |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
161
|
|
|
|
|
848
|
my $base = $archive->basename; |
134
|
|
|
|
|
|
|
|
135
|
161
|
50
|
|
|
|
1647
|
whine "$base appears to be a bundle. Prereqs for bundles cannot be determined automatically" |
136
|
|
|
|
|
|
|
if $base =~ m/^ Bundle- /x; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# whine "$base uses dynamic configuration so prereqs may be incomplete" |
139
|
|
|
|
|
|
|
# if $self->dm->meta->dynamic_config; |
140
|
|
|
|
|
|
|
|
141
|
161
|
|
|
|
|
1070
|
return @prereqs; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub metadata { |
147
|
161
|
|
|
161
|
0
|
559
|
my ($self) = @_; |
148
|
|
|
|
|
|
|
|
149
|
161
|
|
|
|
|
5649
|
my $archive = $self->archive; |
150
|
161
|
|
|
|
|
1001
|
debug "Extracting metadata from archive $archive"; |
151
|
|
|
|
|
|
|
|
152
|
161
|
|
|
81
|
|
2144
|
my $metadata = try { $self->dm->meta } catch { throw "Unable to extract metadata from $archive: $_" }; |
|
161
|
|
|
47
|
|
12930
|
|
|
0
|
|
|
|
|
0
|
|
153
|
|
|
|
|
|
|
|
154
|
161
|
|
|
|
|
4216
|
return $metadata; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
#============================================================================= |
158
|
|
|
|
|
|
|
# TODO: Generalize these workarounds and/or move them into a separate module |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub __apply_workarounds { |
161
|
161
|
|
|
161
|
|
898
|
my ($self, @provides) = @_; |
162
|
|
|
|
|
|
|
|
163
|
161
|
50
|
|
|
|
8329
|
return $self->__common_sense_workaround(@provides) |
164
|
|
|
|
|
|
|
if $self->archive->basename =~ m/^ common-sense /x; |
165
|
|
|
|
|
|
|
|
166
|
161
|
50
|
|
|
|
6559
|
return $self->__fcgi_workaround(@provides) |
167
|
|
|
|
|
|
|
if $self->archive->basename =~ m/^ FCGI-\d /x; |
168
|
|
|
|
|
|
|
|
169
|
161
|
|
|
|
|
1719
|
return @provides; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub __common_sense_workaround { |
175
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
my ($version) = ( $self->archive->basename =~ m/common-sense- ([\d_.]+) \.tar\.gz/x ); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
return { |
180
|
0
|
|
|
|
|
|
name => 'common::sense', |
181
|
|
|
|
|
|
|
file => 'sense.pm.PL', |
182
|
|
|
|
|
|
|
version => version->parse($version), |
183
|
|
|
|
|
|
|
}; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub __fcgi_workaround { |
189
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
my ($version) = ( $self->archive->basename =~ m/FCGI- ([\d_.]+) \.tar\.gz/x ); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
return { |
194
|
0
|
|
|
|
|
|
name => 'FCGI', |
195
|
|
|
|
|
|
|
file => 'FCGI.PL', |
196
|
|
|
|
|
|
|
version => version->parse($version), |
197
|
|
|
|
|
|
|
}; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
1; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
__END__ |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=pod |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=encoding UTF-8 |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=for :stopwords Jeffrey Ryan Thalhammer |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 NAME |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Pinto::PackageExtractor - Extract packages provided/required by a distribution archive |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 VERSION |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
version 0.13 |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 AUTHOR |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@stratopan.com> |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
233
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=cut |