CPAN-PackageDetails
view release on metacpan or search on metacpan
lib/CPAN/PackageDetails.pm view on Meta::CPAN
# file is gzipped
# check header # # # # # # # # # # # # # # # # # # #
my $packages = $class->read( $file );
# count of entries in non-zero # # # # # # # # # # # # # # # # # # #
my $header_count = $packages->get_header( 'line_count' );
my $entries_count = $packages->count;
unless( $header_count ) {
$error->{entry_count_mismatch} = 1;
$error->{line_count} = $header_count;
$error->{entry_count} = $entries_count;
$error->{error_count} += 1;
}
unless( $header_count == $entries_count ) {
$error->{entry_count_mismatch} = 1;
$error->{line_count} = $header_count;
$error->{entry_count} = $entries_count;
$error->{error_count} += 1;
}
if( $cpan_path ) {
my $missing_in_file = $packages->check_for_missing_dists_in_file( $cpan_path );
my $missing_in_repo = $packages->check_for_missing_dists_in_repo( $cpan_path );
$error->{missing_in_file} = $missing_in_file if @$missing_in_file;
$error->{missing_in_repo} = $missing_in_repo if @$missing_in_repo;
$error->{error_count} += @$missing_in_file + @$missing_in_repo;
}
croak $error if $error->{error_count};
return 1;
}
=item check_for_missing_dists_in_repo( CPAN_PATH )
Given an object and a CPAN_PATH, return an anonymous array of the
distributions in the object that are not in CPAN_PATH. That is,
complain when the object has extra distributions.
C<check_file> calls this for you and adds the result to its
error output.
=cut
sub check_for_missing_dists_in_repo {
my( $packages, $cpan_path ) = @_;
my @missing;
my( $entries ) = $packages->as_unique_sorted_list;
foreach my $entry ( @$entries ) {
my $path = $entry->path;
my $native_path = catfile( $cpan_path, split m|/|, $path );
push @missing, $path unless -e $native_path;
}
return \@missing;
}
=item check_for_missing_dists_in_file( CPAN_PATH )
Given an object and a CPAN_PATH, return an anonymous array of the
distributions in CPAN_PATH that do not show up in the object. That is,
complain when the object doesn't have all the dists.
C<check_file> calls this for you and adds the result to its
error output.
=cut
sub check_for_missing_dists_in_file {
my( $packages, $cpan_path ) = @_;
my $dists = $packages->_get_repo_dists( $cpan_path );
$packages->_filter_older_dists( $dists );
my %files = map { $_, 1 } @$dists;
use Data::Dumper;
my( $entries ) = $packages->as_unique_sorted_list;
foreach my $entry ( @$entries ) {
my $path = $entry->path;
my $native_path = catfile( $cpan_path, split m|/|, $path );
delete $files{$native_path};
}
[ keys %files ];
}
sub _filter_older_dists {
my( $self, $array ) = @_;
my %Seen;
my @order;
require CPAN::DistnameInfo;
foreach my $path ( @$array ) {
my( $basename, $directory, $suffix ) = fileparse( $path, qw(.tar.gz .tgz .zip .tar.bz2) );
my( $name, $version, $developer ) = CPAN::DistnameInfo::distname_info( $basename );
my $tuple = [ $path, $name, $version ];
push @order, $name;
# first branch, haven't seen the distro yet
if( ! exists $Seen{ $name } ) { $Seen{ $name } = $tuple }
# second branch, the version we see now is greater than before
elsif( $Seen{ $name }[2] lt $version ) { $Seen{ $name } = $tuple }
# third branch, nothing. Really? Are you sure there's not another case?
else { () }
}
@$array = map {
if( exists $Seen{$_} ) {
my $dist = $Seen{$_}[0];
delete $Seen{$_};
$dist;
}
else {
()
}
} @order;
return 1;
}
sub _distname_info {
my $file = shift or return;
my ($dist, $version) = $file =~ /^
( # start of dist name
(?:
[-+.]*
(?:
[A-Za-z0-9]+
|
(?<=\D)_
|
_(?=\D)
)*
(?:
[A-Za-z]
(?=
( run in 0.769 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )