Pinto
view release on metacpan or search on metacpan
lib/Pinto/Repository.pm view on Meta::CPAN
# Retrieve latest version of package in the entire repository
elsif ($pkg_name) {
my $where = { name => $pkg_name };
my @pkgs = $self->db->schema->search_package($where)->with_distribution;
my $latest = ( sort { $a <=> $b } @pkgs )[-1];
return defined $latest ? $latest : ();
}
throw 'Invalid arguments';
}
#-------------------------------------------------------------------------------
sub get_distribution {
my ( $self, %args ) = @_;
# Retrieve a distribution by DistSpec or PackageSpec
if ( my $spec = $args{spec} ) {
if ( itis( $spec, 'Pinto::DistributionSpec' ) ) {
my $author = $spec->author;
my $archive = $spec->archive;
return $self->db->schema->distribution_rs->with_packages->find_by_author_archive( $author, $archive );
}
elsif ( itis( $spec, 'Pinto::PackageSpec' ) ) {
my $pkg = $self->get_package( name => $spec->name );
return () if !defined($pkg) or $pkg->version < $spec->version;
return $pkg->distribution;
}
throw 'Invalid arguments';
}
# Retrieve a distribution by its path (e.g. AUTHOR/Dist-1.0.tar.gz)
elsif ( my $path = $args{path} ) {
my ( $author, $archive ) = Pinto::Util::parse_dist_path($path);
return $self->db->schema->distribution_rs->with_packages->find_by_author_archive( $author, $archive );
}
# Retrieve a distribution by author and archive
elsif ( my $author = $args{author} ) {
my $archive = $args{archive} or throw "Must specify archive with author";
return $self->db->schema->distribution_rs->with_packages->find_by_author_archive( $author, $archive );
}
throw 'Invalid arguments';
}
#-------------------------------------------------------------------------------
sub ups_distribution {
my ( $self, %args ) = @_;
my $spec = $args{spec};
my $cascade = $args{cascade} || 0;
my $dist_url;
if ( Pinto::Util::itis( $spec, 'Pinto::PackageSpec' ) ) {
$dist_url = $self->locate( package => $spec->name, version => $spec->version, latest => $cascade );
}
elsif ( Pinto::Util::itis( $spec, 'Pinto::DistributionSpec' ) ) {
$dist_url = $self->locate( distribution => $spec->path );
}
else {
throw 'Invalid arguments';
}
throw "Cannot find $spec anywhere" if not $dist_url;
return $self->fetch_distribution( url => $dist_url );
}
#-------------------------------------------------------------------------------
sub add_distribution {
my ( $self, %args ) = @_;
my $archive = $args{archive};
my $author = uc $args{author};
my $source = $args{source} || 'LOCAL';
$self->assert_archive_not_duplicate( $author, $archive );
# Assemble the basic structure...
my $dist_struct = {
author => $author,
source => $source,
archive => $archive->basename,
mtime => Pinto::Util::mtime($archive),
md5 => Pinto::Util::md5($archive),
sha256 => Pinto::Util::sha256($archive)
};
my $extractor = Pinto::PackageExtractor->new( archive => $archive );
# Add provided packages...
my @provides = $extractor->provides;
$dist_struct->{packages} = \@provides;
# Add required packages...
my @requires = $extractor->requires;
$dist_struct->{prerequisites} = \@requires;
# Add metadata...
my $metadata = $extractor->metadata;
$dist_struct->{metadata} = $metadata;
my $p = scalar @provides;
my $r = scalar @requires;
debug "Distribution $archive provides $p and requires $r packages";
# Update database *before* moving the archive into the
# repository, so if there is an error in the DB, we can stop and
# the repository will still be clean.
my $dist = $self->db->schema->create_distribution($dist_struct);
$self->store->add_archive( $archive => $dist->native_path );
( run in 1.036 second using v1.01-cache-2.11-cpan-437f7b0c052 )