| 1 | # Licensed to Elasticsearch B.V. under one or more contributor | ||
| 2 | # license agreements. See the NOTICE file distributed with | ||
| 3 | # this work for additional information regarding copyright | ||
| 4 | # ownership. Elasticsearch B.V. licenses this file to you under | ||
| 5 | # the Apache License, Version 2.0 (the "License"); you may | ||
| 6 | # not use this file except in compliance with the License. | ||
| 7 | # You may obtain a copy of the License at | ||
| 8 | # | ||
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | # | ||
| 11 | # Unless required by applicable law or agreed to in writing, | ||
| 12 | # software distributed under the License is distributed on an | ||
| 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| 14 | # KIND, either express or implied. See the License for the | ||
| 15 | # specific language governing permissions and limitations | ||
| 16 | # under the License. | ||
| 17 | |||
| 18 | package Search::Elasticsearch::Client::8_0::Role::Scroll; | ||
| 19 | $Search::Elasticsearch::Client::8_0::Role::Scroll::VERSION = '8.12'; | ||
| 20 | use Moo::Role; | ||
| 21 | requires 'finish'; | ||
| 22 | use Search::Elasticsearch::Util qw(parse_params throw); | ||
| 23 | use Devel::GlobalDestruction; | ||
| 24 | use namespace::clean; | ||
| 25 | has 'es' => ( is => 'ro', required => 1 ); | ||
| 26 | has 'scroll' => ( is => 'ro' ); | ||
| 27 | has 'total' => ( is => 'rwp' ); | ||
| 28 | has 'max_score' => ( is => 'rwp' ); | ||
| 29 | has 'facets' => ( is => 'rwp' ); | ||
| 30 | has 'aggregations' => ( is => 'rwp' ); | ||
| 31 | has 'suggest' => ( is => 'rwp' ); | ||
| 32 | has 'took' => ( is => 'rwp' ); | ||
| 33 | has 'total_took' => ( is => 'rwp' ); | ||
| 34 | has 'search_params' => ( is => 'ro' ); | ||
| 35 | has 'is_finished' => ( is => 'rwp', default => '' ); | ||
| 36 | has '_pid' => ( is => 'ro', default => sub {$$} ); | ||
| 37 | has '_scroll_id' => ( is => 'rwp', clearer => 1, predicate => 1 ); | ||
| 38 | |||
| 39 | #=================================== | ||
| 40 | sub scroll_request { | ||
| 41 | #=================================== | ||
| 42 | my $self = shift; | ||
| 43 | throw( 'Illegal', | ||
| 44 | 'Scroll requests are not fork safe and may only be ' | ||
| 45 | . 'refilled by the same process that created the instance.' ) | ||
| 46 | if $self->_pid != $$; | ||
| 47 | |||
| 48 | my %args = ( scroll => $self->scroll ); | ||
| 49 | $args{body} = { scroll_id => $self->_scroll_id }; | ||
| 50 | $self->es->scroll(%args); | ||
| 51 | } | ||
| 52 | |||
| 53 | #=================================== | ||
| 54 | sub DEMOLISH { | ||
| 55 | #=================================== | ||
| 56 | my $self = shift or return; | ||
| 57 | return if in_global_destruction; | ||
| 58 | $self->finish; | ||
| 59 | } | ||
| 60 | |||
| 61 | 1; | ||
| 62 | |||
| 63 | # ABSTRACT: Provides common functionality to L<Search::Elasticsearch::Client::8_0::Scroll> and L<Search::Elasticsearch::Client::8_0::Async::Scroll> | ||
| 64 | |||
| 65 | __END__ |