Skip to content

Commit e783c2b

Browse files
committed
add additional hacks around to ESXM to avoid type on ES7
1 parent a5aa6e5 commit e783c2b

File tree

4 files changed

+101
-11
lines changed

4 files changed

+101
-11
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ElasticSearchX::Model::Document::Role;
2+
use strict;
3+
use warnings;
4+
5+
use MetaCPAN::Model::Hacks;
6+
7+
no warnings 'redefine';
8+
9+
my $_put = \&_put;
10+
*_put = sub {
11+
my ($self) = @_;
12+
my $es = $self->index->model->es;
13+
14+
my %return = &$_put;
15+
16+
if ( $es->api_version le '6_0' ) {
17+
return %return;
18+
}
19+
20+
delete $return{type};
21+
return %return;
22+
};
23+
24+
1;

lib/MetaCPAN/Model/ESWrapper.pm

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package MetaCPAN::Model::ESWrapper;
2+
use strict;
3+
use warnings;
4+
5+
use MetaCPAN::Types::TypeTiny qw(ES);
6+
7+
sub new {
8+
my ( $class, $es ) = @_;
9+
if ( $es->api_version le '6_0' ) {
10+
return $es;
11+
}
12+
return bless { es => ES->assert_coerce($es) }, $class;
13+
}
14+
15+
sub DESTROY { }
16+
17+
sub AUTOLOAD {
18+
my $sub = our $AUTOLOAD =~ s/.*:://r;
19+
my $self = shift;
20+
$self->{es}->$sub(@_);
21+
}
22+
23+
sub _args {
24+
my $self = shift;
25+
if ( @_ == 1 ) {
26+
return ( $self, %{ $_[0] } );
27+
}
28+
return ( $self, @_ );
29+
}
30+
31+
sub count {
32+
my ( $self, %args ) = &_args;
33+
delete $args{type};
34+
$self->{es}->count(%args);
35+
}
36+
37+
sub get {
38+
my ( $self, %args ) = &_args;
39+
delete $args{type};
40+
$self->{es}->get(%args);
41+
}
42+
43+
sub delete {
44+
my ( $self, %args ) = &_args;
45+
delete $args{type};
46+
$self->{es}->delete(%args);
47+
}
48+
49+
sub search {
50+
my ( $self, %args ) = &_args;
51+
delete $args{type};
52+
$self->{es}->search(%args);
53+
}
54+
55+
sub scroll_helper {
56+
my ( $self, %args ) = &_args;
57+
delete $args{type};
58+
$self->{es}->scroll_helper(%args);
59+
}
60+
61+
1;

lib/MetaCPAN/Role/Script.pm

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package MetaCPAN::Role::Script;
22

33
use Moose::Role;
44

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( AbsPath Bool ES HashRef Int Path Str );
10-
use MetaCPAN::Util qw( root_dir );
11-
use Mojo::Server ();
12-
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( AbsPath Bool ES HashRef Int Path Str );
10+
use MetaCPAN::Util qw( root_dir );
11+
use Mojo::Server ();
12+
use Term::ANSIColor qw( colored );
13+
use MetaCPAN::Model::ESWrapper ();
1314

1415
use MooseX::Getopt::OptionTypeMap ();
1516
for my $type ( Path, AbsPath, ES ) {
@@ -136,7 +137,9 @@ sub _build_model {
136137
my $self = shift;
137138

138139
# es provided by ElasticSearchX::Model::Role
139-
return MetaCPAN::Model->new( es => $self->es );
140+
141+
my $es = MetaCPAN::Model::ESWrapper->new( $self->es );
142+
return MetaCPAN::Model->new( es => $es );
140143
}
141144

142145
sub _build_ua {

lib/MetaCPAN/Server/Model/ESModel.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package MetaCPAN::Server::Model::ESModel;
22

33
use Moose;
44

5-
use MetaCPAN::Model ();
5+
use MetaCPAN::Model ();
6+
use MetaCPAN::Model::ESWrapper ();
67

78
extends 'Catalyst::Model';
89

@@ -16,7 +17,8 @@ has _esx_model => (
1617
lazy => 1,
1718
default => sub {
1819
my $self = shift;
19-
MetaCPAN::Model->new( es => $self->es );
20+
my $es = MetaCPAN::Model::ESWrapper->new( $self->es );
21+
MetaCPAN::Model->new( es => $es );
2022
},
2123
);
2224

0 commit comments

Comments
 (0)