File Coverage

blib/lib/OpenSearch/Client.pm
Criterion Covered Total %
statement 21 23 91.3
branch 1 2 50.0
condition 6 7 85.7
subroutine 4 4 100.0
pod 0 1 0.0
total 32 37 86.4


line stmt bran cond sub pod time code
1             # OpenSearch::Client is an unofficial client for OpenSearch.
2             # It is derived from Search::Elasticsearch version 7.714
3             # License details from that work are contained in the NOTICE
4             # file distributed with this work.
5             #-----------------------------------------------------------------------
6             # OpenSearch::Client
7             #-----------------------------------------------------------------------
8             # Copyright 2026 Mark Dootson
9             #
10             # Licensed under the Apache License, Version 2.0 (the "License");
11             # you may not use this file except in compliance with the License.
12             # You may obtain a copy of the License at
13             #
14             # http://www.apache.org/licenses/LICENSE-2.0
15             #
16             # Unless required by applicable law or agreed to in writing, software
17             # distributed under the License is distributed on an "AS IS" BASIS,
18             # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19             # See the License for the specific language governing permissions and
20             # limitations under the License.
21              
22             package OpenSearch::Client;
23              
24 60     60   7149444 use Moo 2.001000 ();
  60         378646  
  60         1626  
25              
26 60     60   23967 use OpenSearch::Client::Util qw(parse_params load_plugin);
  60         188  
  60         417  
27 60     60   40536 use namespace::clean;
  60         679910  
  60         403  
28              
29             our $VERSION = '3.007005';
30              
31             my %Default_Plugins = (
32             client => [ 'OpenSearch::Client::Core', '3_0::Direct' ],
33             cxn_factory => [ 'OpenSearch::Client::Cxn::Factory', '' ],
34             cxn_pool => [ 'OpenSearch::Client::CxnPool', 'Static' ],
35             logger => [ 'OpenSearch::Client::Logger', 'LogAny' ],
36             serializer => [ 'OpenSearch::Client::Serializer', 'JSON' ],
37             transport => [ 'OpenSearch::Client::Transport', '' ],
38             );
39              
40             my @Load_Order = qw(
41             serializer
42             logger
43             cxn_factory
44             cxn_pool
45             transport
46             client
47             );
48              
49             #===================================
50             sub new {
51             #===================================
52 100     100 0 7820200 my ( $class, $params ) = parse_params(@_);
53              
54 100   100     651 $params->{cxn} ||= 'HTTPTiny';
55 100   50     443 my $plugins = delete $params->{plugins} || [];
56 100 50       362 $plugins = [$plugins] unless ref $plugins eq 'ARRAY';
57              
58 100         265 for my $name (@Load_Order) {
59 600         93624 my ( $base, $default ) = @{ $Default_Plugins{$name} };
  600         1847  
60 600   100     2424 my $sub_class = $params->{$name} || $default;
61 600         1781 my $plugin_class = load_plugin( $base, $sub_class );
62 600         16310 $params->{$name} = $plugin_class->new($params);
63             }
64              
65 100         96739 for my $name (@$plugins) {
66 0         0 my $plugin_class
67             = load_plugin( 'OpenSearch::Client::Plugin', $name );
68 0         0 $plugin_class->_init_plugin($params);
69             }
70              
71 100         1961 return $params->{client};
72             }
73              
74             1;
75              
76             __END__