Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a controller for File::download_url and exposed the matching mo…
…dule version. Tests are currently skipped
- Loading branch information
1 parent
f66ae99
commit 2f240c9
Showing
3 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package MetaCPAN::Server::Controller::Search::DownloadURL; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Moose; | ||
|
||
BEGIN { extends 'MetaCPAN::Server::Controller' } | ||
|
||
with 'MetaCPAN::Server::Role::JSONP'; | ||
|
||
has '+type' => ( default => 'file' ); | ||
|
||
sub get : Local : Path('/download_url') : Args(1) { | ||
my ( $self, $c, $module ) = @_; | ||
my $args = $c->req->params; | ||
|
||
my $model = $self->model($c); | ||
my $res = $model->find_download_url( $module, $args )->raw->all; | ||
my $hit = $res->{hits}{hits}[0] | ||
or return $c->detach( '/not_found', [] ); | ||
|
||
$c->stash( | ||
{ %{ $hit->{_source} }, | ||
%{ $hit->{inner_hits}{module}{hits}{hits}[0]{_source} } | ||
} | ||
); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use lib 't/lib'; | ||
use MetaCPAN::Server::Test; | ||
use MetaCPAN::TestHelpers; | ||
use Test::More skip_all => | ||
"Need to add CPAN::Test::Dummy::Perl5::VersionBump to CPAN::Faker and write tests"; | ||
|
||
use Log::Any::Adapter ( 'File', 'out' ); | ||
|
||
test_psgi app, sub { | ||
my $cb = shift; | ||
|
||
# test ES script using doc['blah'] value | ||
{ | ||
ok( my $res = $cb->( | ||
GET | ||
'/download_url/CPAN::Test::Dummy::Perl5::VersionBump::Decrease' | ||
), | ||
'GET' | ||
); | ||
my $json = decode_json_ok($res); | ||
|
||
use Data::Dump qw(pp); | ||
print STDERR ( pp( scalar $json ), "\n" ); | ||
|
||
# my $got | ||
# = [ map { $_->{_source}{documentation} } | ||
# @{ $json->{hits}{hits} } ]; | ||
# | ||
# is_deeply $got, [ | ||
# qw( | ||
# Multiple::Modules | ||
# Multiple::Modules::A | ||
# Multiple::Modules::B | ||
# Multiple::Modules::RDeps | ||
# Multiple::Modules::Tester | ||
# Multiple::Modules::RDeps::A | ||
# Multiple::Modules::RDeps::Deprecated | ||
# ) | ||
# ], | ||
# 'results are sorted by module name length' | ||
# or diag( Test::More::explain($got) ); | ||
# } | ||
}; | ||
}; | ||
|
||
done_testing; |