File tree Expand file tree Collapse file tree 4 files changed +101
-11
lines changed
ElasticSearchX/Model/Document Expand file tree Collapse file tree 4 files changed +101
-11
lines changed Original file line number Diff line number Diff line change 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;
Original file line number Diff line number Diff line change 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;
Original file line number Diff line number Diff line change @@ -2,14 +2,15 @@ package MetaCPAN::Role::Script;
22
33use 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
1415use MooseX::Getopt::OptionTypeMap ();
1516for 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
142145sub _build_ua {
Original file line number Diff line number Diff line change @@ -2,7 +2,8 @@ package MetaCPAN::Server::Model::ESModel;
22
33use Moose;
44
5- use MetaCPAN::Model ();
5+ use MetaCPAN::Model ();
6+ use MetaCPAN::Model::ESWrapper ();
67
78extends ' 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
You can’t perform that action at this time.
0 commit comments