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 59     59   7010826 use Moo 2.001000 ();
  59         359413  
  59         1526  
25              
26 59     59   22004 use OpenSearch::Client::Util qw(parse_params load_plugin);
  59         223  
  59         424  
27 59     59   38764 use namespace::clean;
  59         655818  
  59         334  
28              
29             our $VERSION = '3.007002';
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 7522035 my ( $class, $params ) = parse_params(@_);
53              
54 100   100     586 $params->{cxn} ||= 'HTTPTiny';
55 100   50     421 my $plugins = delete $params->{plugins} || [];
56 100 50       331 $plugins = [$plugins] unless ref $plugins eq 'ARRAY';
57              
58 100         256 for my $name (@Load_Order) {
59 600         89986 my ( $base, $default ) = @{ $Default_Plugins{$name} };
  600         1722  
60 600   100     2140 my $sub_class = $params->{$name} || $default;
61 600         1600 my $plugin_class = load_plugin( $base, $sub_class );
62 600         13498 $params->{$name} = $plugin_class->new($params);
63             }
64              
65 100         92145 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         1666 return $params->{client};
72             }
73              
74             1;
75              
76             __END__