line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ruby::VersionManager::Gem; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
17
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
5
|
1
|
|
|
1
|
|
326
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
4
|
use feature 'say'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
98
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
8
|
1
|
|
|
1
|
|
928
|
use Data::Dumper; |
|
1
|
|
|
|
|
6473
|
|
|
1
|
|
|
|
|
933
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.004004; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has _gem_list => ( is => 'rw' ); |
13
|
|
|
|
|
|
|
has _dispatch => ( is => 'rw' ); |
14
|
|
|
|
|
|
|
has _options => ( is => 'rw' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub BUILD { |
17
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $dispatch = { reinstall => $self->can('_reinstall'), }; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$self->_dispatch($dispatch); |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub run_action { |
27
|
0
|
|
|
0
|
1
|
|
my ( $self, $action, @options ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if ( exists $self->_dispatch->{$action} ) { |
30
|
0
|
|
|
|
|
|
$self->_options(@options); |
31
|
0
|
|
|
|
|
|
$self->_dispatch->{$action}->($self); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
0
|
|
|
|
|
|
system 'gem ' . join ' ', ( $action, @options ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return 1; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _reinstall { |
41
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $stdin .= $_ while (<>); |
44
|
0
|
0
|
0
|
|
|
|
if ($stdin) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$self->_gem_list( $self->_parse_gemlist($stdin)); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ( defined $self->_gem_list && -f $self->_gem_list ) { |
48
|
0
|
|
|
|
|
|
my $gemlist = ''; |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
|
|
|
local $/; |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
open my $fh, '<', $self->_gem_list; |
52
|
0
|
|
|
|
|
|
$gemlist = <$fh>; |
53
|
0
|
|
|
|
|
|
close $fh; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
$self->_gem_list( $self->_parse_gemlist($gemlist) ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ( defined $self->_options && -f ( $self->_options )[0] ) { |
58
|
0
|
|
|
|
|
|
my $gemlist = ''; |
59
|
|
|
|
|
|
|
{ |
60
|
0
|
|
|
|
|
|
local $/; |
|
0
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
open my $fh, '<', ( $self->_options )[0]; |
62
|
0
|
|
|
|
|
|
$gemlist = <$fh>; |
63
|
0
|
|
|
|
|
|
close $fh; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
$self->_gem_list( $self->_parse_gemlist($gemlist) ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
0
|
|
|
|
|
|
my $gemlist = qx[gem list]; |
69
|
0
|
|
|
|
|
|
$self->_gem_list( $self->_parse_gemlist($gemlist) ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$self->_install_gems( $self->_gem_list, { nodeps => 1 } ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _parse_gemlist { |
76
|
0
|
|
|
0
|
|
|
my ( $self, $gemlist ) = @_; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $gems = {}; |
79
|
0
|
|
|
|
|
|
for my $line ( split /\n/, $gemlist ) { |
80
|
0
|
|
|
|
|
|
my ( $gem, $versions ) = $line =~ / |
81
|
|
|
|
|
|
|
([-_\w]+)\s # capture gem name |
82
|
|
|
|
|
|
|
[(]( |
83
|
|
|
|
|
|
|
(?: |
84
|
|
|
|
|
|
|
(?: |
85
|
|
|
|
|
|
|
(?:\d+\.)*\d+ |
86
|
|
|
|
|
|
|
) |
87
|
|
|
|
|
|
|
,?\s? |
88
|
|
|
|
|
|
|
)+ |
89
|
|
|
|
|
|
|
)[)]/mxg; |
90
|
0
|
0
|
|
|
|
|
$gems->{$gem} = [ split ', ', $versions ] if defined $gem; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $gems; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _install_gems { |
97
|
0
|
|
|
0
|
|
|
my ( $self, $gems, $opts ) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
for my $gem ( keys %$gems ) { |
100
|
0
|
|
|
|
|
|
for my $version ( @{ $gems->{$gem} } ) { |
|
0
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $cmd = "gem install $gem "; |
102
|
0
|
|
|
|
|
|
$cmd .= "-v=$version"; |
103
|
0
|
0
|
0
|
|
|
|
if ( defined $opts && $opts->{'nodeps'} ) { |
104
|
0
|
|
|
|
|
|
$cmd .= " --ignore-dependencies"; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my $output = qx[$cmd]; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return 1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |