line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Socialtext::CPANWiki; |
2
|
1
|
|
|
1
|
|
33771
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
452
|
use Socialtext::CPANWiki::RSSFeed; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Data::Dumper; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Socialtext::CPANWiki - Update a wiki with info from the CPAN RSS Feed |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Socialtext::CPANWiki->new( |
18
|
|
|
|
|
|
|
rester => $rester, |
19
|
|
|
|
|
|
|
filter_page => 'CPAN Module Filter', |
20
|
|
|
|
|
|
|
)->update; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
|
|
|
|
|
|
my $class = shift; |
26
|
|
|
|
|
|
|
my $self = { |
27
|
|
|
|
|
|
|
@_, |
28
|
|
|
|
|
|
|
pause_id => {}, |
29
|
|
|
|
|
|
|
author => {}, |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
die 'rester is mandatory!' unless $self->{rester}; |
32
|
|
|
|
|
|
|
bless $self, $class; |
33
|
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub update { |
37
|
|
|
|
|
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$self->{releases} = Socialtext::CPANWiki::RSSFeed->new->parse_feed; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->_filter_packages if $self->{filter_page}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->_update_releases; |
44
|
|
|
|
|
|
|
$self->_update_pause_ids; |
45
|
|
|
|
|
|
|
$self->_update_authors; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _filter_packages { |
49
|
|
|
|
|
|
|
my $self = shift; |
50
|
|
|
|
|
|
|
my $package_filter = $self->load_package_list; |
51
|
|
|
|
|
|
|
my $releases = $self->{releases}; |
52
|
|
|
|
|
|
|
if (%$package_filter) { |
53
|
|
|
|
|
|
|
@$releases = grep { $package_filter->{$_->{name}} } |
54
|
|
|
|
|
|
|
@$releases; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _update_releases { |
59
|
|
|
|
|
|
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
print "Putting releases onto the wiki ...\n"; |
62
|
|
|
|
|
|
|
for my $r (@{ $self->{releases} }) { |
63
|
|
|
|
|
|
|
my $continue = 1; |
64
|
|
|
|
|
|
|
eval { |
65
|
|
|
|
|
|
|
$continue = $self->_put_release_on_wiki($r); |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
warn $@ if $@; |
68
|
|
|
|
|
|
|
last unless $continue; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _update_pause_ids { |
73
|
|
|
|
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $pause_id = $self->{pause_id}; |
76
|
|
|
|
|
|
|
print "\nUpdating PAUSE ID pages ...\n" if %$pause_id; |
77
|
|
|
|
|
|
|
for my $id (keys %$pause_id) { |
78
|
|
|
|
|
|
|
my $author = $pause_id->{$id}; |
79
|
|
|
|
|
|
|
put_author_page($id, <
|
80
|
|
|
|
|
|
|
[$author] |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
{include: [$author]} |
83
|
|
|
|
|
|
|
EOT |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _update_authors { |
88
|
|
|
|
|
|
|
my $self = shift; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $author = $self->{author}; |
91
|
|
|
|
|
|
|
print "\nUpdating author pages ...\n" if %$author; |
92
|
|
|
|
|
|
|
for my $id (keys %$author) { |
93
|
|
|
|
|
|
|
my $releases = $author->{$id}; |
94
|
|
|
|
|
|
|
my $pause_id = $releases->[0]->{pause_id}; |
95
|
|
|
|
|
|
|
$self->_put_author_page($id, <
|
96
|
|
|
|
|
|
|
* "CPAN Page" |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
^^ Packages |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
{search: tag: package AND tag: $pause_id} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
EOT |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub load_package_list { |
107
|
|
|
|
|
|
|
my $self = shift; |
108
|
|
|
|
|
|
|
my $page_name = $self->{filter_page}; |
109
|
|
|
|
|
|
|
my $rester = $self->{rester}; |
110
|
|
|
|
|
|
|
print "Loading '$page_name' from " . $rester->workspace . "\n"; |
111
|
|
|
|
|
|
|
my $page = $rester->get_page($page_name); |
112
|
|
|
|
|
|
|
my %packages; |
113
|
|
|
|
|
|
|
while ($page =~ m/^\*\s+(.+)$/mg) { |
114
|
|
|
|
|
|
|
$packages{$1}++; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
return \%packages; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _put_release_on_wiki { |
120
|
|
|
|
|
|
|
my $self = shift; |
121
|
|
|
|
|
|
|
my $r = shift; |
122
|
|
|
|
|
|
|
my $rester = $self->{rester}; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $release_page = "$r->{name}-$r->{version}"; |
125
|
|
|
|
|
|
|
print sprintf('%50s ', $release_page); |
126
|
|
|
|
|
|
|
$rester->get_page($release_page); |
127
|
|
|
|
|
|
|
my $code = $rester->response->code; |
128
|
|
|
|
|
|
|
if ($code eq '200') { |
129
|
|
|
|
|
|
|
print "skipping ...\n"; |
130
|
|
|
|
|
|
|
return 0; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$rester->put_page($release_page, <
|
134
|
|
|
|
|
|
|
^^ Release Details |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
*Package:* [$r->{name}] |
137
|
|
|
|
|
|
|
*Version:* "$r->{version}" <$r->{link}> |
138
|
|
|
|
|
|
|
*Description:* $r->{desc} |
139
|
|
|
|
|
|
|
*Author:* "$r->{author}" {pause_id}/> |
140
|
|
|
|
|
|
|
*PAUSE ID:* "$r->{pause_id}" {pause_id}/> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
"$release_page on CPAN" <$r->{link}> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
^^ Comments |
145
|
|
|
|
|
|
|
EOT |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my @release_tags = ('release', $r->{name}, $r->{pause_id}, $r->{version}); |
148
|
|
|
|
|
|
|
print 'tags: ', join(', ', @release_tags); |
149
|
|
|
|
|
|
|
for my $p (@release_tags) { |
150
|
|
|
|
|
|
|
$rester->put_pagetag($release_page, $p); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $package_page = $r->{name}; |
154
|
|
|
|
|
|
|
print "\n", sprintf('%50s ', $package_page); |
155
|
|
|
|
|
|
|
my $package_page_text = $rester->get_page($r->{name}); |
156
|
|
|
|
|
|
|
my $comments = "^^ Comments:\n"; |
157
|
|
|
|
|
|
|
if ($package_page_text =~ m/\Q$comments\E(.+)/s) { |
158
|
|
|
|
|
|
|
$comments .= $1; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$rester->put_page($r->{name}, <
|
162
|
|
|
|
|
|
|
*Package:* $r->{name} |
163
|
|
|
|
|
|
|
*Latest release:* [$release_page] |
164
|
|
|
|
|
|
|
*Version:* "$r->{version}" <$r->{link}> |
165
|
|
|
|
|
|
|
*Description:* $r->{desc} |
166
|
|
|
|
|
|
|
*Author:* "$r->{author}" {pause_id}/> |
167
|
|
|
|
|
|
|
*PAUSE ID:* {category: $r->{pause_id}} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
"Latest release on CPAN: $release_page" <$r->{link}> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
^^ All Releases |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
{category: $r->{name}} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$comments |
177
|
|
|
|
|
|
|
EOT |
178
|
|
|
|
|
|
|
my @package_tags = ('package', $r->{name}, $r->{pause_id}, $r->{version}); |
179
|
|
|
|
|
|
|
print 'tags: ', join(', ', @package_tags); |
180
|
|
|
|
|
|
|
for my $p (@package_tags) { |
181
|
|
|
|
|
|
|
$rester->put_pagetag($package_page, $p); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
print "\n"; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# Update author tables |
187
|
|
|
|
|
|
|
$self->{pause_id}{$r->{pause_id}} = $r->{author}; |
188
|
|
|
|
|
|
|
push @{ $self->{author}{$r->{author}} }, $r; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
return 1; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub _put_author_page { |
194
|
|
|
|
|
|
|
my $self = shift; |
195
|
|
|
|
|
|
|
my $page = shift; |
196
|
|
|
|
|
|
|
my $content = shift; |
197
|
|
|
|
|
|
|
my $rester = $self->{rester}; |
198
|
|
|
|
|
|
|
my @tags = @_; |
199
|
|
|
|
|
|
|
my $code = ''; |
200
|
|
|
|
|
|
|
eval { |
201
|
|
|
|
|
|
|
my $existing_page = $rester->get_page($page); |
202
|
|
|
|
|
|
|
$code = $rester->response->code; |
203
|
|
|
|
|
|
|
}; |
204
|
|
|
|
|
|
|
warn "Error: get_page($page, 'pause_id'): $@" if $@; |
205
|
|
|
|
|
|
|
return unless $code eq '404'; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
print " $page\n"; |
208
|
|
|
|
|
|
|
eval { |
209
|
|
|
|
|
|
|
$rester->put_page($page, $content); |
210
|
|
|
|
|
|
|
}; |
211
|
|
|
|
|
|
|
warn "Error: put_page($page, ): $@" if $@; |
212
|
|
|
|
|
|
|
for my $t (@tags) { |
213
|
|
|
|
|
|
|
eval { |
214
|
|
|
|
|
|
|
$rester->put_pagetag($page, $t); |
215
|
|
|
|
|
|
|
}; |
216
|
|
|
|
|
|
|
warn "Error: put_pagetag($page, $t): $@" if $@; |
217
|
|
|
|
|
|
|
}; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 AUTHOR |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Luke Closs, C<< >> |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Copyright 2006, 2007 Luke Closs, all rights reserved. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
229
|
|
|
|
|
|
|
under the same terms as Perl itself. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
1; |