CPANDB

 view release on metacpan or  search on metacpan

lib/CPANDB.pm  view on Meta::CPAN

package CPANDB; # git description: af7547f

use 5.008005;
use strict;
use warnings;
use IO::File             ();
use DateTime        0.55 ();
use Params::Util    1.00 ();
use ORLite          1.51 ();
use ORLite::Mirror  1.20 ();

our $VERSION = '0.19';
our @LOCATION = (
	locale    => 'C',
	time_zone => 'UTC',
);

sub import {
	my $class  = shift;
	my $params = Params::Util::_HASH(shift) || {};

	# Pass through any params from above
	$params->{url}    ||= 'http://svn.ali.as/db/cpandb.bz2';
	$params->{maxage} ||= 24 * 60 * 60; # One day

	# Always turn on string eval debugging if Perl is new enough
	if ( $^V > 5.008008 ) {
		$^P = $^P | 0x800;
	}

	# Prevent double-initialisation
	$class->can('orlite') or
	ORLite::Mirror->import( $params );

	return 1;
}

sub latest {
	my $class = shift;

	# Find the distribution most recently uploaded
	my @latest = CPANDB::Distribution->select(
		'ORDER BY uploaded DESC LIMIT 1',
	);
	unless ( @latest == 1 ) {
		die "Unexpected number of uploads";
	}

	# When was it?
	return $latest[0]->uploaded;
}

sub latest_datetime {
	my $class  = shift;
	my @latest = split /\D+/, $class->latest;
	return DateTime->new(
		year  => $latest[0],
		month => $latest[1],
		day   => $latest[2],
		@LOCATION,
	);
}

sub age {
	my $class    = shift;
	my $latest   = $class->latest_datetime;
	my $today    = DateTime->today( @LOCATION );
	my $duration = $today - $latest;
	return $duration->in_units('days');
}

sub distribution {
	my $self = shift;
	my @dist = CPANDB::Distribution->select(



( run in 1.055 second using v1.01-cache-2.11-cpan-ceb78f64989 )