blib/lib/Cassandra/Client/Config.pm

filter: Statementstmt 32.6% 17 / 52 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 22.2% 22 / 99 CC 24 SCAR 62.1
CC
24
Cov
19%
new
600.0
BEGIN
1.0
BEGIN
1.0
CRAP 496.7
↑ Summary blib/lib/Cassandra/Client/Connection.pm »
1 package Cassandra::Client::Config;
2 13 our $AUTHORITY = 'cpan:TVDW';
3 13 $Cassandra::Client::Config::VERSION = '0.21';
4 13 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use Ref::Util qw/is_plain_arrayref is_plain_coderef is_blessed_ref/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Cassandra::Client::Policy::Auth::Password;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub new {
Subroutine new: not called CC=24 SCAR=64.0
Pod undocumented
12 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 default_idempotency => 0,
23 max_page_size => 5000,
24 max_connections => 2,
25 timer_granularity => 0.1,
26 request_timeout => 11,
27 warmup => 0,
28 max_concurrent_queries => 1000,
29 tls => 0,
30 protocol_version => 4,
31  
32 throttler => undef,
33 command_queue => undef,
34 retry_policy => undef,
35 load_balancing_policy => undef,
36 authentication => undef,
37  
38 stats_hook => undef,
39 }, $class;
40  
41 0 ▶ if (my $cp= $config->{contact_points}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cp = $config->{'contact_points'}) { } 0 0 0
42 0 ▶ if (is_plain_arrayref($cp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_plain_arrayref($cp)) { } 0 0 0
43 0 @{$self->{contact_points}=[]}= @$cp;
44 0 } else { die "contact_points must be an arrayref"; }
45 0 } else { die "contact_points not specified"; }
46  
47 # Booleans
48 0 for (qw/anyevent warmup tls default_idempotency/) {
49 0 ▶ if (exists($config->{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{$_}) 0 0 0
50 0 $self->{$_}= !!$config->{$_};
51 }
52 }
53  
54 # Numbers, ignore undef
55 0 for (qw/port timer_granularity request_timeout max_connections max_concurrent_queries/) {
56 0 ▶ if (defined($config->{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{$_}) 0 0 0
57 0 $self->{$_}= 0+ $config->{$_};
58 }
59 }
60 # Numbers, undef actually means undef
61 0 for (qw/max_page_size/) {
62 0 ▶ if (exists($config->{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{$_}) 0 0 0
63 0 ▶ $self->{$_}= defined($config->{$_}) ? (0+ $config->{$_}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $config->{$_} ? : 0 0 0
64 }
65 }
66  
67 # Strings
68 0 for (qw/cql_version keyspace compression default_consistency/) {
69 0 ▶ if (exists($config->{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{$_}) 0 0 0
70 0 ▶ $self->{$_}= defined($config->{$_}) ? "$config->{$_}" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $config->{$_} ? : 0 0 0
71 }
72 }
73  
74 # Coderefs
75 0 for (qw/stats_hook/) {
76 0 ▶ if (defined($config->{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{$_}) 0 0 0
77 0 ▶ die "$_ must be a CODE reference" unless is_plain_coderef($config->{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless is_plain_coderef($config->{$_}) 0 0 0
78 0 $self->{$_}= $config->{$_};
79 }
80 }
81  
82 # Policies
83 0 for (qw/throttler retry_policy command_queue load_balancing_policy authentication/) {
84 0 ▶ if (exists($config->{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{$_}) 0 0 0
85 die "$_ must be a blessed reference implementing the correct API"
86 0 ▶ unless is_blessed_ref($config->{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless is_blessed_ref($config->{$_}) 0 0 0
87 0 $self->{$_}= $config->{$_};
88 }
89 }
90  
91 0 ▶ if (exists($config->{username}) || exists($config->{password})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{"username"} or exists $config->{"password"}) 0 0 0
Condition0%0/3
exists $config->{"username"} or exists $config->{"password"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $config->{"username"} or exists $config->{"password"}
exists $config->{"username"} exists $config->{"password"}
Truth table0%0/3
A or B
A= exists $config->{"username"}B= exists $config->{"password"}
ABresult
1X1
011
000
92 $self->{authentication}= Cassandra::Client::Policy::Auth::Password->new(
93 username => $config->{username},
94 password => $config->{password},
95 0 );
96 }
97  
98 0 ▶ if (exists $config->{protocol_version}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{"protocol_version"}) 0 0 0
99 0 ▶ if ($config->{protocol_version} == 3 || $config->{protocol_version} == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{'protocol_version'} == 3 or $config->{'protocol_version'} == 4) { } 0 0 0
Condition0%0/3
$config->{"protocol_version"} == 3 or $config->{"protocol_version"} == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{"protocol_version"} == 3 or $config->{"protocol_version"} == 4
$config->{"protocol_version"} == 3 $config->{"protocol_version"} == 4
Truth table0%0/3
A or B
A= $config->{"protocol_version"} == 3B= $config->{"protocol_version"} == 4
ABresult
1X1
011
000
100 0 $self->{protocol_version}= 0+ $config->{protocol_version};
101 } else {
102 0 die "Invalid protocol_version: must be one of [3, 4]";
103 }
104 }
105  
106 0 return $self;
107 }
108  
109 13 1;
110  
111 __END__
↑ Summary blib/lib/Cassandra/Client/Connection.pm »