| 1 | package CPANDB::Generator; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =pod | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | CPANDB::Generator - Generator module for the CPAN Index Database | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # Simplicity itself | ||||||||||||||||||||||||||||
| 12 | CPANDB::Generator->new->run; | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | This is a module used to generate a unified index database, pulling in | ||||||||||||||||||||||||||||
| 17 | data from various other sources to produce a single schema that contains | ||||||||||||||||||||||||||||
| 18 | the essential elements from all of them. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | It is uploaded to the CPAN for the purpose of full disclosure, or in case | ||||||||||||||||||||||||||||
| 21 | the author gets hit by a bus. Generating the index database involves | ||||||||||||||||||||||||||||
| 22 | downloading a number of relatively large SQLite datasets, the consumption | ||||||||||||||||||||||||||||
| 23 | of several gigabytes of disk, and a fairly large amount of CPU time. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | If you are interested in using the index database, you should | ||||||||||||||||||||||||||||
| 26 | instead see the L<CPANDB> distribution. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 METHODS | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use 5.008005; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use File::Spec 3.30 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | use File::Temp 0.21 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | use File::Path 2.07 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | use File::pushd 1.00 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | use File::Remove 1.42 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | use File::HomeDir 0.86 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | use Params::Util 1.00 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | use URI 1.37 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | use URI::file (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 2 | ▶ | use DBI 1.608 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | use DBD::SQLite 1.25 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | use CPAN::SQLite 0.197 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 2 | ▶ | use CPAN::Mini::Visit 0.11 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | use LWP::UserAgent 5.819 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | use Xtract::Publish 0.10 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 2 | ▶ | use Algorithm::Dependency 1.108 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 2 | ▶ | use Algorithm::Dependency::Weight (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | use Algorithm::Dependency::Source::DBI 1.06 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | our $VERSION = '0.19'; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | ▶ | use Object::Tiny 1.06 qw{ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | cpan | ||||||||||||||||||||||||||||
| 60 | urllist | ||||||||||||||||||||||||||||
| 61 | sqlite | ||||||||||||||||||||||||||||
| 62 | publish | ||||||||||||||||||||||||||||
| 63 | trace | ||||||||||||||||||||||||||||
| 64 | dbh | ||||||||||||||||||||||||||||
| 65 | cpanmeta | ||||||||||||||||||||||||||||
| 66 | minicpan | ||||||||||||||||||||||||||||
| 67 | 2 | }; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | ▶ | use CPANDB::Generator::GetIndex (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | ##################################################################### | ||||||||||||||||||||||||||||
| 76 | # Constructor | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =pod | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head2 new | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | my $cpan = CPANDB::Generator->new( | ||||||||||||||||||||||||||||
| 83 | cpan => '/root/.cpan', | ||||||||||||||||||||||||||||
| 84 | sqlite => '/root/CPANDB.sqlite', | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | Creates a new generation object. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | The optional C<cpan> param identifies the path to your | ||||||||||||||||||||||||||||
| 90 | cpan operating directory. By default, a fresh one will be | ||||||||||||||||||||||||||||
| 91 | generated in a temporary directory, and deleted at the end of | ||||||||||||||||||||||||||||
| 92 | the generation run. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | The optional C<sqlite> param specifies where the SQLite database | ||||||||||||||||||||||||||||
| 95 | should be written to. By default, this will be to a standard | ||||||||||||||||||||||||||||
| 96 | location in your home directory. | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Returns a new B<CPANDB::Generator> object. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my $self = shift->SUPER::new(@_); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # Default the CPAN path to a temp directory, | ||||||||||||||||||||||||||||
| 106 | # so that we don't disturb any existing files. | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | unless ( defined $self->cpan ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | $self->{cpan} = File::Temp::tempdir( CLEANUP => 1 ); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # Establish where we will be writing to | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | unless ( defined $self->sqlite ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $self->{sqlite} = File::Spec->catdir( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | File::HomeDir->my_data, | ||||||||||||||||||||||||||||
| 115 | ($^O eq 'MSWin32' ? 'Perl' : '.perl'), | ||||||||||||||||||||||||||||
| 116 | 'CPANDB-Generator', | ||||||||||||||||||||||||||||
| 117 | 'cpan.db', | ||||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # Set the default path to the publishing location | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | unless ( exists $self->{publish} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | $self->{publish} = 'cpan'; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # If we have a minicpan and no urllist, | ||||||||||||||||||||||||||||
| 127 | # derive the latter from the former. | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ( $self->minicpan and not $self->urllist ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->minicpan and not $self->urllist
MC/DC0%0/2
$self->minicpan and not $self->urllist
$self->minicpan
not $self->urllist
Truth table0%0/3
A and not(B)
A= $self->minicpanB= not $self->urllist
| |||||||||||||||||||||||||||||
| 129 | 0 | my $uri = URI::file->new( $self->minicpan, undef )->as_string; | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | unless ( $uri =~ m/\/\z/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | $uri .= '/'; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 0 | $self->{urllist} = [ $uri ]; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | return $self; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =pod | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head2 dir | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | The C<dir> method returns the directory that the SQLite | ||||||||||||||||||||||||||||
| 144 | database will be written into. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub dir { | ||||||||||||||||||||||||||
|
Subroutine
dir: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 0 | File::Basename::dirname($_[0]->sqlite); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =pod | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head2 dsn | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | The C<dsn> method returns the L<DBI> DSN that is used to connect | ||||||||||||||||||||||||||||
| 157 | to the generated database. | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub dsn { | ||||||||||||||||||||||||||
|
Subroutine
dsn: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 0 | "DBI:SQLite:" . $_[0]->sqlite | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =pod | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =head2 cpan_sql | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | Once it has been fetched or updated from your CPAN mirror, the | ||||||||||||||||||||||||||||
| 170 | C<cpan_sql> method returns the location of the L<CPAN::SQLite> | ||||||||||||||||||||||||||||
| 171 | database used by the CPAN client. | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | This database is used as the source of the information that forms | ||||||||||||||||||||||||||||
| 174 | the core of the unified index database, and that the rest of the | ||||||||||||||||||||||||||||
| 175 | data will be decorated around. | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub cpan_sql { | ||||||||||||||||||||||||||
|
Subroutine
cpan_sql: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 180 | 0 | File::Spec->catfile($_[0]->cpan, 'cpandb.sql'); | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | ##################################################################### | ||||||||||||||||||||||||||||
| 188 | # Main Methods | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | =pod | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =head2 run | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | The C<run> method executes the process that will produce and fill the | ||||||||||||||||||||||||||||
| 195 | final database. | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=24 SCAR=64.0
Pod
documented
| |||||||||||||||||||||||||||||
| 200 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | # Create the output directory | ||||||||||||||||||||||||||||
| 203 | 0 | File::Path::make_path($self->dir); | |||||||||||||||||||||||||||
| 204 | 0 | ▶ | unless ( -d $self->dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 0 | Carp::croak("Failed to create '" . $self->dir . "'"); | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # Clear the database if it already exists | ||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if ( -f $self->sqlite ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 0 | File::Remove::remove($self->sqlite); | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if ( -f $self->sqlite ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 0 | Carp::croak("Failed to clear " . $self->sqlite); | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | # Connect to the database | ||||||||||||||||||||||||||||
| 217 | 0 | ▶ | unless ( $self->{dbh} = DBI->connect($self->dsn) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | Carp::croak("connect: \$DBI::errstr"); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | # Allocate a lot more memory to cut down file churn | ||||||||||||||||||||||||||||
| 222 | 0 | $self->do('PRAGMA cache_size = 100000'); | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | # Refresh the CPAN index database | ||||||||||||||||||||||||||||
| 225 | 0 | $self->say("Fetching CPAN Index..."); | |||||||||||||||||||||||||||
| 226 | 0 | my $update = CPANDB::Generator::GetIndex->new( | |||||||||||||||||||||||||||
| 227 | cpan => $self->cpan, | ||||||||||||||||||||||||||||
| 228 | urllist => $self->urllist, | ||||||||||||||||||||||||||||
| 229 | )->delegate; | ||||||||||||||||||||||||||||
| 230 | 0 | ▶ | unless ( -f $self->cpan_sql ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 0 | Carp::croak("Failed to fetch CPAN index"); | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | # Load the CPAN Uploads database | ||||||||||||||||||||||||||||
| 235 | 0 | $self->say("Fetching CPAN Uploads..."); | |||||||||||||||||||||||||||
| 236 | 0 | require ORDB::CPANUploads; | |||||||||||||||||||||||||||
| 237 | 0 | ORDB::CPANUploads->import( { | |||||||||||||||||||||||||||
| 238 | show_progress => 1, | ||||||||||||||||||||||||||||
| 239 | } ); | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | # Load the CPAN Testers database | ||||||||||||||||||||||||||||
| 242 | 0 | $self->say("Fetching CPAN Testers... (This may take a while)"); | |||||||||||||||||||||||||||
| 243 | 0 | require ORDB::CPANTesters; | |||||||||||||||||||||||||||
| 244 | 0 | ORDB::CPANTesters->import( { | |||||||||||||||||||||||||||
| 245 | show_progress => 1, | ||||||||||||||||||||||||||||
| 246 | } ); | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | # Load the CPAN META.yml database | ||||||||||||||||||||||||||||
| 249 | 0 | my $cpanmeta; | |||||||||||||||||||||||||||
| 250 | 0 | ▶ | if ( $self->cpanmeta ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | # Generate out own CPANMeta database | ||||||||||||||||||||||||||||
| 252 | 0 | $self->say("Generating META.yml Data..."); | |||||||||||||||||||||||||||
| 253 | 0 | require ORDB::CPANMeta::Generator; | |||||||||||||||||||||||||||
| 254 | 0 | ▶ | my $prefer_bin = $^O eq 'MSWin32' ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 0 | $cpanmeta = ORDB::CPANMeta::Generator->new( | |||||||||||||||||||||||||||
| 256 | minicpan => $self->minicpan, | ||||||||||||||||||||||||||||
| 257 | trace => $self->trace, | ||||||||||||||||||||||||||||
| 258 | prefer_bin => $prefer_bin, | ||||||||||||||||||||||||||||
| 259 | publish => undef, | ||||||||||||||||||||||||||||
| 260 | warnings => 1, | ||||||||||||||||||||||||||||
| 261 | delta => 1, | ||||||||||||||||||||||||||||
| 262 | ); | ||||||||||||||||||||||||||||
| 263 | 0 | $cpanmeta->run; | |||||||||||||||||||||||||||
| 264 | } else { | ||||||||||||||||||||||||||||
| 265 | 0 | $self->say("Fetching META.yml Data..."); | |||||||||||||||||||||||||||
| 266 | 0 | require ORDB::CPANMeta; | |||||||||||||||||||||||||||
| 267 | 0 | ORDB::CPANMeta->import; | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | # Attach the various databases | ||||||||||||||||||||||||||||
| 271 | 0 | ▶ | my $cpanmeta_sqlite = $cpanmeta ? $cpanmeta->sqlite : ORDB::CPANMeta->sqlite; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | $self->do( "ATTACH DATABASE ? AS meta", {}, $cpanmeta_sqlite ); | |||||||||||||||||||||||||||
| 273 | 0 | $self->do( "ATTACH DATABASE ? AS cpan", {}, $self->cpan_sql ); | |||||||||||||||||||||||||||
| 274 | 0 | $self->do( "ATTACH DATABASE ? AS upload", {}, ORDB::CPANUploads->sqlite ); | |||||||||||||||||||||||||||
| 275 | 0 | $self->do( "ATTACH DATABASE ? AS testers", {}, ORDB::CPANTesters->sqlite ); | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | # Pre-process the cpan data to produce cleaner intermediate | ||||||||||||||||||||||||||||
| 278 | # temp tables that produce better joins later on. | ||||||||||||||||||||||||||||
| 279 | 0 | $self->say("Cleaning CPAN Index..."); | |||||||||||||||||||||||||||
| 280 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 281 | CREATE TABLE t_distribution AS | ||||||||||||||||||||||||||||
| 282 | SELECT | ||||||||||||||||||||||||||||
| 283 | d.dist_name as dist, | ||||||||||||||||||||||||||||
| 284 | d.dist_vers as version, | ||||||||||||||||||||||||||||
| 285 | d.dist_name || ' ' || d.dist_vers as dist_version, | ||||||||||||||||||||||||||||
| 286 | a.cpanid as author, | ||||||||||||||||||||||||||||
| 287 | a.cpanid || '/' || d.dist_file as release | ||||||||||||||||||||||||||||
| 288 | FROM | ||||||||||||||||||||||||||||
| 289 | auths a, | ||||||||||||||||||||||||||||
| 290 | dists d | ||||||||||||||||||||||||||||
| 291 | WHERE | ||||||||||||||||||||||||||||
| 292 | a.auth_id = d.auth_id | ||||||||||||||||||||||||||||
| 293 | END_SQL | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | # Index the cleaned dist table | ||||||||||||||||||||||||||||
| 296 | 0 | $self->create_index( t_distribution => qw{ | |||||||||||||||||||||||||||
| 297 | dist | ||||||||||||||||||||||||||||
| 298 | version | ||||||||||||||||||||||||||||
| 299 | dist_version | ||||||||||||||||||||||||||||
| 300 | author | ||||||||||||||||||||||||||||
| 301 | release | ||||||||||||||||||||||||||||
| 302 | } ); | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | # Pre-process the uploads data to produce a cleaner intermediate | ||||||||||||||||||||||||||||
| 305 | # temp table that won't break the joins we'll need to do later on. | ||||||||||||||||||||||||||||
| 306 | 0 | $self->say("Cleaning CPAN Uploads..."); | |||||||||||||||||||||||||||
| 307 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 308 | CREATE TABLE t_uploaded AS | ||||||||||||||||||||||||||||
| 309 | SELECT | ||||||||||||||||||||||||||||
| 310 | author || '/' || filename as release, | ||||||||||||||||||||||||||||
| 311 | DATE(released, 'unixepoch') AS uploaded | ||||||||||||||||||||||||||||
| 312 | FROM upload.uploads | ||||||||||||||||||||||||||||
| 313 | END_SQL | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | # Index the temporary tables so our joins don't take forever | ||||||||||||||||||||||||||||
| 316 | 0 | $self->create_index( t_uploaded => 'release' ); | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | # Pre-process the CPAN Testers results to produce a smaller | ||||||||||||||||||||||||||||
| 319 | # database that provides sub-totals for each dist/version/result. | ||||||||||||||||||||||||||||
| 320 | 0 | $self->say("Cleaning CPAN Testers (pass 1)..."); | |||||||||||||||||||||||||||
| 321 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 322 | CREATE TABLE t_cpanstats AS | ||||||||||||||||||||||||||||
| 323 | SELECT | ||||||||||||||||||||||||||||
| 324 | dist AS dist, | ||||||||||||||||||||||||||||
| 325 | dist || ' ' || version AS dist_version, | ||||||||||||||||||||||||||||
| 326 | state AS state | ||||||||||||||||||||||||||||
| 327 | FROM testers.cpanstats | ||||||||||||||||||||||||||||
| 328 | WHERE | ||||||||||||||||||||||||||||
| 329 | state IN ( 'pass', 'fail', 'unknown', 'na' ) | ||||||||||||||||||||||||||||
| 330 | AND perl NOT LIKE '%patch%' | ||||||||||||||||||||||||||||
| 331 | AND perl NOT LIKE '%RC%' | ||||||||||||||||||||||||||||
| 332 | AND ( | ||||||||||||||||||||||||||||
| 333 | perl LIKE '5.4%' | ||||||||||||||||||||||||||||
| 334 | OR perl LIKE '5.5%' | ||||||||||||||||||||||||||||
| 335 | OR perl LIKE '5.6%' | ||||||||||||||||||||||||||||
| 336 | OR perl LIKE '5.8%' | ||||||||||||||||||||||||||||
| 337 | OR perl LIKE '5.10%' | ||||||||||||||||||||||||||||
| 338 | ) | ||||||||||||||||||||||||||||
| 339 | AND dist_version in ( | ||||||||||||||||||||||||||||
| 340 | select dist_version from t_distribution | ||||||||||||||||||||||||||||
| 341 | ) | ||||||||||||||||||||||||||||
| 342 | AND tester NOT LIKE '%dcollins%' | ||||||||||||||||||||||||||||
| 343 | END_SQL | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | # Step two, group into the smaller totals table | ||||||||||||||||||||||||||||
| 346 | 0 | $self->say("Cleaning CPAN Testers (pass 2)..."); | |||||||||||||||||||||||||||
| 347 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 348 | CREATE TABLE t_testers AS | ||||||||||||||||||||||||||||
| 349 | SELECT | ||||||||||||||||||||||||||||
| 350 | dist AS dist, | ||||||||||||||||||||||||||||
| 351 | state AS state, | ||||||||||||||||||||||||||||
| 352 | COUNT(*) AS total | ||||||||||||||||||||||||||||
| 353 | FROM | ||||||||||||||||||||||||||||
| 354 | t_cpanstats | ||||||||||||||||||||||||||||
| 355 | GROUP BY | ||||||||||||||||||||||||||||
| 356 | dist_version, state | ||||||||||||||||||||||||||||
| 357 | END_SQL | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | # Index the totals table | ||||||||||||||||||||||||||||
| 360 | 0 | $self->say("Cleaning CPAN Testers (indexing)..."); | |||||||||||||||||||||||||||
| 361 | 0 | $self->create_index( t_testers => qw{ | |||||||||||||||||||||||||||
| 362 | dist | ||||||||||||||||||||||||||||
| 363 | state | ||||||||||||||||||||||||||||
| 364 | } ); | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | # Create the author table | ||||||||||||||||||||||||||||
| 367 | 0 | $self->say("Generating table author..."); | |||||||||||||||||||||||||||
| 368 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 369 | CREATE TABLE author ( | ||||||||||||||||||||||||||||
| 370 | author TEXT NOT NULL PRIMARY KEY, | ||||||||||||||||||||||||||||
| 371 | name TEXT NOT NULL | ||||||||||||||||||||||||||||
| 372 | ) | ||||||||||||||||||||||||||||
| 373 | END_SQL | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | # Fill the author table | ||||||||||||||||||||||||||||
| 376 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 377 | INSERT INTO author | ||||||||||||||||||||||||||||
| 378 | SELECT | ||||||||||||||||||||||||||||
| 379 | cpanid AS author, | ||||||||||||||||||||||||||||
| 380 | fullname AS name | ||||||||||||||||||||||||||||
| 381 | FROM | ||||||||||||||||||||||||||||
| 382 | cpan.auths | ||||||||||||||||||||||||||||
| 383 | ORDER BY | ||||||||||||||||||||||||||||
| 384 | author | ||||||||||||||||||||||||||||
| 385 | END_SQL | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | # Index the author table | ||||||||||||||||||||||||||||
| 388 | 0 | $self->create_index( author => 'name' ); | |||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | # Create the distribution table | ||||||||||||||||||||||||||||
| 391 | 0 | $self->say("Generating table distribution..."); | |||||||||||||||||||||||||||
| 392 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 393 | CREATE TABLE distribution ( | ||||||||||||||||||||||||||||
| 394 | distribution TEXT NOT NULL PRIMARY KEY, | ||||||||||||||||||||||||||||
| 395 | version TEXT NULL, | ||||||||||||||||||||||||||||
| 396 | author TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 397 | meta INTEGER NOT NULL, | ||||||||||||||||||||||||||||
| 398 | license TEXT NULL, | ||||||||||||||||||||||||||||
| 399 | release TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 400 | uploaded TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 401 | pass INTEGER NOT NULL, | ||||||||||||||||||||||||||||
| 402 | fail INTEGER NOT NULL, | ||||||||||||||||||||||||||||
| 403 | unknown INTEGER NOT NULL, | ||||||||||||||||||||||||||||
| 404 | na INTEGER NOT NULL, | ||||||||||||||||||||||||||||
| 405 | rating TEXT NULL, | ||||||||||||||||||||||||||||
| 406 | ratings INTEGER NOT NULL, | ||||||||||||||||||||||||||||
| 407 | weight INTEGER NOT NULL, | ||||||||||||||||||||||||||||
| 408 | volatility INTEGER NOT NULL, | ||||||||||||||||||||||||||||
| 409 | FOREIGN KEY ( author ) REFERENCES author ( author ) | ||||||||||||||||||||||||||||
| 410 | ) | ||||||||||||||||||||||||||||
| 411 | END_SQL | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | # Fill the distribution table | ||||||||||||||||||||||||||||
| 414 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 415 | INSERT INTO distribution | ||||||||||||||||||||||||||||
| 416 | SELECT | ||||||||||||||||||||||||||||
| 417 | d.dist AS distribution, | ||||||||||||||||||||||||||||
| 418 | d.version AS version, | ||||||||||||||||||||||||||||
| 419 | d.author AS author, | ||||||||||||||||||||||||||||
| 420 | 0 as meta, | ||||||||||||||||||||||||||||
| 421 | NULL as license, | ||||||||||||||||||||||||||||
| 422 | d.release AS release, | ||||||||||||||||||||||||||||
| 423 | u.uploaded AS uploaded, | ||||||||||||||||||||||||||||
| 424 | 0 AS pass, | ||||||||||||||||||||||||||||
| 425 | 0 AS fail, | ||||||||||||||||||||||||||||
| 426 | 0 AS unknown, | ||||||||||||||||||||||||||||
| 427 | 0 AS na, | ||||||||||||||||||||||||||||
| 428 | NULL AS rating, | ||||||||||||||||||||||||||||
| 429 | 0 AS ratings, | ||||||||||||||||||||||||||||
| 430 | 0 AS weight, | ||||||||||||||||||||||||||||
| 431 | 0 AS volatility | ||||||||||||||||||||||||||||
| 432 | FROM | ||||||||||||||||||||||||||||
| 433 | t_distribution d, | ||||||||||||||||||||||||||||
| 434 | t_uploaded u | ||||||||||||||||||||||||||||
| 435 | WHERE | ||||||||||||||||||||||||||||
| 436 | d.release = u.release | ||||||||||||||||||||||||||||
| 437 | ORDER BY | ||||||||||||||||||||||||||||
| 438 | distribution | ||||||||||||||||||||||||||||
| 439 | END_SQL | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | # Fetch the popular ratings for the distributions | ||||||||||||||||||||||||||||
| 442 | 0 | my $counter = 0; | |||||||||||||||||||||||||||
| 443 | # require Parse::CPAN::Ratings; | ||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ( Parse::CPAN::Ratings->VERSION ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 445 | 0 | $self->say('Fetching CPAN Ratings...'); | |||||||||||||||||||||||||||
| 446 | 0 | my $ratings_url = 'http://cpanratings.perl.org/csv/all_ratings.csv'; | |||||||||||||||||||||||||||
| 447 | 0 | my $ratings_dir = File::Temp::tempdir( CLEANUP => 1 ); | |||||||||||||||||||||||||||
| 448 | 0 | my $ratings_file = File::Spec->catfile( $ratings_dir, 'all_ratings.csv' ); | |||||||||||||||||||||||||||
| 449 | 0 | my $response = LWP::UserAgent->new( | |||||||||||||||||||||||||||
| 450 | agent => "CPANDB::Generator/$VERSION", | ||||||||||||||||||||||||||||
| 451 | timeout => 10, | ||||||||||||||||||||||||||||
| 452 | )->mirror( $ratings_url => $ratings_file ); | ||||||||||||||||||||||||||||
| 453 | 0 | ▶ | unless ( $response->is_success or $response->code == 304 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response->is_success or $response->code == 304
MC/DC0%0/2
$response->is_success or $response->code == 304
$response->is_success
$response->code == 304
Truth table0%0/3
A or B
A= $response->is_successB= $response->code == 304
| |||||||||||||||||||||||||||||
| 454 | 0 | Carp::croak("Error: Failed to fetch $ratings_url"); | |||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||
| 456 | 0 | ▶ | my $ratings = Parse::CPAN::Ratings->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | filename => $ratings_file, | ||||||||||||||||||||||||||||
| 458 | ) or Carp::croak("Error: Failed to parse $ratings_url"); | ||||||||||||||||||||||||||||
| 459 | 0 | $self->say('Populating CPAN Ratings...'); | |||||||||||||||||||||||||||
| 460 | 0 | $self->dbh->begin_work; | |||||||||||||||||||||||||||
| 461 | 0 | foreach my $rating ( $ratings->ratings ) { | |||||||||||||||||||||||||||
| 462 | 0 | $self->do( | |||||||||||||||||||||||||||
| 463 | 'UPDATE distribution SET rating = ?, ratings = ? WHERE distribution = ?', | ||||||||||||||||||||||||||||
| 464 | {}, $rating->rating, $rating->review_count, $rating->distribution, | ||||||||||||||||||||||||||||
| 465 | ); | ||||||||||||||||||||||||||||
| 466 | 0 | ▶ | next if ++$counter % 100; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | 0 | $self->dbh->commit; | |||||||||||||||||||||||||||
| 468 | 0 | $self->dbh->begin_work; | |||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||
| 470 | 0 | $self->dbh->commit; | |||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | # Create the module table | ||||||||||||||||||||||||||||
| 474 | 0 | $self->say("Generating table module..."); | |||||||||||||||||||||||||||
| 475 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 476 | CREATE TABLE module ( | ||||||||||||||||||||||||||||
| 477 | module TEXT NOT NULL PRIMARY KEY, | ||||||||||||||||||||||||||||
| 478 | version TEXT NULL, | ||||||||||||||||||||||||||||
| 479 | distribution TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 480 | FOREIGN KEY ( distribution ) REFERENCES distribution ( distribution ) | ||||||||||||||||||||||||||||
| 481 | ) | ||||||||||||||||||||||||||||
| 482 | END_SQL | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | # Fill the module table | ||||||||||||||||||||||||||||
| 485 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 486 | INSERT INTO module | ||||||||||||||||||||||||||||
| 487 | SELECT | ||||||||||||||||||||||||||||
| 488 | m.mod_name as module, | ||||||||||||||||||||||||||||
| 489 | m.mod_vers as version, | ||||||||||||||||||||||||||||
| 490 | d.dist_name as distribution | ||||||||||||||||||||||||||||
| 491 | FROM | ||||||||||||||||||||||||||||
| 492 | mods m, | ||||||||||||||||||||||||||||
| 493 | dists d | ||||||||||||||||||||||||||||
| 494 | WHERE | ||||||||||||||||||||||||||||
| 495 | d.dist_id = m.dist_id | ||||||||||||||||||||||||||||
| 496 | ORDER BY | ||||||||||||||||||||||||||||
| 497 | module | ||||||||||||||||||||||||||||
| 498 | END_SQL | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | # Index the module table | ||||||||||||||||||||||||||||
| 501 | 0 | $self->create_index( module => qw{ | |||||||||||||||||||||||||||
| 502 | version | ||||||||||||||||||||||||||||
| 503 | distribution | ||||||||||||||||||||||||||||
| 504 | } ); | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | # Create the module dependency table | ||||||||||||||||||||||||||||
| 507 | 0 | $self->say("Generating table t_requires..."); | |||||||||||||||||||||||||||
| 508 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 509 | CREATE TABLE t_requires ( | ||||||||||||||||||||||||||||
| 510 | distribution TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 511 | module TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 512 | version TEXT NULL, | ||||||||||||||||||||||||||||
| 513 | phase TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 514 | core REAL NULL | ||||||||||||||||||||||||||||
| 515 | ) | ||||||||||||||||||||||||||||
| 516 | END_SQL | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | # Fill the module dependency table | ||||||||||||||||||||||||||||
| 519 | 0 | $self->create_index( distribution => 'release' ); | |||||||||||||||||||||||||||
| 520 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 521 | INSERT INTO t_requires | ||||||||||||||||||||||||||||
| 522 | SELECT | ||||||||||||||||||||||||||||
| 523 | d.distribution AS distribution, | ||||||||||||||||||||||||||||
| 524 | m.module AS module, | ||||||||||||||||||||||||||||
| 525 | m.version AS version, | ||||||||||||||||||||||||||||
| 526 | m.phase AS phase, | ||||||||||||||||||||||||||||
| 527 | m.core AS core | ||||||||||||||||||||||||||||
| 528 | FROM | ||||||||||||||||||||||||||||
| 529 | distribution d, | ||||||||||||||||||||||||||||
| 530 | meta.meta_dependency m | ||||||||||||||||||||||||||||
| 531 | WHERE | ||||||||||||||||||||||||||||
| 532 | d.release = m.release | ||||||||||||||||||||||||||||
| 533 | ORDER BY | ||||||||||||||||||||||||||||
| 534 | distribution, | ||||||||||||||||||||||||||||
| 535 | phase, | ||||||||||||||||||||||||||||
| 536 | core desc, | ||||||||||||||||||||||||||||
| 537 | module | ||||||||||||||||||||||||||||
| 538 | END_SQL | ||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | # Index the module dependency table | ||||||||||||||||||||||||||||
| 541 | 0 | $self->create_index( t_requires => qw{ | |||||||||||||||||||||||||||
| 542 | distribution | ||||||||||||||||||||||||||||
| 543 | module | ||||||||||||||||||||||||||||
| 544 | version | ||||||||||||||||||||||||||||
| 545 | phase | ||||||||||||||||||||||||||||
| 546 | } ); | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | # Create the distribution dependency table | ||||||||||||||||||||||||||||
| 549 | 0 | $self->say("Generating table dependency..."); | |||||||||||||||||||||||||||
| 550 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 551 | CREATE TABLE dependency ( | ||||||||||||||||||||||||||||
| 552 | distribution TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 553 | dependency TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 554 | phase TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 555 | core REAL NULL, | ||||||||||||||||||||||||||||
| 556 | PRIMARY KEY ( distribution, dependency, phase ), | ||||||||||||||||||||||||||||
| 557 | FOREIGN KEY ( distribution ) REFERENCES distribition ( distribution ), | ||||||||||||||||||||||||||||
| 558 | FOREIGN KEY ( dependency ) REFERENCES distribution ( distribution ) | ||||||||||||||||||||||||||||
| 559 | ) | ||||||||||||||||||||||||||||
| 560 | END_SQL | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | # Fill the distribution dependency table | ||||||||||||||||||||||||||||
| 563 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 564 | INSERT INTO dependency | ||||||||||||||||||||||||||||
| 565 | SELECT | ||||||||||||||||||||||||||||
| 566 | distribution, | ||||||||||||||||||||||||||||
| 567 | dependency, | ||||||||||||||||||||||||||||
| 568 | phase, | ||||||||||||||||||||||||||||
| 569 | core | ||||||||||||||||||||||||||||
| 570 | FROM ( | ||||||||||||||||||||||||||||
| 571 | SELECT | ||||||||||||||||||||||||||||
| 572 | r.distribution as distribution, | ||||||||||||||||||||||||||||
| 573 | m.distribution as dependency, | ||||||||||||||||||||||||||||
| 574 | r.phase as phase, | ||||||||||||||||||||||||||||
| 575 | r.core as core | ||||||||||||||||||||||||||||
| 576 | FROM | ||||||||||||||||||||||||||||
| 577 | module m, | ||||||||||||||||||||||||||||
| 578 | t_requires r | ||||||||||||||||||||||||||||
| 579 | WHERE | ||||||||||||||||||||||||||||
| 580 | m.module == r.module | ||||||||||||||||||||||||||||
| 581 | ORDER BY | ||||||||||||||||||||||||||||
| 582 | distribution, | ||||||||||||||||||||||||||||
| 583 | phase, | ||||||||||||||||||||||||||||
| 584 | dependency, | ||||||||||||||||||||||||||||
| 585 | core | ||||||||||||||||||||||||||||
| 586 | ) | ||||||||||||||||||||||||||||
| 587 | GROUP BY | ||||||||||||||||||||||||||||
| 588 | distribution, | ||||||||||||||||||||||||||||
| 589 | dependency, | ||||||||||||||||||||||||||||
| 590 | phase | ||||||||||||||||||||||||||||
| 591 | END_SQL | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | # Index the distribution dependency table | ||||||||||||||||||||||||||||
| 594 | 0 | $self->create_index( dependency => qw{ | |||||||||||||||||||||||||||
| 595 | distribution | ||||||||||||||||||||||||||||
| 596 | dependency | ||||||||||||||||||||||||||||
| 597 | phase | ||||||||||||||||||||||||||||
| 598 | core | ||||||||||||||||||||||||||||
| 599 | } ); | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | # Generate the final version of the requires table | ||||||||||||||||||||||||||||
| 602 | # dropping the unneeded core column. | ||||||||||||||||||||||||||||
| 603 | 0 | $self->say('Generating table requires...'); | |||||||||||||||||||||||||||
| 604 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 605 | CREATE TABLE requires ( | ||||||||||||||||||||||||||||
| 606 | distribution TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 607 | module TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 608 | version TEXT NULL, | ||||||||||||||||||||||||||||
| 609 | phase TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 610 | PRIMARY KEY ( distribution, module, phase ), | ||||||||||||||||||||||||||||
| 611 | FOREIGN KEY ( distribution ) REFERENCES distribution ( distribution ), | ||||||||||||||||||||||||||||
| 612 | FOREIGN KEY ( module ) REFERENCES module ( module ) | ||||||||||||||||||||||||||||
| 613 | ) | ||||||||||||||||||||||||||||
| 614 | END_SQL | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | # Fill it | ||||||||||||||||||||||||||||
| 617 | 0 | $self->do(<<'END_SQL'); | |||||||||||||||||||||||||||
| 618 | INSERT INTO requires | ||||||||||||||||||||||||||||
| 619 | SELECT | ||||||||||||||||||||||||||||
| 620 | distribution, | ||||||||||||||||||||||||||||
| 621 | module, | ||||||||||||||||||||||||||||
| 622 | version, | ||||||||||||||||||||||||||||
| 623 | phase | ||||||||||||||||||||||||||||
| 624 | FROM | ||||||||||||||||||||||||||||
| 625 | t_requires | ||||||||||||||||||||||||||||
| 626 | ORDER BY | ||||||||||||||||||||||||||||
| 627 | distribution, | ||||||||||||||||||||||||||||
| 628 | phase, | ||||||||||||||||||||||||||||
| 629 | module | ||||||||||||||||||||||||||||
| 630 | END_SQL | ||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | # Add the indexes | ||||||||||||||||||||||||||||
| 633 | 0 | $self->create_index( requires => qw{ | |||||||||||||||||||||||||||
| 634 | distribution | ||||||||||||||||||||||||||||
| 635 | module | ||||||||||||||||||||||||||||
| 636 | version | ||||||||||||||||||||||||||||
| 637 | phase | ||||||||||||||||||||||||||||
| 638 | } ); | ||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||
| 640 | # Derive the distribution weights | ||||||||||||||||||||||||||||
| 641 | 0 | $self->say('Generating column distribution.weight...'); | |||||||||||||||||||||||||||
| 642 | SCOPE: { | ||||||||||||||||||||||||||||
| 643 | 0 | my $weight = $self->weight->weight_all; | |||||||||||||||||||||||||||
| 644 | 0 | $self->say('Populating column distribution.weight...'); | |||||||||||||||||||||||||||
| 645 | 0 | $self->dbh->begin_work; | |||||||||||||||||||||||||||
| 646 | 0 | foreach my $distribution ( sort keys %$weight ) { | |||||||||||||||||||||||||||
| 647 | $self->do( | ||||||||||||||||||||||||||||
| 648 | 'UPDATE distribution SET weight = ? WHERE distribution = ?', | ||||||||||||||||||||||||||||
| 649 | 0 | {}, $weight->{$distribution}, $distribution, | |||||||||||||||||||||||||||
| 650 | ); | ||||||||||||||||||||||||||||
| 651 | 0 | ▶ | next if ++$counter % 100; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 652 | 0 | $self->dbh->commit; | |||||||||||||||||||||||||||
| 653 | 0 | $self->dbh->begin_work; | |||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | 0 | $self->dbh->commit; | |||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||
| 658 | # Derive the distribution volatility | ||||||||||||||||||||||||||||
| 659 | 0 | $self->say('Generating column distribution.volatility...'); | |||||||||||||||||||||||||||
| 660 | SCOPE: { | ||||||||||||||||||||||||||||
| 661 | 0 | my $volatility = $self->volatility->weight_all; | |||||||||||||||||||||||||||
| 662 | 0 | $self->say('Populating column distribution.volatility...'); | |||||||||||||||||||||||||||
| 663 | 0 | $self->dbh->begin_work; | |||||||||||||||||||||||||||
| 664 | 0 | foreach my $distribution ( sort keys %$volatility ) { | |||||||||||||||||||||||||||
| 665 | $self->do( | ||||||||||||||||||||||||||||
| 666 | 'UPDATE distribution SET volatility = ? WHERE distribution = ?', | ||||||||||||||||||||||||||||
| 667 | 0 | {}, $volatility->{$distribution} - 1, $distribution, | |||||||||||||||||||||||||||
| 668 | ); | ||||||||||||||||||||||||||||
| 669 | 0 | ▶ | next if ++$counter % 100; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 670 | 0 | $self->dbh->commit; | |||||||||||||||||||||||||||
| 671 | 0 | $self->dbh->begin_work; | |||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||
| 673 | 0 | $self->dbh->commit; | |||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||
| 676 | # Populate distribution-level META.yml information | ||||||||||||||||||||||||||||
| 677 | 0 | $self->say('Generating columns distribution.(meta|license)...'); | |||||||||||||||||||||||||||
| 678 | SCOPE: { | ||||||||||||||||||||||||||||
| 679 | 0 | my $metas = $self->dbh->selectall_arrayref( | |||||||||||||||||||||||||||
| 680 | 'SELECT * FROM meta.meta_distribution', | ||||||||||||||||||||||||||||
| 681 | { Slice => {} }, | ||||||||||||||||||||||||||||
| 682 | ); | ||||||||||||||||||||||||||||
| 683 | 0 | $self->dbh->begin_work; | |||||||||||||||||||||||||||
| 684 | 0 | foreach my $meta ( @$metas ) { | |||||||||||||||||||||||||||
| 685 | $self->do( | ||||||||||||||||||||||||||||
| 686 | 'UPDATE distribution SET meta = ?, license = ? WHERE release = ?', | ||||||||||||||||||||||||||||
| 687 | {}, $meta->{meta}, $meta->{meta_license}, $meta->{release}, | ||||||||||||||||||||||||||||
| 688 | 0 | ); | |||||||||||||||||||||||||||
| 689 | 0 | ▶ | next if ++$counter % 100; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 690 | 0 | $self->dbh->commit; | |||||||||||||||||||||||||||
| 691 | 0 | $self->dbh->begin_work; | |||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||
| 693 | 0 | $self->dbh->commit; | |||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | # Fill the CPAN Testers totals | ||||||||||||||||||||||||||||
| 697 | 0 | $self->say("Generating columns distribution.(pass|fail|unknown|na)..."); | |||||||||||||||||||||||||||
| 698 | SCOPE: { | ||||||||||||||||||||||||||||
| 699 | 0 | my $testers = $self->dbh->selectall_arrayref( | |||||||||||||||||||||||||||
| 700 | 'SELECT * FROM t_testers', {} | ||||||||||||||||||||||||||||
| 701 | ); | ||||||||||||||||||||||||||||
| 702 | 0 | $self->dbh->begin_work; | |||||||||||||||||||||||||||
| 703 | 0 | foreach my $t ( @$testers ) { | |||||||||||||||||||||||||||
| 704 | 0 | $self->do( | |||||||||||||||||||||||||||
| 705 | "UPDATE distribution SET $t->[1] = ? WHERE distribution = ?", | ||||||||||||||||||||||||||||
| 706 | {}, $t->[2], $t->[0], | ||||||||||||||||||||||||||||
| 707 | ); | ||||||||||||||||||||||||||||
| 708 | 0 | ▶ | next if ++$counter % 100; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 709 | 0 | $self->dbh->commit; | |||||||||||||||||||||||||||
| 710 | 0 | $self->dbh->begin_work; | |||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||
| 712 | 0 | $self->dbh->commit; | |||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | # Index the rest of the distribution table | ||||||||||||||||||||||||||||
| 716 | 0 | $self->create_index( distribution => qw{ | |||||||||||||||||||||||||||
| 717 | version | ||||||||||||||||||||||||||||
| 718 | author | ||||||||||||||||||||||||||||
| 719 | meta | ||||||||||||||||||||||||||||
| 720 | license | ||||||||||||||||||||||||||||
| 721 | pass | ||||||||||||||||||||||||||||
| 722 | fail | ||||||||||||||||||||||||||||
| 723 | unknown | ||||||||||||||||||||||||||||
| 724 | na | ||||||||||||||||||||||||||||
| 725 | uploaded | ||||||||||||||||||||||||||||
| 726 | rating | ||||||||||||||||||||||||||||
| 727 | ratings | ||||||||||||||||||||||||||||
| 728 | weight | ||||||||||||||||||||||||||||
| 729 | volatility | ||||||||||||||||||||||||||||
| 730 | } ); | ||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||
| 732 | # Clean up tables | ||||||||||||||||||||||||||||
| 733 | 0 | $self->say("Dropping excess tables..."); | |||||||||||||||||||||||||||
| 734 | 0 | $self->do( "DROP TABLE t_requires" ); | |||||||||||||||||||||||||||
| 735 | 0 | $self->do( "DROP TABLE t_distribution" ); | |||||||||||||||||||||||||||
| 736 | 0 | $self->do( "DROP TABLE t_uploaded" ); | |||||||||||||||||||||||||||
| 737 | 0 | $self->do( "DROP TABLE t_cpanstats" ); | |||||||||||||||||||||||||||
| 738 | 0 | $self->do( "DROP TABLE t_testers" ); | |||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||
| 740 | # Clean up databases | ||||||||||||||||||||||||||||
| 741 | 0 | $self->say("Dropping attached databases..."); | |||||||||||||||||||||||||||
| 742 | 0 | $self->do( "DETACH DATABASE cpan" ); | |||||||||||||||||||||||||||
| 743 | 0 | $self->do( "DETACH DATABASE upload" ); | |||||||||||||||||||||||||||
| 744 | 0 | $self->do( "DETACH DATABASE meta" ); | |||||||||||||||||||||||||||
| 745 | 0 | $self->do( "DETACH DATABASE testers" ); | |||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||
| 747 | # Shrink the main database file | ||||||||||||||||||||||||||||
| 748 | 0 | $self->say("Freeing excess space..."); | |||||||||||||||||||||||||||
| 749 | 0 | $self->do( "VACUUM" ); | |||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | # Optimise the indexes | ||||||||||||||||||||||||||||
| 752 | 0 | $self->say("Optimising indexes..."); | |||||||||||||||||||||||||||
| 753 | 0 | $self->do( "ANALYZE main" ); | |||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||
| 755 | # Publish the database to the current directory | ||||||||||||||||||||||||||||
| 756 | 0 | ▶ | if ( defined $self->publish ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 757 | 0 | $self->say('Publishing the generated database...'); | |||||||||||||||||||||||||||
| 758 | 0 | Xtract::Publish->new( | |||||||||||||||||||||||||||
| 759 | from => $self->sqlite, | ||||||||||||||||||||||||||||
| 760 | sqlite => $self->publish, | ||||||||||||||||||||||||||||
| 761 | trace => $self->trace, | ||||||||||||||||||||||||||||
| 762 | raw => 0, | ||||||||||||||||||||||||||||
| 763 | gz => 1, | ||||||||||||||||||||||||||||
| 764 | bz2 => 1, | ||||||||||||||||||||||||||||
| 765 | lz => 1, | ||||||||||||||||||||||||||||
| 766 | )->run; | ||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||
| 769 | 0 | return 1; | |||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||
| 772 | 0 | ▶ | sub create_index { | ||||||||||||||||||||||||||
|
Subroutine
create_index: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 773 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 774 | 0 | my $table = shift; | |||||||||||||||||||||||||||
| 775 | 0 | foreach my $column ( @_ ) { | |||||||||||||||||||||||||||
| 776 | 0 | $self->do("CREATE INDEX ${table}__${column} ON ${table} ( ${column} )"); | |||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||
| 778 | 0 | return 1; | |||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||
| 785 | ###################################################################### | ||||||||||||||||||||||||||||
| 786 | # Weight and Volatility Math | ||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||
| 788 | 0 | ▶ | sub weight { | ||||||||||||||||||||||||||
|
Subroutine
weight: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 789 | 0 | Algorithm::Dependency::Weight->new( | |||||||||||||||||||||||||||
| 790 | source => $_[0]->weight_source, | ||||||||||||||||||||||||||||
| 791 | ); | ||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||
| 794 | 0 | ▶ | sub weight_source { | ||||||||||||||||||||||||||
|
Subroutine
weight_source: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 795 | 0 | Algorithm::Dependency::Source::DBI->new( | |||||||||||||||||||||||||||
| 796 | dbh => $_[0]->dbh, | ||||||||||||||||||||||||||||
| 797 | select_ids => "SELECT distribution FROM distribution WHERE distribution NOT LIKE 'Task-%' AND distribution NOT LIKE 'Acme-%'", | ||||||||||||||||||||||||||||
| 798 | select_depends => "SELECT DISTINCT distribution, dependency FROM dependency", | ||||||||||||||||||||||||||||
| 799 | ); | ||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||
| 802 | 0 | ▶ | sub volatility { | ||||||||||||||||||||||||||
|
Subroutine
volatility: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 803 | 0 | Algorithm::Dependency::Weight->new( | |||||||||||||||||||||||||||
| 804 | source => $_[0]->volatility_source, | ||||||||||||||||||||||||||||
| 805 | ); | ||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||
| 808 | 0 | ▶ | sub volatility_source { | ||||||||||||||||||||||||||
|
Subroutine
volatility_source: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 809 | 0 | Algorithm::Dependency::Source::DBI->new( | |||||||||||||||||||||||||||
| 810 | dbh => $_[0]->dbh, | ||||||||||||||||||||||||||||
| 811 | select_ids => "SELECT distribution FROM distribution", | ||||||||||||||||||||||||||||
| 812 | select_depends => "SELECT DISTINCT dependency, distribution FROM dependency", | ||||||||||||||||||||||||||||
| 813 | ); | ||||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||
| 820 | ###################################################################### | ||||||||||||||||||||||||||||
| 821 | # Support Methods | ||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||
| 823 | 0 | ▶ | sub do { | ||||||||||||||||||||||||||
|
Subroutine
do: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 824 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 825 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 826 | 0 | ▶ | unless ( $dbh->do(@_) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 827 | 0 | Carp::croak("Database Error: " . $dbh->errstr); | |||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||
| 829 | 0 | return 1; | |||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||
| 832 | 0 | ▶ | sub say { | ||||||||||||||||||||||||||
|
Subroutine
say: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 833 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 834 | 0 | ▶ | if ( Params::Util::_CODE($self->trace) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 835 | 0 | $self->trace->say( @_ ); | |||||||||||||||||||||||||||
| 836 | } elsif ( $self->trace ) { | ||||||||||||||||||||||||||||
| 837 | 0 | my $t = scalar localtime time; | |||||||||||||||||||||||||||
| 838 | 0 | print map { "[$t] $_\n" } @_; | |||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||
| 842 | 2 | 1; | |||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||
| 844 | =pod | ||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||
| 846 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||
| 848 | Bugs should be reported via the CPAN bug tracker at | ||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||
| 850 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPANDB-Generator> | ||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||
| 852 | For other issues, contact the author. | ||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||
| 854 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||
| 856 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||
| 858 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||
| 860 | Copyright 2009 Adam Kennedy. | ||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||
| 862 | This program is free software; you can redistribute | ||||||||||||||||||||||||||||
| 863 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||
| 865 | The full text of the license can be found in the | ||||||||||||||||||||||||||||
| 866 | LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||
| 868 | =cut | ||||||||||||||||||||||||||||