ClickHouse/Result.pm

filter: Statementstmt 100% 44 / 44 Branchbran 96.4% 27 / 28 Conditioncond 83.3% 15 / 18 MC/DCmcdc 75.0% 9 / 12 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 93.6% 103 / 110 CC 24 SCAR 27.3
CC
24
Cov
96%
_clickhouse_validate_table_options
21.1
clickhouse_table
3.0
_clickhouse_throw
2.0
CRAP 15.4
« ClickHouse/DDL.pm ↑ Summary ClickHouse/Diff/Column.pm »
1 package DBIO::ClickHouse::Result;
2 # ABSTRACT: ClickHouse-specific Result component for DBIO
3  
4 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 27 our $VERSION = '0.900007';
8  
9 27 ▶use base 'DBIO::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 27 ▶use DBIO::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 27 __PACKAGE__->mk_classdata('_clickhouse_table_options');
14  
15  
16 27 my %VALID_OPTION = map { $_ => 1 } qw(
17 engine order_by primary_key partition_by settings
18 );
19  
20 72 ▶sub clickhouse_table {
Subroutine clickhouse_table: called CC=3 SCAR=11.0
Pod documented
21 72 my ($class, $options) = @_;
22  
23 72 ▶ $class->_clickhouse_table_options(_clickhouse_validate_table_options($class, $options))
Branch: 1 branch
BranchTrueFalseTotal
if defined $options 61 11 72
24 if defined $options;
25  
26 62 my $stored = $class->_clickhouse_table_options;
27 62 ▶ return $stored ? { %$stored } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$stored ? : 61 1 62
28 }
29  
30 61 ▶sub _clickhouse_validate_table_options {
Subroutine _clickhouse_validate_table_options: called CC=21 SCAR=30.5
31 61 my ($class, $options) = @_;
32  
33 61 ▶ _clickhouse_throw($class, 'clickhouse_table() expects a hashref of table options')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $options eq "HASH" 2 59 61
34 unless ref $options eq 'HASH';
35  
36 59 my %clean;
37 59 for my $key (sort keys %$options) {
38 _clickhouse_throw($class, "clickhouse_table(): unknown option '$key'")
39 162 ▶ unless $VALID_OPTION{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $VALID_OPTION{$key} 1 161 162
40  
41 161 my $value = $options->{$key};
42 161 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 161 161
43  
44 161 ▶ if ($key eq 'engine' || $key eq 'partition_by') {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'engine' or $key eq 'partition_by') { } 79 82 161
elsif ($key eq 'order_by' or $key eq 'primary_key') { } 78 4 82
Condition100%3/3
$key eq "engine" or $key eq "partition_by"
l!l&&r!l&&!r
522782
MC/DC100%2/2
$key eq "engine" or $key eq "partition_by"
$key eq "engine" $key eq "partition_by"
Truth table100%3/3
A or B
A= $key eq "engine"B= $key eq "partition_by"
ABresult
1X1
011
000
45 79 ▶ _clickhouse_throw($class, "clickhouse_table(): '$key' must be a non-empty string")
Branch: 1 branch
BranchTrueFalseTotal
if ref $value or not length $value 3 76 79
Condition100%3/3
ref $value or not length $value
l!l&&r!l&&!r
2176
MC/DC100%2/2
ref $value or not length $value
ref $value not length $value
Truth table100%3/3
A or not(B)
A= ref $valueB= not length $value
ABresult
1X1
011
000
46 if ref $value || !length $value;
47 76 $clean{$key} = $value;
48 }
49 ▶ elsif ($key eq 'order_by' || $key eq 'primary_key') {
Condition100%3/3
$key eq "order_by" or $key eq "primary_key"
l!l&&r!l&&!r
53254
MC/DC100%2/2
$key eq "order_by" or $key eq "primary_key"
$key eq "order_by" $key eq "primary_key"
Truth table100%3/3
A or B
A= $key eq "order_by"B= $key eq "primary_key"
ABresult
1X1
011
000
50 78 ▶ my @entries = ref $value eq 'ARRAY' ? @$value : ($value);
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 77 1 78
51 78 for my $entry (@entries) {
52 103 ▶ _clickhouse_throw($class,
Branch: 1 branch
BranchTrueFalseTotal
if ref $entry and ref $entry ne "SCALAR" 1 102 103
Condition66%2/3
ref $entry and ref $entry ne "SCALAR"
!ll&&!rl&&r
10201
MC/DC50%1/2
ref $entry and ref $entry ne "SCALAR"
ref $entry ref $entry ne "SCALAR"
Truth table66%2/3
A and B
A= ref $entryB= ref $entry ne "SCALAR"
ABresult
0X0
100
111
53 "clickhouse_table(): '$key' entries must be column names or scalar refs of raw SQL")
54 if ref $entry && ref $entry ne 'SCALAR';
55 102 ▶ _clickhouse_throw($class, "clickhouse_table(): '$key' entries must not be empty")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry or length $entry 1 101 102
Condition66%2/3
ref $entry or length $entry
l!l&&r!l&&!r
01011
MC/DC50%1/2
ref $entry or length $entry
ref $entry length $entry
Truth table66%2/3
A or B
A= ref $entryB= length $entry
ABresult
1X1
011
000
56 if !ref $entry && !length $entry;
57 }
58 76 $clean{$key} = \@entries;
59 }
60 else {
61 4 ▶ _clickhouse_throw($class, "clickhouse_table(): 'settings' must be a hashref")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 1 3 4
62 unless ref $value eq 'HASH';
63 3 for my $name (sort keys %$value) {
64 _clickhouse_throw($class,
65 "clickhouse_table(): setting '$name' must be a scalar or scalar ref")
66 3 ▶ if ref $value->{$name} && ref $value->{$name} ne 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value->{$name} and ref $value->{$name} ne "SCALAR" 1 2 3
Condition66%2/3
ref $value->{$name} and ref $value->{$name} ne "SCALAR"
!ll&&!rl&&r
201
MC/DC50%1/2
ref $value->{$name} and ref $value->{$name} ne "SCALAR"
ref $value->{$name} ref $value->{$name} ne "SCALAR"
Truth table66%2/3
A and B
A= ref $value->{$name}B= ref $value->{$name} ne "SCALAR"
ABresult
0X0
100
111
67 }
68 2 $clean{$key} = { %$value };
69 }
70 }
71  
72 51 return \%clean;
73 }
74  
75 # Route errors through the result class's own throw_exception when the
76 # component is mixed into one (the family rule), and fall back to a plain
77 # DBIO::Exception when it is not -- DBIO::Base has no throw_exception, and a
78 # component must never install one, which would shadow the result class's.
79 10 ▶sub _clickhouse_throw {
Subroutine _clickhouse_throw: called CC=2 SCAR=6.9
80 10 my ($class, $message) = @_;
81 10 ▶ return $class->throw_exception($message) if $class->can('throw_exception');
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("throw_exception") 9 1 10
82 1 DBIO::Exception->throw($message);
83 }
84  
85  
86 27 1;
87  
88 __END__
« ClickHouse/DDL.pm ↑ Summary ClickHouse/Diff/Column.pm »