File Coverage

blib/lib/Search/Elasticsearch/Cxn/Factory.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 26 28 92.8


line stmt bran cond sub pod time code
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::Cxn::Factory;
19             $Search::Elasticsearch::Cxn::Factory::VERSION = '7.717';
20 55     55   23235 use Moo;
  55         108  
  55         456  
21 55     55   15211 use Search::Elasticsearch::Util qw(parse_params load_plugin);
  55         101  
  55         508  
22 55     55   16724 use namespace::clean;
  55         102  
  55         343  
23              
24             has 'cxn_class' => ( is => 'ro', required => 1 );
25             has '_factory' => ( is => 'ro', required => 1 );
26             has 'default_host' => ( is => 'ro', default => 'http://localhost:9200' );
27             has 'max_content_length' => ( is => 'rw', default => 104_857_600 );
28              
29             #===================================
30             sub BUILDARGS {
31             #===================================
32 100     100 0 57706 my ( $class, $params ) = parse_params(@_);
33 100         344 my %args = (%$params);
34 100         223 delete $args{nodes};
35              
36             my $cxn_class
37 100         273 = load_plugin( 'Search::Elasticsearch::Cxn', delete $args{cxn} );
38             $params->{_factory} = sub {
39 175     175   353 my ( $self, $node ) = @_;
40 175         2533 $cxn_class->new(
41             %args,
42             node => $node,
43             max_content_length => $self->max_content_length
44             );
45 100         2121 };
46 100         221 $params->{cxn_args} = \%args;
47 100         204 $params->{cxn_class} = $cxn_class;
48 100         1671 return $params;
49             }
50              
51             #===================================
52 175     175 0 577 sub new_cxn { shift->_factory->(@_) }
53             #===================================
54              
55             1;
56              
57             =pod
58              
59             =encoding UTF-8
60              
61             =head1 NAME
62              
63             Search::Elasticsearch::Cxn::Factory - Used by CxnPools to create new Cxn instances.
64              
65             =head1 VERSION
66              
67             version 7.717
68              
69             =head1 DESCRIPTION
70              
71             This class is used by the L implementations
72             to create new L-based instances. It holds on
73             to all the configuration options passed to L so
74             that new Cxns can use them.
75              
76             It contains no user serviceable parts.
77              
78             =head1 AUTHOR
79              
80             Enrico Zimuel
81              
82             =head1 COPYRIGHT AND LICENSE
83              
84             This software is Copyright (c) 2022 by Elasticsearch BV.
85              
86             This is free software, licensed under:
87              
88             The Apache License, Version 2.0, January 2004
89              
90             =cut
91              
92             __END__