Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit df4d868

Browse files
committedJan 29, 2025
use our own ES type using Type::Tiny
1 parent bb2560c commit df4d868

File tree

8 files changed

+57
-30
lines changed

8 files changed

+57
-30
lines changed
 

‎lib/Catalyst/Plugin/Session/Store/ElasticSearch.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package Catalyst::Plugin::Session::Store::ElasticSearch;
44

55
use Moose;
66
extends 'Catalyst::Plugin::Session::Store';
7-
use MooseX::Types::ElasticSearch qw( ES );
7+
use MetaCPAN::Types::TypeTiny qw( ES );
88

99
use MetaCPAN::ESConfig qw( es_doc_path );
1010
use MetaCPAN::Server::Config ();

‎lib/MetaCPAN/API.pm

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ To run the api web server, run the following on one of the servers:
1919

2020
use Mojo::Base 'Mojolicious';
2121

22-
use File::Temp ();
23-
use List::Util qw( any );
24-
use MetaCPAN::Script::Runner ();
25-
use Search::Elasticsearch ();
26-
use Try::Tiny qw( catch try );
27-
use MetaCPAN::Server::Config ();
28-
use MooseX::Types::ElasticSearch qw(ES);
22+
use File::Temp ();
23+
use List::Util qw( any );
24+
use MetaCPAN::Script::Runner ();
25+
use Search::Elasticsearch ();
26+
use Try::Tiny qw( catch try );
27+
use MetaCPAN::Server::Config ();
28+
use MooseX::Types::TypeTiny qw( ES );
2929

3030
has es => sub {
3131
ES->assert_coerce(

‎lib/MetaCPAN/Query.pm

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package MetaCPAN::Query;
22
use Moose;
33

4-
use Module::Runtime qw( require_module );
5-
use Module::Pluggable::Object ();
6-
use MooseX::Types::ElasticSearch qw( ES );
4+
use Module::Runtime qw( require_module );
5+
use Module::Pluggable::Object ();
6+
use MooseX::Types::TypeTiny qw( ES );
77

88
has es => (
99
is => 'ro',

‎lib/MetaCPAN/Query/Role/Common.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package MetaCPAN::Query::Role::Common;
22
use Moose::Role;
33

4-
use MooseX::Types::ElasticSearch qw( ES );
4+
use MooseX::Types::TypeTiny qw( ES );
55

66
has es => (
77
is => 'ro',

‎lib/MetaCPAN/Role/Script.pm

+9-10
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ package MetaCPAN::Role::Script;
22

33
use Moose::Role;
44

5-
use Carp ();
6-
use MooseX::Types::ElasticSearch qw( ES );
7-
use IO::Prompt::Tiny qw( prompt );
8-
use Log::Contextual qw( :log :dlog );
9-
use MetaCPAN::Model ();
10-
use MetaCPAN::Types::TypeTiny qw( Bool HashRef Int Path Str );
11-
use MetaCPAN::Util qw( root_dir );
12-
use Mojo::Server ();
13-
use Term::ANSIColor qw( colored );
5+
use Carp ();
6+
use IO::Prompt::Tiny qw( prompt );
7+
use Log::Contextual qw( :log :dlog );
8+
use MetaCPAN::Model ();
9+
use MetaCPAN::Types::TypeTiny qw( Bool ES HashRef Int Path Str );
10+
use MetaCPAN::Util qw( root_dir );
11+
use Mojo::Server ();
12+
use Term::ANSIColor qw( colored );
1413

1514
use MooseX::Getopt::OptionTypeMap ();
16-
for my $type ( Path, AbsPath ) {
15+
for my $type ( Path, AbsPath, ES ) {
1716
MooseX::Getopt::OptionTypeMap->add_option_type_to_map( $type, '=s' );
1817
}
1918

‎lib/MetaCPAN/Server/Model/ES.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package MetaCPAN::Server::Model::ES;
22

33
use Moose;
44

5-
use MetaCPAN::Server::Config ();
6-
use MooseX::Types::ElasticSearch qw( ES );
5+
use MetaCPAN::Server::Config ();
6+
use MooseX::Types::TypeTiny qw( ES );
77

88
extends 'Catalyst::Model';
99

‎lib/MetaCPAN/Types/TypeTiny.pm

+28
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use Type::Library -base, -declare => ( qw(
2020
HashRefCPANMeta
2121
2222
CommaSepOption
23+
24+
ES
2325
) );
2426
use Type::Utils qw( as coerce declare extends from via );
2527

@@ -129,4 +131,30 @@ coerce CommaSepOption, from Str, via {
129131
return [ map split(/\s*,\s*/), $_ ];
130132
};
131133

134+
declare ES, as Object;
135+
coerce ES, from Str, via {
136+
my $server = $_;
137+
$server = "127.0.0.1$server" if ( $server =~ /^:/ );
138+
return Search::Elasticsearch->new(
139+
nodes => $server,
140+
cxn => 'HTTPTiny',
141+
);
142+
};
143+
144+
coerce ES, from HashRef, via {
145+
return Search::Elasticsearch->new( {
146+
cxn => 'HTTPTiny',
147+
%$_,
148+
} );
149+
};
150+
151+
coerce ES, from ArrayRef, via {
152+
my @servers = @$_;
153+
@servers = map { /^:/ ? "127.0.0.1$_" : $_ } @servers;
154+
return Search::Elasticsearch->new(
155+
nodes => \@servers,
156+
cxn => 'HTTPTiny',
157+
);
158+
};
159+
132160
1;

‎t/lib/MetaCPAN/Server/Test.pm

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use strict;
44
use warnings;
55
use feature qw(state);
66

7-
use HTTP::Request::Common qw( DELETE GET POST ); ## no perlimports
8-
use MetaCPAN::Model ();
9-
use MetaCPAN::Server ();
10-
use MetaCPAN::Server::Config ();
11-
use MooseX::Types::ElasticSearch qw( ES );
12-
use Plack::Test; ## no perlimports
7+
use HTTP::Request::Common qw( DELETE GET POST ); ## no perlimports
8+
use MetaCPAN::Model ();
9+
use MetaCPAN::Server ();
10+
use MetaCPAN::Server::Config ();
11+
use MooseX::Types::TypeTiny qw( ES );
12+
use Plack::Test; ## no perlimports
1313

1414
use base 'Exporter';
1515
our @EXPORT_OK = qw(

0 commit comments

Comments
 (0)
Please sign in to comment.