File Coverage

blib/lib/Cassandra/Client/Config.pm
Criterion Covered Total %
statement 11 46 23.9
branch 0 32 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 15 84 17.8


line stmt bran cond sub pod time code
1             package Cassandra::Client::Config;
2             our $AUTHORITY = 'cpan:TVDW';
3             $Cassandra::Client::Config::VERSION = '0.13_006'; # TRIAL
4              
5 1     1   20 $Cassandra::Client::Config::VERSION = '0.13006';use 5.010;
  1         5  
6 1     1   8 use strict;
  1         3  
  1         29  
7 1     1   8 use warnings;
  1         2  
  1         46  
8              
9 1     1   412 use Ref::Util qw/is_plain_arrayref/;
  1         1854  
  1         600  
10              
11             sub new {
12 0     0 0   my ($class, $config)= @_;
13              
14 0           my $self= bless {
15             anyevent => 0,
16             contact_points => undef,
17             port => 9042,
18             cql_version => undef,
19             keyspace => undef,
20             compression => undef,
21             default_consistency => undef,
22             max_page_size => 5000,
23             max_connections => 2,
24             timer_granularity => 0.1,
25             request_timeout => 11,
26             warmup => 0,
27             max_concurrent_queries => 1000,
28             tls => 0,
29              
30             throttler => undef,
31             command_queue => undef,
32             retry_policy => undef,
33             load_balancing_policy => undef,
34             }, $class;
35              
36 0 0         if (my $cp= $config->{contact_points}) {
37 0 0         if (is_plain_arrayref($cp)) {
38 0           @{$self->{contact_points}=[]}= @$cp;
  0            
39 0           } else { die "contact_points must be an arrayref"; }
40 0           } else { die "contact_points not specified"; }
41              
42             # Booleans
43 0           for (qw/anyevent warmup tls/) {
44 0 0         if (exists($config->{$_})) {
45 0           $self->{$_}= !!$config->{$_};
46             }
47             }
48              
49             # Numbers
50 0           for (qw/port timer_granularity request_timeout max_connections max_concurrent_queries/) {
51 0 0         if (defined($config->{$_})) {
52 0           $self->{$_}= 0+ $config->{$_};
53             }
54             }
55 0           for (qw/max_page_size/) {
56 0 0         if (exists($config->{$_})) {
57 0 0         $self->{$_}= defined($config->{$_}) ? (0+ $config->{$_}) : undef;
58             }
59             }
60              
61             # Strings
62 0           for (qw/cql_version keyspace compression default_consistency/) {
63 0 0         if (exists($config->{$_})) {
64 0 0         $self->{$_}= defined($config->{$_}) ? "$config->{$_}" : undef;
65             }
66             }
67              
68 0 0         if (exists($config->{throttler})) {
69             die "throttler must be a Cassandra::Client::Policy::Throttle::Default"
70 0 0         unless $config->{throttler}->isa("Cassandra::Client::Policy::Throttle::Default");
71 0           $self->{throttler}= $config->{throttler};
72             }
73 0 0         if (exists($config->{retry_policy})) {
74             die "retry_policy must be a Cassandra::Client::Policy::Retry::Default"
75 0 0         unless $config->{retry_policy}->isa("Cassandra::Client::Policy::Retry::Default");
76 0           $self->{retry_policy}= $config->{retry_policy};
77             }
78 0 0         if (exists($config->{command_queue})) {
79             die "command_queue must be a Cassandra::Client::Policy::Queue::Default"
80 0 0         unless $config->{command_queue}->isa("Cassandra::Client::Policy::Queue::Default");
81 0           $self->{command_queue}= $config->{command_queue};
82             }
83 0 0         if (exists($config->{load_balancing_policy})) {
84             die "load_balancing_policy must be a Cassandra::Client::Policy::LoadBalancing::Default"
85 0 0         unless $config->{load_balancing_policy}->isa("Cassandra::Client::Policy::LoadBalancing::Default");
86 0           $self->{load_balancing_policy}= $config->{load_balancing_policy};
87             }
88              
89 0           $self->{username}= $config->{username};
90 0           $self->{password}= $config->{password};
91              
92 0           return $self;
93             }
94              
95             1;
96              
97             __END__