ClickHouse/Native.pm

filter: Statementstmt 97.8% 137 / 140 Branchbran 90.0% 81 / 90 Conditioncond 66.6% 34 / 51 MC/DCmcdc 46.4% 13 / 28 Subroutinesub 100% 24 / 24 Podpod 75.0% 3 / 4 totaltotal 86.6% 292 / 337 CC 66 SCAR 20.4
CC
66
Cov
90%
_resolve_source
13.1
_source_label
13.1
columns_for
11.2
CRAP 7.7
« ClickHouse/Storage.pm ↑ Summary ClickHouse/Diff/Table.pm »
1 package DBIO::ClickHouse::Native;
2 # ABSTRACT: Turn DBIO schemas and rows into ClickHouse::Encoder input
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.900007';
8  
9 1 ▶use base 'DBIO::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use DBIO::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use DBIO::ClickHouse::DDL ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 15 ▶sub columns_for {
Subroutine columns_for: called CC=11 SCAR=24.2
Pod documented
17 15 my ($class, $thing, %opts) = @_;
18  
19 15 my @unknown = grep { $_ ne 'columns' } sort keys %opts;
20 $class->throw_exception(
21 'columns_for(): unknown option' . (@unknown > 1 ? 's ' : ' ')
22 15 ▶ . join(', ', map { "'$_'" } @unknown)
Branch: 2 branches
BranchTrueFalseTotal
if @unknown 1 14 15
@unknown > 1 ? : 0 1 1
23 ) if @unknown;
24  
25 14 my $source = $class->_resolve_source($thing);
26  
27 10 my @names;
28 10 ▶ if (defined $opts{columns}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{'columns'}) { } 6 4 10
29 $class->throw_exception(
30 "columns_for(): 'columns' must be an arrayref of column names")
31 6 ▶ unless ref $opts{columns} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts{"columns"} eq "ARRAY" 1 5 6
32 $class->throw_exception(
33 "columns_for(): 'columns' must not be empty")
34 5 ▶ unless @{ $opts{columns} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$opts{"columns"};} 1 4 5
35 4 @names = @{ $opts{columns} };
36 }
37 else {
38 4 @names = $source->columns;
39 4 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless @names 0 4 4
40 'columns_for(): ' . _source_label($source) . ' has no columns')
41 unless @names;
42 }
43  
44 8 my @columns;
45 8 for my $name (@names) {
46 34 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name and $source->has_column($name) 1 33 34
Condition50%3/6
defined $name and length $name and $source->has_column($name)
!ll&&!rl&&r
0133
defined $name and length $name
!ll&&!rl&&r
0034
MC/DC33%1/3
defined $name and length $name and $source->has_column($name)
defined $name length $name $source->has_column($name)
Truth table50%2/4
A and B and C
A= defined $nameB= length $nameC= $source->has_column($name)
ABCresult
0XX0
10X0
1100
1111
47 'columns_for(): ' . _source_label($source) . " has no column '$name'")
48 unless defined $name && length $name && $source->has_column($name);
49  
50 33 push @columns,
51 [$name, DBIO::ClickHouse::DDL->column_type($source->column_info($name))];
52 }
53  
54 7 return \@columns;
55 }
56  
57  
58 19 ▶sub rows_from {
Subroutine rows_from: called CC=2 SCAR=6.9
Pod documented
59 19 my ($class, $rows, $columns) = @_;
60  
61 19 my $next = $class->row_iterator($rows, $columns);
62  
63 18 my @out;
64 18 ▶ while (defined(my $row = $next->())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $row = &$next())) 12 9 21
65 12 push @out, $row;
66 }
67  
68 9 return \@out;
69 }
70  
71  
72 23 ▶sub row_iterator {
Subroutine row_iterator: called CC=4 SCAR=13.9
Pod documented
73 23 my ($class, $rows, $columns) = @_;
74  
75 23 $class->_assert_columns($columns);
76  
77 21 ▶ if (Scalar::Util::blessed($rows) && $rows->isa('DBIO::ResultSet')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($rows) and $rows->isa("DBIO::ResultSet")) 2 19 21
Condition100%3/3
builtin::blessed($rows) and $rows->isa("DBIO::ResultSet")
!ll&&!rl&&r
1812
MC/DC100%2/2
builtin::blessed($rows) and $rows->isa("DBIO::ResultSet")
builtin::blessed($rows) $rows->isa("DBIO::ResultSet")
Truth table100%3/3
A and B
A= builtin::blessed($rows)B= $rows->isa("DBIO::ResultSet")
ABresult
0X0
100
111
78 6 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
79 6 my $row = $rows->next;
80 6 ▶ return undef unless defined $row;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $row 2 4 6
81 4 return $class->_row_values($row, $columns);
82 2 };
83 }
84  
85 19 ▶ if (ref $rows eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rows eq "ARRAY") 18 1 19
86 18 my $i = 0;
87 28 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
88 28 ▶ return undef if $i > $#{$rows};
Branch: 1 branch
BranchTrueFalseTotal
if $i > $#{$rows;} 8 20 28
89 20 return $class->_row_values($rows->[$i++], $columns);
90 18 };
91 }
92  
93 $class->throw_exception(
94 1 'row_iterator() needs a DBIO::ResultSet or an arrayref of rows, got '
95 . _describe($rows));
96 }
97  
98 # --- column list ------------------------------------------------------------
99  
100 23 ▶sub _assert_columns {
Subroutine _assert_columns: called CC=10 SCAR=24.1
101 23 my ($class, $columns) = @_;
102  
103 23 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $columns eq "ARRAY" and @$columns 1 22 23
Condition66%2/3
ref $columns eq "ARRAY" and @$columns
!ll&&!rl&&r
1022
MC/DC50%1/2
ref $columns eq "ARRAY" and @$columns
ref $columns eq "ARRAY" @$columns
Truth table66%2/3
A and B
A= ref $columns eq "ARRAY"B= @$columns
ABresult
0X0
100
111
104 'The column list must be a non-empty arrayref of [ name, type ] pairs, '
105 . 'as returned by columns_for(), got ' . _describe($columns))
106 unless ref $columns eq 'ARRAY' && @$columns;
107  
108 22 for my $pair (@$columns) {
109 37 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pair eq "ARRAY" and @$pair == 2 and defined $pair->[0] and length $pair->[0] and defined $pair->[1] and length $pair->[1] 1 36 37
Condition66%10/15
ref $pair eq "ARRAY" and @$pair == 2 and defined $pair->[0] and length $pair->[0] and defined $pair->[1] and length $pair->[1]
!ll&&!rl&&r
1036
ref $pair eq "ARRAY" and @$pair == 2 and defined $pair->[0] and length $pair->[0] and defined $pair->[1]
!ll&&!rl&&r
1036
ref $pair eq "ARRAY" and @$pair == 2 and defined $pair->[0] and length $pair->[0]
!ll&&!rl&&r
1036
ref $pair eq "ARRAY" and @$pair == 2 and defined $pair->[0]
!ll&&!rl&&r
1036
ref $pair eq "ARRAY" and @$pair == 2
!ll&&!rl&&r
0136
MC/DC16%1/6
ref $pair eq "ARRAY" and @$pair == 2 and defined $pair->[0] and length $pair->[0] and defined $pair->[1] and length $pair->[1]
ref $pair eq "ARRAY" @$pair == 2 defined $pair->[0] length $pair->[0] defined $pair->[1] length $pair->[1]
Truth table28%2/7
A and B and C and D and E and F
A= ref $pair eq "ARRAY"B= @$pair == 2C= defined $pair->[0]D= length $pair->[0]E= defined $pair->[1]F= length $pair->[1]
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
110 'The column list must hold [ name, type ] pairs, got ' . _describe($pair))
111 unless ref $pair eq 'ARRAY' && @$pair == 2
112 && defined $pair->[0] && length $pair->[0]
113 && defined $pair->[1] && length $pair->[1];
114 }
115  
116 21 return;
117 }
118  
119 # --- row conversion ---------------------------------------------------------
120  
121 24 ▶sub _row_values {
Subroutine _row_values: called CC=2 SCAR=6.9
122 24 my ($class, $row, $columns) = @_;
123  
124 24 my @values;
125 24 for my $pair (@$columns) {
126 38 my ($name, $type) = @$pair;
127 # Scalar context on both calls: an undef value must stay one element of
128 # the row, not collapse out of the list.
129 38 my $raw = $class->_raw_value($row, $name);
130 34 my $value = $class->_checked_value($name, $type, $raw);
131 28 push @values, $value;
132 }
133  
134 14 return \@values;
135 }
136  
137 # The deflated value of one column. For a result object that means
138 # get_column(), which is DBIO's deflation path -- a value that was set through
139 # an InflateColumn accessor is deflated here and nowhere else. A plain hashref
140 # (DBIO::ResultClass::HashRefInflator, or data the caller assembled) is taken
141 # as-is; there is no result object to deflate through.
142 38 ▶sub _raw_value {
Subroutine _raw_value: called CC=7 SCAR=19.5
143 38 my ($class, $row, $name) = @_;
144  
145 38 ▶ if (Scalar::Util::blessed($row)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($row)) 16 22 38
146 16 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless $row->can("get_column") 0 16 16
147 'Each row must be a DBIO result object or a hashref; a ' . ref($row)
148 . ' object has no get_column()')
149 unless $row->can('get_column');
150  
151 # get_column() on a column that was never selected returns undef, which
152 # would export as a NULL the row never had. Refuse instead.
153 16 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
if $row->can("has_column_loaded") and not $row->has_column_loaded($name) 1 15 16
Condition66%2/3
$row->can("has_column_loaded") and not $row->has_column_loaded($name)
!ll&&!rl&&r
0151
MC/DC50%1/2
$row->can("has_column_loaded") and not $row->has_column_loaded($name)
$row->can("has_column_loaded") not $row->has_column_loaded($name)
Truth table66%2/3
A and not(B)
A= $row->can("has_column_loaded")B= not $row->has_column_loaded($name)
ABresult
0X0
100
111
154 "Column '$name' was not fetched into this " . ref($row) . ' -- exporting '
155 . 'it would write a value the row does not have. Select the column, or '
156 . 'leave it out of the column list')
157 if $row->can('has_column_loaded') && !$row->has_column_loaded($name);
158  
159 15 return $row->get_column($name);
160 }
161  
162 22 ▶ if (ref $row eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $row eq "HASH") 20 2 22
163 $class->throw_exception("Row hashref has no key '$name'")
164 20 ▶ unless exists $row->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $row->{$name} 1 19 20
165 19 return $row->{$name};
166 }
167  
168 $class->throw_exception(
169 2 'Each row must be a DBIO result object or a hashref, got '
170 . _describe($row));
171 }
172  
173 34 ▶sub _checked_value {
Subroutine _checked_value: called CC=9 SCAR=22.0
174 34 my ($class, $name, $type, $value) = @_;
175  
176 34 ▶ if (!defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 5 29 34
177 5 ▶ return undef if _accepts_undef($type);
Branch: 1 branch
BranchTrueFalseTotal
if _accepts_undef($type) 4 1 5
178  
179 1 $class->throw_exception(
180 "Column '$name' is undef but its ClickHouse type is '$type', which "
181 . 'cannot hold a NULL -- the encoder would silently write the type\'s '
182 . 'zero value instead. Declare the column is_nullable so the type '
183 . 'becomes Nullable(...), or keep the row out of the export');
184 }
185  
186 29 ▶ if (my $ref = ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = ref $value) 6 23 29
187 6 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) 1 5 6
188 "Column '$name' holds a $ref object, which reached here undeflated. "
189 . 'ClickHouse::Encoder does not dispatch through ->epoch; it takes the '
190 . "value's string or numeric conversion, and for '$type' that is "
191 . 'silently wrong (a DateTime outside UTC loses its offset, a numeric '
192 . "column gets the leading digits of the stringification). Give the "
193 . 'column its inflator/deflator (e.g. '
194 . "load_components('InflateColumn::DateTime')) so that get_column() "
195 . 'hands back the stored value')
196 if Scalar::Util::blessed($value);
197  
198 5 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless $ref eq "ARRAY" or $ref eq "HASH" 1 4 5
Condition100%3/3
$ref eq "ARRAY" or $ref eq "HASH"
l!l&&r!l&&!r
311
MC/DC100%2/2
$ref eq "ARRAY" or $ref eq "HASH"
$ref eq "ARRAY" $ref eq "HASH"
Truth table100%3/3
A or B
A= $ref eq "ARRAY"B= $ref eq "HASH"
ABresult
1X1
011
000
199 "Column '$name' holds a $ref reference, which no ClickHouse type accepts")
200 unless $ref eq 'ARRAY' || $ref eq 'HASH';
201  
202 4 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless _accepts_reference($type) 1 3 4
203 "Column '$name' holds a $ref reference, but its ClickHouse type '$type' "
204 . 'takes a plain scalar')
205 unless _accepts_reference($type);
206  
207 3 return $value;
208 }
209  
210 $class->throw_exception(
211 23 ▶ "Column '$name' has the composite type '$type', which ClickHouse::Encoder "
Branch: 1 branch
BranchTrueFalseTotal
if _requires_reference($type) 2 21 23
212 . 'takes as a Perl reference, but the value is the plain scalar '
213 . _abbreviate($value) . '. Composite columns do not survive the MySQL wire '
214 . 'protocol -- ClickHouse hands them back as their text rendering, not as '
215 . 'a Perl structure -- so they can only be exported from rows you built '
216 . 'yourself. See DBIO::ClickHouse::Native, "Composite types are a one-way '
217 . 'street"')
218 if _requires_reference($type);
219  
220 21 return $value;
221 }
222  
223 # --- type predicates --------------------------------------------------------
224 #
225 # These read the rendered ClickHouse type string, which is the only thing the
226 # encoder is configured with. They deliberately do NOT re-derive anything from
227 # column_info: DBIO::ClickHouse::DDL::column_type is the one type authority,
228 # and a caller may legitimately pass a column list that came from
229 # ClickHouse::Encoder->for_table instead.
230  
231 # Types whose encoder input is a Perl reference -- an arrayref or a hashref --
232 # rather than a scalar. Object('json') is the pre-24.8 spelling of JSON; the
233 # geo names are ClickHouse's own aliases over Tuple/Array.
234 1 my $COMPOSITE_TYPE = qr/\A(?:
235 Array | Map | Tuple | Nested | Variant | JSON | Object
236 | Point | Ring | LineString | MultiLineString | Polygon | MultiPolygon
237 )\b/x;
238  
239 # Dynamic takes a scalar leaf OR an array of them, so it is in neither the
240 # "must be a reference" nor the "must be a scalar" camp.
241 1 my $ANY_SHAPE_TYPE = qr/\ADynamic\b/;
242  
243 # Nullable is the type wrapper; LowCardinality nests outside it.
244 29 ▶sub _unwrap {
Subroutine _unwrap: called CC=1 SCAR=0.0
245 29 my ($type) = @_;
246 29 $type =~ s/\A\s+//;
247 29 $type =~ s/\ALowCardinality\(\s*//;
248 29 $type =~ s/\ANullable\(\s*//;
249 29 return $type;
250 }
251  
252 5 ▶sub _accepts_undef {
Subroutine _accepts_undef: called CC=3 SCAR=11.0
253 5 my ($type) = @_;
254 5 ▶ return 1 if $type =~ /\A\s*(?:LowCardinality\(\s*)?Nullable\(/;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /\A\s*(?:LowCardinality\(\s*)?Nullable\(/ 3 2 5
255 # A Variant arm and a Dynamic value both carry their own null discriminator.
256 2 ▶ return 1 if _unwrap($type) =~ /\A(?:Variant\b|Dynamic\b)/;
Branch: 1 branch
BranchTrueFalseTotal
if _unwrap($type) =~ /\A(?:Variant\b|Dynamic\b)/ 1 1 2
257 1 return 0;
258 }
259  
260 23 ▶sub _requires_reference {
Subroutine _requires_reference: called CC=2 SCAR=6.9
261 23 my ($type) = @_;
262 23 ▶ return _unwrap($type) =~ $COMPOSITE_TYPE ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
_unwrap($type) =~ /$COMPOSITE_TYPE/x ? : 2 21 23
263 }
264  
265 4 ▶sub _accepts_reference {
Subroutine _accepts_reference: called CC=3 SCAR=11.0
266 4 my ($type) = @_;
267 4 my $inner = _unwrap($type);
268 4 ▶ return ($inner =~ $COMPOSITE_TYPE || $inner =~ $ANY_SHAPE_TYPE) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$inner =~ /$COMPOSITE_TYPE/x || $inner =~ /$ANY_SHAPE_TYPE/ ? : 3 1 4
Condition100%3/3
$inner =~ /$COMPOSITE_TYPE/x or $inner =~ /$ANY_SHAPE_TYPE/
l!l&&r!l&&!r
211
MC/DC100%2/2
$inner =~ /$COMPOSITE_TYPE/x or $inner =~ /$ANY_SHAPE_TYPE/
$inner =~ /$COMPOSITE_TYPE/x $inner =~ /$ANY_SHAPE_TYPE/
Truth table100%3/3
A or B
A= $inner =~ /$COMPOSITE_TYPE/xB= $inner =~ /$ANY_SHAPE_TYPE/
ABresult
1X1
011
000
269 }
270  
271 # --- diagnostics ------------------------------------------------------------
272  
273 1 ▶sub _source_label {
Subroutine _source_label: called CC=5 SCAR=25.7
274 1 my ($source) = @_;
275 1 my $name = $source->source_name;
276 1 ▶ return "source '$name'" if defined $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name and length $name 1 0 1
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
001
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
277 0 $name = $source->result_class;
278 0 ▶ return "result class '$name'" if defined $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name and length $name 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
279 0 return 'the result source';
280 }
281  
282 6 ▶sub _describe {
Subroutine _describe: called CC=4 SCAR=13.9
283 6 my ($thing) = @_;
284 6 ▶ return 'undef' unless defined $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 1 5 6
285 5 ▶ return ref($thing) . ' object' if Scalar::Util::blessed($thing);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($thing) 1 4 5
286 4 ▶ return 'a ' . ref($thing) . ' reference' if ref $thing;
Branch: 1 branch
BranchTrueFalseTotal
if ref $thing 1 3 4
287 3 return 'the plain scalar ' . _abbreviate($thing);
288 }
289  
290 5 ▶sub _abbreviate {
Subroutine _abbreviate: called CC=2 SCAR=7.0
291 5 my ($value) = @_;
292 5 ▶ $value = substr($value, 0, 40) . '...' if length $value > 43;
Branch: 1 branch
BranchTrueFalseTotal
if length $value > 43 0 5 5
293 5 $value =~ s/\s+/ /g;
294 5 return "'$value'";
295 }
296  
297 # --- source resolution ------------------------------------------------------
298  
299 14 ▶sub _resolve_source {
Subroutine _resolve_source: called CC=13 SCAR=25.8
300 14 my ($class, $thing) = @_;
301  
302 14 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing and ref $thing || length $thing 1 13 14
Condition66%4/6
defined $thing and ref $thing || length $thing
!ll&&!rl&&r
1013
ref $thing or length $thing
l!l&&r!l&&!r
1030
MC/DC33%1/3
defined $thing and ref $thing || length $thing
defined $thing ref $thing length $thing
Truth table75%3/4
A and B or C
A= defined $thingB= ref $thingC= length $thing
ABCresult
0XX0
1000
11X1
1011
303 'columns_for() needs a ResultSource, a ResultSet, a result object or a '
304 . 'result class name, got ' . _describe($thing))
305 if !defined $thing || (!ref($thing) && !length $thing);
306  
307 13 ▶ if (Scalar::Util::blessed($thing)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($thing)) 10 3 13
308 10 ▶ return $thing if $thing->isa('DBIO::ResultSource');
Branch: 1 branch
BranchTrueFalseTotal
if $thing->isa("DBIO::ResultSource") 7 3 10
309 3 ▶ return $thing->result_source
Branch: 1 branch
BranchTrueFalseTotal
if $thing->isa("DBIO::ResultSet") or $thing->isa("DBIO::Row") 2 1 3
Condition100%3/3
$thing->isa("DBIO::ResultSet") or $thing->isa("DBIO::Row")
l!l&&r!l&&!r
111
MC/DC100%2/2
$thing->isa("DBIO::ResultSet") or $thing->isa("DBIO::Row")
$thing->isa("DBIO::ResultSet") $thing->isa("DBIO::Row")
Truth table100%3/3
A or B
A= $thing->isa("DBIO::ResultSet")B= $thing->isa("DBIO::Row")
ABresult
1X1
011
000
310 if $thing->isa('DBIO::ResultSet') || $thing->isa('DBIO::Row');
311  
312 1 $class->throw_exception(
313 'columns_for(): cannot get a ResultSource out of a ' . ref($thing)
314 . ' object');
315 }
316  
317 $class->throw_exception(
318 3 ▶ 'columns_for() needs a ResultSource, a ResultSet, a result object or a '
Branch: 1 branch
BranchTrueFalseTotal
if ref $thing 0 3 3
319 . 'result class name, got ' . _describe($thing))
320 if ref $thing;
321  
322 # A result class name. Load it, so that a name coming from configuration
323 # works, then insist on the accessor rather than guessing at the class.
324 3 ▶ if (!$thing->can('result_source_instance')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($thing->can("result_source_instance")) 2 1 3
325 2 ▶ eval { $class->ensure_class_loaded($thing); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $class->ensure_class_loaded($thing); 1 } } or $class->throw_exception("columns_for(): cannot load '${thing}': $@") 1 1 2
326 or $class->throw_exception("columns_for(): cannot load '$thing': $@");
327 }
328  
329 $class->throw_exception(
330 2 ▶ "columns_for(): '$thing' is not a DBIO result class -- it has no "
Branch: 1 branch
BranchTrueFalseTotal
unless $thing->can("result_source_instance") 1 1 2
331 . 'result_source_instance')
332 unless $thing->can('result_source_instance');
333  
334 1 my $source = $thing->result_source_instance;
335 1 ▶ $class->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless $source 0 1 1
336 "columns_for(): result class '$thing' has no result source. Was table() "
337 . 'called on it?')
338 unless $source;
339  
340 1 return $source;
341 }
342  
343 # DBIO::Base deliberately has no throw_exception -- a component must not
344 # install one, which would shadow the result class's. This class is never
345 # mixed into anything, so it carries its own, the same way
346 # DBIO::SQLMaker::ClassicExtensions does.
347 22 ▶sub throw_exception { DBIO::Exception->throw($_[1]) }
Subroutine throw_exception: called CC=1 SCAR=0.0
Pod undocumented
348  
349  
350 1 1;
351  
352 __END__
« ClickHouse/Storage.pm ↑ Summary ClickHouse/Diff/Table.pm »