| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CPANPLUS::Shell::Default::Plugins::Repo; |
|
2
|
|
|
|
|
|
|
our $VERSION = '0.0.3'; |
|
3
|
1
|
|
|
1
|
|
945
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
893
|
|
|
4
|
|
|
|
|
|
|
our %handlers; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my $cache_file = "$ENV{HOME}/.cpan-repo"; |
|
7
|
|
|
|
|
|
|
|
|
8
|
0
|
|
|
0
|
0
|
|
sub plugins { ( repo => 'repo' ) } |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub repo { |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# /helloworld bob --nofoo --bar=2 joe |
|
13
|
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
0
|
|
my $class = shift; # CPANPLUS::Shell::Default::Plugins::HW |
|
15
|
0
|
|
|
|
|
|
my $shell = shift; # CPANPLUS::Shell::Default object |
|
16
|
0
|
|
|
|
|
|
my $cb = shift; # CPANPLUS::Backend object |
|
17
|
0
|
|
|
|
|
|
my $cmd = shift; # 'helloworld' |
|
18
|
0
|
|
|
|
|
|
my $input = shift; # 'bob joe' |
|
19
|
0
|
|
|
|
|
|
my $opts = shift; # { foo => 0, bar => 2 } |
|
20
|
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my ($action,@params) = split /\s+/, $input; |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
|
0
|
|
|
|
$action ||= 'list'; |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
s/\s//g for ($action,@params); |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $handler_id = $action; |
|
28
|
0
|
0
|
|
|
|
|
if (exists $handlers{$handler_id}){ |
|
29
|
0
|
|
|
|
|
|
print "fire handler : $handler_id \n"; |
|
30
|
0
|
|
|
|
|
|
$handlers{$handler_id}->($cb,@params), |
|
31
|
|
|
|
|
|
|
}else{ |
|
32
|
0
|
|
|
|
|
|
print "handler [$handler_id] not found \n"; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$handlers{'list'} = sub { |
|
41
|
|
|
|
|
|
|
my $cb = shift; |
|
42
|
|
|
|
|
|
|
if(my $repo_server = load_repo_server_from_file()){ |
|
43
|
|
|
|
|
|
|
print "[fetching repos from $repo_server]\n"; |
|
44
|
|
|
|
|
|
|
system ("curl -s $repo_server/list/"); |
|
45
|
|
|
|
|
|
|
print "\n"; |
|
46
|
|
|
|
|
|
|
}else{ |
|
47
|
|
|
|
|
|
|
print "CPAN::Repo server not set; use /repo server to setup it\n" |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
}; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$handlers{'set'} = sub { |
|
55
|
|
|
|
|
|
|
my $cb = shift; |
|
56
|
|
|
|
|
|
|
my @repos = @_; |
|
57
|
|
|
|
|
|
|
commit_repos_to_cs($cb,@repos); |
|
58
|
|
|
|
|
|
|
return; |
|
59
|
|
|
|
|
|
|
}; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$handlers{'server'} = sub { |
|
63
|
|
|
|
|
|
|
my $cb = shift; |
|
64
|
|
|
|
|
|
|
my $uri = shift; |
|
65
|
|
|
|
|
|
|
save_repo_server_to_file($uri); |
|
66
|
|
|
|
|
|
|
return; |
|
67
|
|
|
|
|
|
|
}; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub repo_help { |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
0
|
0
|
|
return <
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Provides interface to CPAN::Repo server. |
|
75
|
|
|
|
|
|
|
# See http://search.cpan.org/perldoc?CPAN::Repo for details. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
/? repo |
|
78
|
|
|
|
|
|
|
/repo server # setup CPAN::Repo server |
|
79
|
|
|
|
|
|
|
/repo list # list available repos from CPAN::Repo server |
|
80
|
|
|
|
|
|
|
/repo set ... # setup repos and save it as custom sources |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
MESSAGE |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub load_repo_server_from_file { |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
0
|
|
`touch $cache_file`; |
|
90
|
0
|
|
|
|
|
|
my $uri; |
|
91
|
0
|
|
|
|
|
|
print "load $cache_file ...\n"; |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
if(open F, $cache_file){ |
|
94
|
0
|
|
|
|
|
|
while (my $l = ){ |
|
95
|
0
|
|
|
|
|
|
chomp $l; s/\s//g for $l; |
|
|
0
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
$l=~/\S+/ or next; |
|
97
|
0
|
|
|
|
|
|
$uri = $l; |
|
98
|
0
|
|
|
|
|
|
last; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
0
|
|
|
|
|
|
close F; |
|
101
|
|
|
|
|
|
|
}else{ |
|
102
|
0
|
|
|
|
|
|
print "error : cannot open file [$cache_file] : $!\n"; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
0
|
|
|
|
|
|
return $uri; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub save_repo_server_to_file { |
|
108
|
0
|
|
|
0
|
0
|
|
my $uri = shift; |
|
109
|
0
|
|
|
|
|
|
`touch $cache_file`; |
|
110
|
0
|
0
|
|
|
|
|
if(open F, '>', $cache_file){ |
|
111
|
0
|
|
|
|
|
|
print F $uri, "\n"; close F; |
|
|
0
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
print "save $uri to $cache_file\n"; |
|
113
|
|
|
|
|
|
|
}else{ |
|
114
|
0
|
|
|
|
|
|
print "error : cannot open repo file [$cache_file] to write : $!\n"; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
0
|
|
|
|
|
|
return; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub commit_repos_to_cs { |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
0
|
0
|
|
my $cb = shift; |
|
122
|
0
|
|
|
|
|
|
my @repos = @_; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
print "commit repos to custom source file ...\n"; |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
if (@repos){ |
|
127
|
0
|
|
|
|
|
|
my $uri = load_repo_server_from_file(); |
|
128
|
0
|
|
|
|
|
|
my %cs = $cb->list_custom_sources; |
|
129
|
0
|
|
|
|
|
|
for my $cs (values %cs){ |
|
130
|
0
|
|
|
|
|
|
$cb->remove_custom_source( uri => $cs, verbose => 1 ); |
|
131
|
|
|
|
|
|
|
} |
|
132
|
0
|
0
|
|
|
|
|
$uri = "http://" unless $uri=~/^http:\/\//; |
|
133
|
0
|
|
|
|
|
|
$uri.='/'.(join '/', @repos); |
|
134
|
0
|
|
|
|
|
|
$cb->add_custom_source( uri => $uri, verbose => 1 ); |
|
135
|
0
|
|
|
|
|
|
$cb->update_custom_source(); |
|
136
|
|
|
|
|
|
|
}else{ |
|
137
|
0
|
|
|
|
|
|
print "warn : repos list is empty, nothing to do with it\n"; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
0
|
|
|
|
|
|
return; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |