line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# perl::module Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Perl::Module; |
7
|
1
|
|
|
1
|
|
515
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Shell::Command); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
446
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable build test install cpan cpanm) ], |
16
|
|
|
|
|
|
|
commands => { |
17
|
|
|
|
|
|
|
build => [ qw(directory|OPTIONAL) ], |
18
|
|
|
|
|
|
|
test => [ qw(directory|OPTIONAL) ], |
19
|
|
|
|
|
|
|
install => [ qw(module|$module_list|directory|OPTIONAL) ], |
20
|
|
|
|
|
|
|
dist => [ qw(directory|OPTIONAL) ], |
21
|
|
|
|
|
|
|
clean => [ qw(directory|OPTIONAL) ], |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
attributes => { |
24
|
|
|
|
|
|
|
use_test => [ qw(0|1) ], |
25
|
|
|
|
|
|
|
use_sudo => [ qw(0|1) ], |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
attributes_default => { |
28
|
|
|
|
|
|
|
use_test => 0, |
29
|
|
|
|
|
|
|
use_sudo => 1, |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
require_binaries => { |
32
|
|
|
|
|
|
|
'cpanm' => [ ], |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub build { |
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
my ($directory) = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
0
|
|
|
|
my $cwd = defined($self->shell) && $self->shell->pwd || '/tmp'; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
0
|
|
|
|
$directory ||= ''; |
44
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
45
|
0
|
0
|
|
|
|
|
$self->brik_help_run_directory_not_found('build', $directory) or return; |
46
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
47
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($directory) or return; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
0
|
0
|
|
|
|
|
chdir($directory) or return $self->log->error("build: chdir: $!"); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my @cmd = (); |
55
|
0
|
0
|
|
|
|
|
if (-f 'Build.PL') { |
|
|
0
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
@cmd = ( 'perl Build.PL', 'perl Build' ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif (-f 'Makefile.PL') { |
59
|
0
|
|
|
|
|
|
@cmd = ( 'perl Makefile.PL', 'make' ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
63
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
64
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($cwd) or return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
0
|
0
|
|
|
|
|
chdir($cwd) or return $self->log->error("build: chdir: $!"); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
return $self->log->error("build: neither Build.PL nor Makefile.PL were found, abort"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $r; |
74
|
0
|
|
|
|
|
|
$self->use_sudo(0); |
75
|
0
|
|
|
|
|
|
for (@cmd) { |
76
|
0
|
0
|
|
|
|
|
$r = $self->execute($_) or last; # Abord if one cmd failed |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
$self->use_sudo(1); |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
81
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
82
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($cwd) or return; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
0
|
0
|
|
|
|
|
chdir($cwd) or return $self->log->error("build: chdir: $!"); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $r; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub test { |
93
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
94
|
0
|
|
|
|
|
|
my ($directory) = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
0
|
|
|
|
my $cwd = defined($self->shell) && $self->shell->pwd || '/tmp'; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
0
|
|
|
|
$directory ||= ''; |
99
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
100
|
0
|
0
|
|
|
|
|
$self->brik_help_run_directory_not_found('test', $directory) or return; |
101
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
102
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($directory) or return; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
0
|
0
|
|
|
|
|
chdir($directory) or return $self->log->error("test: chdir: $!"); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my $cmd; |
110
|
0
|
0
|
|
|
|
|
if (-f 'Build') { |
|
|
0
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
$cmd = 'perl Build test'; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
elsif (-f 'Makefile') { |
114
|
0
|
|
|
|
|
|
$cmd = 'make test'; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else { |
117
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
118
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
119
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($cwd) or return; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
0
|
0
|
|
|
|
|
chdir($cwd) or return $self->log->error("test: chdir: $!"); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
0
|
|
|
|
|
|
return $self->log->error("test: neither Build nor Makefile were found, abort"); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$self->use_sudo(0); |
129
|
0
|
|
|
|
|
|
my $r = $self->execute($cmd); |
130
|
0
|
|
|
|
|
|
$self->use_sudo(1); |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
133
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
134
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($cwd) or return; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else { |
137
|
0
|
0
|
|
|
|
|
chdir($cwd) or return $self->log->error("test: chdir: $!"); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return $r; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub install { |
145
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
146
|
0
|
|
|
|
|
|
my ($module) = @_; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
0
|
|
|
|
my $cwd = defined($self->shell) && $self->shell->pwd || '/tmp'; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
my $cmd; |
151
|
0
|
0
|
0
|
|
|
|
if ((defined($module) && -d $module) || (! defined($module))) { |
|
|
|
0
|
|
|
|
|
152
|
0
|
|
0
|
|
|
|
my $directory = $module || ''; # We consider there is only one arg: the directory where |
153
|
|
|
|
|
|
|
# to find the module to install |
154
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
155
|
0
|
0
|
|
|
|
|
$self->brik_help_run_directory_not_found('install', $directory) or return; |
156
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
157
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($directory) or return; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
else { |
160
|
0
|
0
|
|
|
|
|
chdir($directory) or return $self->log->error("install: chdir: $!"); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
|
|
|
if (-f 'Build') { |
|
|
0
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$cmd = 'perl Build install'; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
elsif (-f 'Makefile') { |
168
|
0
|
|
|
|
|
|
$cmd = 'make install'; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
172
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
173
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($cwd) or return; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
else { |
176
|
0
|
0
|
|
|
|
|
chdir($cwd) or return $self->log->error("install: chdir: $!"); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
0
|
|
|
|
|
|
return $self->log->error("install: neither Build nor Makefile were found, abort"); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
else { |
183
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('install', $module, 'ARRAY', 'SCALAR') |
184
|
|
|
|
|
|
|
or return; |
185
|
|
|
|
|
|
|
|
186
|
0
|
0
|
|
|
|
|
$cmd = $self->use_test ? 'cpanm' : 'cpanm -n'; |
187
|
0
|
0
|
|
|
|
|
if ($ref eq 'ARRAY') { |
188
|
0
|
|
|
|
|
|
$cmd = join(' ', $cmd, @$module); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
else { |
191
|
0
|
|
|
|
|
|
$cmd = join(' ', $cmd, $module); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
my $r = $self->execute($cmd); |
196
|
|
|
|
|
|
|
|
197
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
198
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($cwd) or return; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
else { |
201
|
0
|
0
|
|
|
|
|
chdir($cwd) or return $self->log->error("install: chdir: $!"); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
return $r; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub dist { |
208
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
209
|
0
|
|
|
|
|
|
my ($directory) = @_; |
210
|
|
|
|
|
|
|
|
211
|
0
|
|
0
|
|
|
|
my $cwd = defined($self->shell) && $self->shell->pwd || '/tmp'; |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
0
|
|
|
|
$directory ||= ''; |
214
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
215
|
0
|
0
|
|
|
|
|
$self->brik_help_run_directory_not_found('dist', $directory) or return; |
216
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
217
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($directory) or return; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
else { |
220
|
0
|
0
|
|
|
|
|
chdir($directory) or return $self->log->error("dist: chdir: $!"); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
my $cmd; |
225
|
0
|
0
|
|
|
|
|
if (-f 'Build') { |
|
|
0
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
$cmd = 'perl Build dist'; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
elsif (-f 'Makefile') { |
229
|
0
|
|
|
|
|
|
$cmd = 'make dist'; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
else { |
232
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
233
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
234
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($cwd) or return; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
else { |
237
|
0
|
0
|
|
|
|
|
chdir($cwd) or return $self->log->error("dist: chdir: $!"); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
} |
240
|
0
|
|
|
|
|
|
return $self->log->error("dist: neither Build nor Makefile were found, abort"); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
0
|
|
|
|
|
|
$self->use_sudo(0); |
244
|
0
|
|
|
|
|
|
my $r = $self->execute($cmd); |
245
|
0
|
|
|
|
|
|
$self->use_sudo(1); |
246
|
|
|
|
|
|
|
|
247
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
248
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
249
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($cwd) or return; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
else { |
252
|
0
|
0
|
|
|
|
|
chdir($cwd) or return $self->log->error("dist: chdir: $!"); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
0
|
|
|
|
|
|
return $r; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub clean { |
260
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
261
|
0
|
|
|
|
|
|
my ($directory) = @_; |
262
|
|
|
|
|
|
|
|
263
|
0
|
|
0
|
|
|
|
my $cwd = defined($self->shell) && $self->shell->pwd || '/tmp'; |
264
|
|
|
|
|
|
|
|
265
|
0
|
|
0
|
|
|
|
$directory ||= ''; |
266
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
267
|
0
|
0
|
|
|
|
|
$self->brik_help_run_directory_not_found('clean', $directory) or return; |
268
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
269
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($directory) or return; |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
else { |
272
|
0
|
0
|
|
|
|
|
chdir($directory) or return $self->log->error("clean: chdir: $!"); |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
0
|
|
|
|
|
|
my $cmd; |
277
|
0
|
0
|
|
|
|
|
if (-f 'Build') { |
|
|
0
|
|
|
|
|
|
278
|
0
|
|
|
|
|
|
$cmd = 'perl Build clean'; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
elsif (-f 'Makefile') { |
281
|
0
|
|
|
|
|
|
$cmd = 'make clean'; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
else { |
284
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
285
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
286
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($cwd) or return; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
else { |
289
|
0
|
0
|
|
|
|
|
chdir($cwd) or return $self->log->error("clean: chdir: $!"); |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
} |
292
|
0
|
|
|
|
|
|
return $self->log->error("clean: neither Build nor Makefile were found, abort"); |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
0
|
|
|
|
|
|
$self->use_sudo(0); |
296
|
0
|
|
|
|
|
|
my $r = $self->execute($cmd); |
297
|
0
|
|
|
|
|
|
$self->use_sudo(1); |
298
|
|
|
|
|
|
|
|
299
|
0
|
0
|
|
|
|
|
if (length($directory)) { |
300
|
0
|
0
|
|
|
|
|
if (defined($self->shell)) { |
301
|
0
|
0
|
|
|
|
|
$self->shell->run_cd($cwd) or return; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
else { |
304
|
0
|
0
|
|
|
|
|
chdir($cwd) or return $self->log->error("clean: chdir: $!"); |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
0
|
|
|
|
|
|
return $r; |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
1; |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
__END__ |