line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VCS::Which; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2009-05-16 16:54:35 |
4
|
|
|
|
|
|
|
# Create by: ivan |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
154652
|
use Moo; |
|
2
|
|
|
|
|
23775
|
|
|
2
|
|
|
|
|
11
|
|
10
|
2
|
|
|
2
|
|
3520
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
42
|
|
11
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
51
|
|
12
|
2
|
|
|
2
|
|
1199
|
use version; |
|
2
|
|
|
|
|
4123
|
|
|
2
|
|
|
|
|
11
|
|
13
|
2
|
|
|
2
|
|
181
|
use Carp; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
137
|
|
14
|
2
|
|
|
2
|
|
1419
|
use Data::Dumper qw/Dumper/; |
|
2
|
|
|
|
|
14880
|
|
|
2
|
|
|
|
|
171
|
|
15
|
2
|
|
|
2
|
|
1288
|
use English qw/ -no_match_vars /; |
|
2
|
|
|
|
|
8042
|
|
|
2
|
|
|
|
|
26
|
|
16
|
2
|
|
|
2
|
|
2554
|
use Path::Tiny; |
|
2
|
|
|
|
|
28980
|
|
|
2
|
|
|
|
|
3928
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = version->new('0.6.9'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our %systems; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has [qw/dir systems/] => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
has [qw/_which _uptodate/] => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
default => sub {{}}, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub BUILD { |
31
|
18
|
|
|
18
|
1
|
128
|
my ($self) = @_; |
32
|
|
|
|
|
|
|
|
33
|
18
|
100
|
|
|
|
54
|
if ( !%systems ) { |
34
|
1
|
|
|
|
|
5
|
$self->get_systems(); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
18
|
|
|
|
|
54
|
$self->load_systems(); |
38
|
|
|
|
|
|
|
|
39
|
18
|
100
|
100
|
|
|
303
|
if ( $self->dir && -f $self->dir ) { |
40
|
1
|
|
|
|
|
12
|
$self->dir( path($self->dir)->parent ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
18
|
|
|
|
|
311
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub load_systems { |
47
|
18
|
|
|
18
|
1
|
28
|
my ( $self ) = @_; |
48
|
|
|
|
|
|
|
|
49
|
18
|
|
|
|
|
60
|
for my $module (keys %systems) { |
50
|
90
|
|
|
|
|
8368
|
$self->{systems}{$module} = $module->new; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
18
|
|
|
|
|
1825
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_systems { |
57
|
1
|
|
|
1
|
1
|
3
|
my ($self) = @_; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
3
|
for my $dir (@INC) { |
60
|
10
|
100
|
|
|
|
54
|
if ( $dir !~ /^\/|^\w:\// ) { |
61
|
2
|
|
|
|
|
7
|
$dir = "./$dir"; |
62
|
|
|
|
|
|
|
} |
63
|
10
|
|
|
|
|
630
|
my @files = glob "$dir/VCS/Which/Plugin/*.pm"; |
64
|
|
|
|
|
|
|
|
65
|
10
|
|
|
|
|
43
|
for my $file (@files) { |
66
|
9
|
|
|
|
|
19
|
my $module = $file; |
67
|
9
|
|
|
|
|
93
|
$module =~ s{\Q$dir\E/}{}xms; |
68
|
9
|
|
|
|
|
34
|
$module =~ s{/}{::}gxms; |
69
|
9
|
|
|
|
|
39
|
$module =~ s{[.]pm$}{}xms; |
70
|
|
|
|
|
|
|
|
71
|
9
|
100
|
|
|
|
34
|
next if $systems{$module}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
eval { |
74
|
5
|
|
|
|
|
2408
|
require $file; |
75
|
5
|
50
|
|
|
|
9
|
} or do { |
76
|
0
|
|
|
|
|
0
|
confess $@, "Error with $file / $module"; |
77
|
|
|
|
|
|
|
}; |
78
|
5
|
|
|
|
|
20736
|
$systems{$module} = 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
5
|
return; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub capabilities { |
86
|
3
|
|
|
3
|
1
|
1051
|
my ($self, $dir) = @_; |
87
|
3
|
|
|
|
|
7
|
my $out; |
88
|
|
|
|
|
|
|
my %out; |
89
|
|
|
|
|
|
|
|
90
|
3
|
100
|
|
|
|
7
|
if ($dir) { |
91
|
2
|
|
|
|
|
8
|
$self->dir($dir); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
1
|
|
|
|
|
4
|
$dir = $self->dir; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
4
|
for my $system (values %{ $self->{systems} }) { |
|
3
|
|
|
|
|
12
|
|
98
|
|
|
|
|
|
|
|
99
|
15
|
|
|
|
|
50
|
$out .= $system->name . ' ' x (10 - length $system->name); |
100
|
15
|
100
|
|
|
|
43
|
$out .= $system->installed ? ' installed ' : ' not installed'; |
101
|
15
|
|
|
|
|
46
|
$out{$system->name}{installed} = $system->installed; |
102
|
|
|
|
|
|
|
|
103
|
15
|
100
|
|
|
|
37
|
if ($dir) { |
104
|
10
|
|
|
|
|
14
|
eval { |
105
|
10
|
100
|
|
|
|
25
|
$out .= $system->used($dir) ? ' versioning' : ' not versioning'; |
106
|
10
|
|
|
|
|
31
|
$out{$system->name}{installed} = $system->used($dir); |
107
|
|
|
|
|
|
|
}; |
108
|
10
|
50
|
|
|
|
25
|
if ($EVAL_ERROR) { |
109
|
0
|
|
|
|
|
0
|
warn "$system error in determining if the directory is used: $EVAL_ERROR\n"; |
110
|
0
|
|
|
|
|
0
|
$out .= ' NA'; |
111
|
0
|
|
|
|
|
0
|
$out{$system->name}{installed} = ' NA'; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
15
|
|
|
|
|
25
|
$out .= "\n"; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
3
|
100
|
|
|
|
24
|
return wantarray ? %out : $out; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub which { |
122
|
27
|
|
|
27
|
1
|
896
|
my ( $self, $dir ) = @_; |
123
|
|
|
|
|
|
|
|
124
|
27
|
100
|
|
|
|
53
|
if ($dir) { |
125
|
5
|
|
|
|
|
18
|
$self->dir($dir); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
else { |
128
|
22
|
|
|
|
|
46
|
$dir = $self->dir; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
27
|
100
|
100
|
|
|
336
|
if ( $dir && -f $dir ) { |
132
|
7
|
|
|
|
|
35
|
$dir = $self->dir( path($dir)->parent ); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
27
|
100
|
|
|
|
865
|
confess "No directory supplied!" if !$dir; |
136
|
|
|
|
|
|
|
|
137
|
26
|
100
|
|
|
|
91
|
return $self->_which->{$dir} if exists $self->_which->{$dir}; |
138
|
|
|
|
|
|
|
|
139
|
17
|
|
|
|
|
65
|
$self->_which->{$dir} = undef; |
140
|
17
|
|
|
|
|
42
|
my %used; |
141
|
|
|
|
|
|
|
my $min; |
142
|
|
|
|
|
|
|
|
143
|
17
|
|
|
|
|
25
|
for my $system (values %{ $self->{systems} }) { |
|
17
|
|
|
|
|
64
|
|
144
|
85
|
100
|
|
|
|
120
|
my $used = eval { $system->used($dir) || 0 }; |
|
85
|
|
|
|
|
253
|
|
145
|
85
|
100
|
|
|
|
1340
|
next if $EVAL_ERROR; |
146
|
|
|
|
|
|
|
|
147
|
81
|
100
|
66
|
|
|
179
|
if ( $used && ! defined $min ) { |
148
|
17
|
|
|
|
|
26
|
$min = $used; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# check that the directory is used and that it was found at a level closer to $dir that the last found system |
152
|
81
|
100
|
66
|
|
|
196
|
if ( $used && $used <= $min ) { |
153
|
17
|
|
|
|
|
50
|
$self->_which->{$dir} = $system; |
154
|
17
|
|
|
|
|
45
|
$min = $used; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
17
|
50
|
|
|
|
74
|
confess "Could not work out what plugin to use with '$dir'\n" if !$self->_which->{$dir}; |
159
|
|
|
|
|
|
|
|
160
|
17
|
|
|
|
|
62
|
return $self->_which->{$dir}; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub uptodate { |
164
|
4
|
|
|
4
|
1
|
2037
|
my ( $self, $dir ) = @_; |
165
|
|
|
|
|
|
|
|
166
|
4
|
100
|
|
|
|
12
|
if ($dir) { |
167
|
2
|
|
|
|
|
8
|
$self->dir($dir); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
else { |
170
|
2
|
|
|
|
|
8
|
$dir = $self->dir; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
4
|
100
|
|
|
|
21
|
confess "No directory supplied!" if !$dir; |
174
|
|
|
|
|
|
|
|
175
|
3
|
100
|
|
|
|
16
|
return $self->_uptodate->{$dir} if exists $self->_uptodate->{$dir}; |
176
|
|
|
|
|
|
|
|
177
|
2
|
|
|
|
|
5
|
my $system = $self->which; |
178
|
|
|
|
|
|
|
|
179
|
2
|
|
|
|
|
7
|
return $self->_uptodate->{$dir} = $system->uptodate($dir); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub exec { |
183
|
4
|
|
|
4
|
1
|
1544
|
my ( $self, @args ) = @_; |
184
|
4
|
|
|
|
|
8
|
my $dir; |
185
|
|
|
|
|
|
|
|
186
|
4
|
100
|
|
|
|
22
|
confess "Nothing to exec!" if !@args; |
187
|
|
|
|
|
|
|
|
188
|
3
|
100
|
|
|
|
51
|
if (-e $args[0]) { |
189
|
1
|
|
|
|
|
9
|
$dir = $self->dir( shift @args ); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
else { |
192
|
2
|
|
|
|
|
10
|
$dir = $self->dir; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
3
|
100
|
|
|
|
21
|
confess "No directory supplied!" if !$dir; |
196
|
|
|
|
|
|
|
|
197
|
2
|
|
|
|
|
7
|
my $system = $self->which; |
198
|
|
|
|
|
|
|
|
199
|
2
|
|
|
|
|
8
|
return $system->exec($dir, @args); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub log { |
203
|
5
|
|
|
5
|
1
|
1666
|
my ( $self, $file, @args ) = @_; |
204
|
|
|
|
|
|
|
|
205
|
5
|
100
|
100
|
|
|
84
|
if ( $file && ! -e $file ) { |
206
|
2
|
|
|
|
|
9
|
unshift @args, $file; |
207
|
2
|
|
|
|
|
3
|
undef $file; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
5
|
100
|
|
|
|
44
|
my $dir |
|
|
100
|
|
|
|
|
|
211
|
|
|
|
|
|
|
= !defined $file ? $self->dir |
212
|
|
|
|
|
|
|
: -f $file ? path($file)->parent |
213
|
|
|
|
|
|
|
: $file; |
214
|
|
|
|
|
|
|
|
215
|
5
|
100
|
|
|
|
112
|
confess "No directory supplied!" if !$dir; |
216
|
|
|
|
|
|
|
|
217
|
4
|
|
|
|
|
12
|
my $system = $self->which($dir); |
218
|
|
|
|
|
|
|
|
219
|
4
|
|
|
|
|
24
|
return $system->log($file, @args); |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub cat { |
223
|
5
|
|
|
5
|
1
|
1755
|
my ( $self, $file, @args ) = @_; |
224
|
|
|
|
|
|
|
|
225
|
5
|
100
|
|
|
|
12
|
if ($file) { |
226
|
3
|
|
|
|
|
12
|
$self->dir($file); |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
else { |
229
|
2
|
|
|
|
|
7
|
$file = $self->dir; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
5
|
100
|
|
|
|
25
|
confess "No file supplied!" if !$file; |
233
|
|
|
|
|
|
|
|
234
|
4
|
|
|
|
|
10
|
my $system = $self->which; |
235
|
|
|
|
|
|
|
|
236
|
4
|
|
|
|
|
23
|
return $system->cat($file, @args); |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub versions { |
240
|
3
|
|
|
3
|
1
|
1150
|
my ( $self, $file, @args ) = @_; |
241
|
|
|
|
|
|
|
|
242
|
3
|
100
|
|
|
|
9
|
if ($file) { |
243
|
1
|
|
|
|
|
4
|
$self->dir($file); |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
else { |
246
|
2
|
|
|
|
|
6
|
$file = $self->dir; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
3
|
100
|
|
|
|
23
|
confess "No file supplied!" if !$file; |
250
|
|
|
|
|
|
|
|
251
|
2
|
|
|
|
|
5
|
my $system = $self->which; |
252
|
|
|
|
|
|
|
|
253
|
2
|
|
|
|
|
18
|
return $system->versions($file, @args); |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub pull { |
257
|
3
|
|
|
3
|
1
|
1253
|
my ( $self, $dir ) = @_; |
258
|
|
|
|
|
|
|
|
259
|
3
|
100
|
|
|
|
10
|
if ($dir) { |
260
|
1
|
|
|
|
|
5
|
$self->dir($dir); |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
else { |
263
|
2
|
|
|
|
|
8
|
$dir = $self->dir; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
3
|
100
|
|
|
|
25
|
confess "No directory supplied!" if !$dir; |
267
|
|
|
|
|
|
|
|
268
|
2
|
|
|
|
|
7
|
my $system = $self->which; |
269
|
|
|
|
|
|
|
|
270
|
2
|
|
|
|
|
17
|
return $system->pull($dir); |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub push { |
274
|
3
|
|
|
3
|
1
|
1205
|
my ( $self, $dir ) = @_; |
275
|
|
|
|
|
|
|
|
276
|
3
|
100
|
|
|
|
8
|
if ($dir) { |
277
|
1
|
|
|
|
|
5
|
$self->dir($dir); |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
else { |
280
|
2
|
|
|
|
|
6
|
$dir = $self->dir; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
3
|
100
|
|
|
|
24
|
confess "No directory supplied!" if !$dir; |
284
|
|
|
|
|
|
|
|
285
|
2
|
|
|
|
|
6
|
my $system = $self->which; |
286
|
|
|
|
|
|
|
|
287
|
2
|
|
|
|
|
20
|
return $system->push($dir); |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub status { |
291
|
3
|
|
|
3
|
1
|
1206
|
my ( $self, $dir ) = @_; |
292
|
|
|
|
|
|
|
|
293
|
3
|
100
|
|
|
|
9
|
if ($dir) { |
294
|
1
|
|
|
|
|
5
|
$self->dir($dir); |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
else { |
297
|
2
|
|
|
|
|
8
|
$dir = $self->dir; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
|
300
|
3
|
100
|
|
|
|
21
|
confess "No directory supplied!" if !$dir; |
301
|
|
|
|
|
|
|
|
302
|
2
|
|
|
|
|
7
|
my $system = $self->which; |
303
|
|
|
|
|
|
|
|
304
|
2
|
|
|
|
|
31
|
return $system->status($dir); |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub checkout { |
308
|
3
|
|
|
3
|
1
|
1165
|
my ( $self, $dir, @extra ) = @_; |
309
|
|
|
|
|
|
|
|
310
|
3
|
100
|
|
|
|
12
|
if ($dir) { |
311
|
1
|
|
|
|
|
5
|
$self->dir($dir); |
312
|
|
|
|
|
|
|
} |
313
|
|
|
|
|
|
|
else { |
314
|
2
|
|
|
|
|
6
|
$dir = $self->dir; |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
3
|
100
|
|
|
|
23
|
confess "No directory supplied!" if !$dir; |
318
|
|
|
|
|
|
|
|
319
|
2
|
|
|
|
|
5
|
my $system = $self->which; |
320
|
|
|
|
|
|
|
|
321
|
2
|
|
|
|
|
19
|
return $system->checkout($dir, @extra); |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
sub add { |
325
|
3
|
|
|
3
|
1
|
1221
|
my ( $self, $dir, @extra ) = @_; |
326
|
|
|
|
|
|
|
|
327
|
3
|
100
|
|
|
|
11
|
if ($dir) { |
328
|
1
|
|
|
|
|
4
|
$self->dir($dir); |
329
|
|
|
|
|
|
|
} |
330
|
|
|
|
|
|
|
else { |
331
|
2
|
|
|
|
|
7
|
$dir = $self->dir; |
332
|
|
|
|
|
|
|
} |
333
|
|
|
|
|
|
|
|
334
|
3
|
100
|
|
|
|
31
|
confess "No directory supplied!" if !$dir; |
335
|
|
|
|
|
|
|
|
336
|
2
|
|
|
|
|
6
|
my $system = $self->which; |
337
|
|
|
|
|
|
|
|
338
|
2
|
|
|
|
|
18
|
return $system->add($dir, @extra); |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
1; |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
__END__ |