File Coverage

blib/lib/Elasticsearch/Cxn/Factory.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 27 29 93.1


line stmt bran cond sub pod time code
1             package Elasticsearch::Cxn::Factory;
2             $Elasticsearch::Cxn::Factory::VERSION = '1.05';
3 42     42   39868 use Moo;
  42         107  
  42         324  
4 42     42   16829 use Elasticsearch::Util qw(parse_params load_plugin);
  42         94  
  42         398  
5 42     42   18919 use namespace::clean;
  42         101  
  42         433  
6              
7             has 'cxn_class' => ( is => 'ro', required => 1 );
8             has '_factory' => ( is => 'ro', required => 1 );
9             has 'default_host' => ( is => 'ro', required => 1 );
10             has 'max_content_length' => ( is => 'rw', default => 104_857_600 );
11              
12             #===================================
13             sub BUILDARGS {
14             #===================================
15 71     71 0 59740 my ( $class, $params ) = parse_params(@_);
16 71         507 my %args = (%$params);
17 71         248 delete $args{nodes};
18              
19 71         347 my $cxn_class = load_plugin( 'Elasticsearch::Cxn', delete $args{cxn} );
20             $params->{_factory} = sub {
21 147     147   323 my ( $self, $node ) = @_;
22 147         4133 $cxn_class->new(
23             %args,
24             node => $node,
25             max_content_length => $self->max_content_length
26             );
27 71         2187 };
28 71         668 $params->{default_host} = $cxn_class->default_host;
29 71         247 $params->{cxn_args} = \%args;
30 71         358 $params->{cxn_class} = $cxn_class;
31 71         1937 return $params;
32             }
33              
34             #===================================
35 147     147 0 855 sub new_cxn { shift->_factory->(@_) }
36             #===================================
37              
38             1;
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             Elasticsearch::Cxn::Factory - Used by CxnPools to create new Cxn instances.
47              
48             =head1 VERSION
49              
50             version 1.05
51              
52             =head1 DESCRIPTION
53              
54             This class is used by the L<Elasticsearch::Role::CxnPool> implementations
55             to create new L<Elasticsearch::Role::Cxn>-based instances. It holds on
56             to all the configuration options passed to L<Elasticsearhch/new()> so
57             that new Cxns can use them.
58              
59             It contains no user serviceable parts.
60              
61             =head1 AUTHOR
62              
63             Clinton Gormley <drtech@cpan.org>
64              
65             =head1 COPYRIGHT AND LICENSE
66              
67             This software is Copyright (c) 2014 by Elasticsearch BV.
68              
69             This is free software, licensed under:
70              
71             The Apache License, Version 2.0, January 2004
72              
73             =cut
74              
75             __END__
76              
77             # ABSTRACT: Used by CxnPools to create new Cxn instances.
78