CPANTS-Weight

 view release on metacpan or  search on metacpan

lib/CPANTS/Weight.pm  view on Meta::CPAN

use Algorithm::Dependency::Weight           ();
use Algorithm::Dependency::Source::DBI 0.05 ();
use Algorithm::Dependency::Source::Invert   ();
use ORDB::CPANTS                       0.05 ();
use ORDB::CPANUploads                  0.04 ();
use ORDB::CPANTesters                  0.09 ();

our $VERSION = '0.15';

our $DEBUG;

sub trace {
	print STDERR "# $_[0]\n" if $DEBUG;
}

use constant ORLITE_FILE => File::Spec->catfile(
	File::HomeDir->my_data,
	($^O eq 'MSWin32' ? 'Perl' : '.perl'),
	'CPANTS-Weight',
	'CPANTS-Weight.sqlite',
);

use constant ORLITE_TIMELINE => File::Spec->catdir(
	File::ShareDir::dist_dir('CPANTS-Weight'),
	'timeline',
);

use ORLite          1.20 ();
use ORLite::Mirror  1.12 ();
use ORLite::Migrate 0.03 {
	file         => ORLITE_FILE,
	create       => 1,
	timeline     => ORLITE_TIMELINE,
	user_version => 3,
};

# Delay download/inflate for the ORDB:: modules until import,
# so we can pass them a common maxage param.
sub import {
	my $class  = shift;
	my $params = Params::Util::_HASH(shift) || {};

	# Download/inflate the CPANTS database
	ORDB::CPANTS->import( {
		maxage => $params->{maxage},
	} );

	# Download/inflate the CPAN PAUSE uploads database
	ORDB::CPANTUploads->import( {
		maxage => $params->{maxage},
	} );

	# Download/inflate the (huge) CPAN Testers database
	ORDB::CPANTesters->import( {
		maxage => $params->{maxage},
	} );

	return 1;
}

# Common string fragments
my $SELECT_IDS = <<'END_SQL';
select
	id
from
	dist
where
	id > 0
END_SQL

my $SELECT_DEPENDS = <<'END_SQL';
select
	dist,
	in_dist
from
	prereq
where
	in_dist is not null
	and
	dist > 0
	and
	in_dist > 0
END_SQL





#####################################################################
# Main Methods

# Only used internally, for caching reasons
sub new {
	my $class = shift;
	my $self  = bless { }, $class;
	return $self;
}

=pod

=head2 run

  CPANTS::Weight->run;

The main C<run> method does a complete generation cycle for the CPANTS
weighting database. It will retrieve the CPANTS data (if needed) calculate
the weights, and then (re)populate the CPANTS-Weight.sqlite database.

Once completed, the C<CPANTS::Weight-E<gt>sqlite> method can be used to
locate the completed SQLite database file.

=cut

sub run {
	my $self = ref($_[0]) ? shift : shift->new;

	# Run import if we haven't already
	ref($self)->import;

	# Skip if the output database is newer than the input database
	# (but is not a new database)



( run in 0.785 second using v1.01-cache-2.11-cpan-b16cb0d3907 )