From e4f72f42d20bd0fc7f0320e2d7b413f48ee68b9a Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Mon, 18 Nov 2024 21:19:51 +0100 Subject: [PATCH] add ESQuery catalyst model --- lib/MetaCPAN/Server/Model/ESQuery.pm | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/MetaCPAN/Server/Model/ESQuery.pm diff --git a/lib/MetaCPAN/Server/Model/ESQuery.pm b/lib/MetaCPAN/Server/Model/ESQuery.pm new file mode 100644 index 000000000..e31615cc4 --- /dev/null +++ b/lib/MetaCPAN/Server/Model/ESQuery.pm @@ -0,0 +1,31 @@ +package MetaCPAN::Server::Model::ESQuery; + +use Moose; + +use MetaCPAN::Query (); + +extends 'Catalyst::Model'; + +has es => ( + is => 'ro', + writer => '_set_es', +); + +has _esx_query => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + MetaCPAN::Query->new( es => $self->es ); + }, +); + +sub ACCEPT_CONTEXT { + my ( $self, $c ) = @_; + if ( !$self->es ) { + $self->_set_es( $c->model('ES') ); + } + return $self->_esx_query; +} + +1;