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 = '8.00';
20 55     55   25824 use Moo;
  55         271  
  55         329  
21 55     55   17747 use Search::Elasticsearch::Util qw(parse_params load_plugin);
  55         169  
  55         399  
22 55     55   19639 use namespace::clean;
  55         148  
  55         342  
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 66736 my ( $class, $params ) = parse_params(@_);
33 100         425 my %args = (%$params);
34 100         252 delete $args{nodes};
35              
36             my $cxn_class
37 100         304 = load_plugin( 'Search::Elasticsearch::Cxn', delete $args{cxn} );
38             $params->{_factory} = sub {
39 175     175   428 my ( $self, $node ) = @_;
40 175         3242 $cxn_class->new(
41             %args,
42             node => $node,
43             max_content_length => $self->max_content_length
44             );
45 100         2643 };
46 100         270 $params->{cxn_args} = \%args;
47 100         232 $params->{cxn_class} = $cxn_class;
48 100         2031 return $params;
49             }
50              
51             #===================================
52 175     175 0 639 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 8.00
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__