Skip to content

Commit

Permalink
some code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Nov 1, 2017
1 parent d09bdfa commit d55664c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 49 deletions.
84 changes: 41 additions & 43 deletions lib/MetaCPAN/Document/File/Set.pm
Expand Up @@ -3,6 +3,7 @@ package MetaCPAN::Document::File::Set;
use Moose;

use MetaCPAN::Util qw( single_valued_arrayref_to_scalar );
use Ref::Util qw( is_hashref );

extends 'ElasticSearchX::Model::Document::Set';

Expand Down Expand Up @@ -716,54 +717,51 @@ sub find_changes_files {
);

# use $c->model b/c we can't let any filters apply here
my $file = eval {
$self->raw->filter(
{
and => [
{ term => { release => $release } },
{ term => { author => $author } },
{
or => [
my $file = $self->raw->filter(
{
and => [
{ term => { release => $release } },
{ term => { author => $author } },
{
or => [

# if it's a perl release, get perldelta
{
and => [
{ term => { distribution => 'perl' } },
{
term => {
'name' => 'perldelta.pod'
}
},
]
},
# if it's a perl release, get perldelta
{
and => [
{ term => { distribution => 'perl' } },
{
term => {
'name' => 'perldelta.pod'
}
},
]
},

# otherwise look for one of these candidates in the root
{
and => [
{ term => { level => 0 } },
{ term => { directory => 0 } },
{
or => [
map {
{ term => { 'name' => $_ } }
} @candidates
]
}
]
}
],
}
]
}
)->size(1)
{
and => [
{ term => { level => 0 } },
{ term => { directory => 0 } },
{
or => [
map { { term => { 'name' => $_ } } }
@candidates
]
}
]
}
],
}
]
}
)->size(1)

# HACK: Sort by level/desc to put pod/perldeta.pod first (if found)
# otherwise sort root files by name and select the first.
->sort( [ { level => 'desc' }, { name => 'asc' } ] )
->first->{_source};
};
# HACK: Sort by level/desc to put pod/perldeta.pod first (if found)
# otherwise sort root files by name and select the first.
->sort( [ { level => 'desc' }, { name => 'asc' } ] )->first;

return $file;
return unless is_hashref($file);
return $file->{_source};
}

__PACKAGE__->meta->make_immutable;
Expand Down
12 changes: 6 additions & 6 deletions lib/MetaCPAN/Document/Release/Set.pm
Expand Up @@ -13,15 +13,15 @@ sub author_status {
my ( $self, $id, $file ) = @_;
return unless $id and $file;

my $st = $file->{_source}
my $status = $file->{_source}
|| single_valued_arrayref_to_scalar( $file->{fields} );

if ( $st and $st->{pauseid} ) {
$st->{release_count}
= $self->aggregate_status_by_author( $st->{pauseid} );
if ( $status and $status->{pauseid} ) {
$status->{release_count}
= $self->aggregate_status_by_author( $status->{pauseid} );

my ( $id_2, $id_1 ) = $id =~ /^((\w)\w)/;
$st->{links} = {
$status->{links} = {
cpan_directory => "http://cpan.org/authors/id/$id_1/$id_2/$id",
backpan_directory =>
"https://cpan.metacpan.org/authors/id/$id_1/$id_2/$id",
Expand All @@ -34,7 +34,7 @@ sub author_status {
};
}

return $st;
return $status;
}

sub aggregate_status_by_author {
Expand Down

0 comments on commit d55664c

Please sign in to comment.