blib/lib/DBIO/MySQL/NotifyTable.pm

filter: Statementstmt 100% 128 / 128 Branchbran 90.3% 47 / 52 Conditioncond 83.0% 49 / 59 MC/DCmcdc 66.6% 24 / 36 Subroutinesub 100% 24 / 24 Podpod 100% 15 / 15 totaltotal 91.4% 287 / 314 CC 53 SCAR 22.2
CC
53
Cov
94%
polled
17.2
new
17.1
subscribed
5.1
CRAP 9.2
« blib/lib/DBIO/MySQL/Diff/View.pm ↑ Summary blib/lib/DBIO/MySQL/Introspect/Columns.pm »
1 package DBIO::MySQL::NotifyTable;
2 # ABSTRACT: LISTEN/NOTIFY emulated over a notify table for MySQL and MariaDB, without I/O
3  
4 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 30 our $VERSION = '0.900007';
8  
9 30 ▶use base 'Class::Accessor::Grouped';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 30 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 30 ▶use Scalar::Util qw( looks_like_number refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 30 my %DEFAULTS = (
15 table => 'dbio_notify',
16 poll_interval => 1,
17 lookback => 60,
18 retention => 3600,
19 cleanup_limit => 1000,
20 );
21  
22 # The widest channel the channel column holds, in characters.
23 30 my $MAX_CHANNEL = 255;
24  
25 # The widest payload the TEXT payload column holds, in bytes.
26 30 my $MAX_PAYLOAD = 65535;
27  
28 # A listener cleans up at most this often, in seconds of polling -- more often
29 # only while each run fills its whole batch.
30 30 my $CLEANUP_PERIOD = 60;
31  
32 # The server-side format of a cutoff: fixed width, so string order is time
33 # order.
34 30 my $CUTOFF_FORMAT = '%Y-%m-%d %H:%i:%s.%f';
35  
36 30 __PACKAGE__->mk_group_ro_accessors(simple => sort keys %DEFAULTS);
37  
38  
39  
40 406 ▶sub new {
Subroutine new: called CC=17 SCAR=28.4
Pod documented
41 406 my ($class, %args) = @_;
42  
43 406 my @unknown = grep { !exists $DEFAULTS{$_} } sort keys %args;
44 406 ▶ croak "unknown notify table setting(s): @unknown" if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 405 406
45  
46 405 ▶ my %cfg = map { $_ => $args{$_} // $DEFAULTS{$_} } keys %DEFAULTS;
Condition66%2/3
$args{$_} // $DEFAULTS{$_}
l!l&&r!l&&!r
15314940
MC/DC0%0/2
$args{$_} // $DEFAULTS{$_}
$args{$_} $DEFAULTS{$_}
Truth table66%2/3
A // B
A= $args{$_}B= $DEFAULTS{$_}
ABresult
1X1
011
000
47  
48 croak sprintf(
49 "notify table name '%s' is not a plain identifier -- it must match "
50 . '[A-Za-z_][A-Za-z0-9_]* and be at most 64 characters long',
51 ref $cfg{table} ? 'a reference' : $cfg{table},
52 ) unless !ref $cfg{table}
53 && $cfg{table} =~ /\A[A-Za-z_][A-Za-z0-9_]*\z/
54 405 ▶ && length $cfg{table} <= 64;
Branch: 2 branches
BranchTrueFalseTotal
unless not ref $cfg{"table"} and $cfg{"table"} =~ /\A[A-Za-z_][A-Za-z0-9_]*\z/ and length $cfg{"table"} <= 64 10 395 405
ref $cfg{'table'} ? : 1 9 10
Condition100%6/6
not ref $cfg{"table"} and $cfg{"table"} =~ /\A[A-Za-z_][A-Za-z0-9_]*\z/ and length $cfg{"table"} <= 64
!ll&&!rl&&r
91395
not ref $cfg{"table"} and $cfg{"table"} =~ /\A[A-Za-z_][A-Za-z0-9_]*\z/
!ll&&!rl&&r
18396
MC/DC100%3/3
not ref $cfg{"table"} and $cfg{"table"} =~ /\A[A-Za-z_][A-Za-z0-9_]*\z/ and length $cfg{"table"} <= 64
not ref $cfg{"table"} $cfg{"table"} =~ /\A[A-Za-z_][A-Za-z0-9_]*\z/ length $cfg{"table"} <= 64
Truth table100%4/4
not(A) and B and C
A= not ref $cfg{"table"}B= $cfg{"table"} =~ /\A[A-Za-z_][A-Za-z0-9_]*\z/C= length $cfg{"table"} <= 64
ABCresult
0XX0
10X0
1100
1111
55  
56 395 for my $key (qw( poll_interval lookback )) {
57 croak "notify $key must be a positive number of seconds, got '$cfg{$key}'"
58 789 ▶ unless looks_like_number($cfg{$key}) && $cfg{$key} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($cfg{$key}) and $cfg{$key} > 0 3 786 789
Condition100%3/3
&looks_like_number($cfg{$key}) and $cfg{$key} > 0
!ll&&!rl&&r
12786
MC/DC100%2/2
&looks_like_number($cfg{$key}) and $cfg{$key} > 0
&looks_like_number($cfg{$key}) $cfg{$key} > 0
Truth table100%3/3
A and B
A= &looks_like_number($cfg{$key})B= $cfg{$key} > 0
ABresult
0X0
100
111
59 }
60 croak "notify lookback must be at least one microsecond, got '$cfg{lookback}'"
61 392 ▶ if _micro($cfg{lookback}) < 1;
Branch: 1 branch
BranchTrueFalseTotal
if _micro($cfg{"lookback"}) < 1 0 392 392
62  
63 croak "notify retention must be 0 (no cleanup) or a positive number of seconds, "
64 . "got '$cfg{retention}'"
65 392 ▶ unless looks_like_number($cfg{retention}) && $cfg{retention} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($cfg{"retention"}) and $cfg{"retention"} >= 0 1 391 392
Condition66%2/3
&looks_like_number($cfg{"retention"}) and $cfg{"retention"} >= 0
!ll&&!rl&&r
01391
MC/DC50%1/2
&looks_like_number($cfg{"retention"}) and $cfg{"retention"} >= 0
&looks_like_number($cfg{"retention"}) $cfg{"retention"} >= 0
Truth table66%2/3
A and B
A= &looks_like_number($cfg{"retention"})B= $cfg{"retention"} >= 0
ABresult
0X0
100
111
66 croak sprintf(
67 'notify retention (%s s) must be greater than lookback plus poll interval '
68 . '(%s s): a notification that commits late must still be there when the '
69 . 'next poll looks for it',
70 $cfg{retention}, $cfg{lookback} + $cfg{poll_interval},
71 391 ▶ ) if $cfg{retention} > 0 && $cfg{retention} <= $cfg{lookback} + $cfg{poll_interval};
Branch: 1 branch
BranchTrueFalseTotal
if $cfg{"retention"} > 0 and $cfg{"retention"} <= $cfg{"lookback"} + $cfg{"poll_interval"} 1 390 391
Condition100%3/3
$cfg{"retention"} > 0 and $cfg{"retention"} <= $cfg{"lookback"} + $cfg{"poll_interval"}
!ll&&!rl&&r
23881
MC/DC100%2/2
$cfg{"retention"} > 0 and $cfg{"retention"} <= $cfg{"lookback"} + $cfg{"poll_interval"}
$cfg{"retention"} > 0 $cfg{"retention"} <= $cfg{"lookback"} + $cfg{"poll_interval"}
Truth table100%3/3
A and B
A= $cfg{"retention"} > 0B= $cfg{"retention"} <= $cfg{"lookback"} + $cfg{"poll_interval"}
ABresult
0X0
100
111
72  
73 croak "notify cleanup_limit must be a positive integer, got '$cfg{cleanup_limit}'"
74 390 ▶ unless defined $cfg{cleanup_limit} && $cfg{cleanup_limit} =~ /\A[1-9][0-9]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cfg{"cleanup_limit"} and $cfg{"cleanup_limit"} =~ /\A[1-9][0-9]*\z/ 1 389 390
Condition66%2/3
defined $cfg{"cleanup_limit"} and $cfg{"cleanup_limit"} =~ /\A[1-9][0-9]*\z/
!ll&&!rl&&r
01389
MC/DC50%1/2
defined $cfg{"cleanup_limit"} and $cfg{"cleanup_limit"} =~ /\A[1-9][0-9]*\z/
defined $cfg{"cleanup_limit"} $cfg{"cleanup_limit"} =~ /\A[1-9][0-9]*\z/
Truth table66%2/3
A and B
A= defined $cfg{"cleanup_limit"}B= $cfg{"cleanup_limit"} =~ /\A[1-9][0-9]*\z/
ABresult
0X0
100
111
75  
76 389 return bless {
77 %cfg,
78 channels => {}, # channel => { mark, cutoff, seen }
79 cleanup_in => 1, # polls until the next cleanup: due after the first
80 }, $class;
81 }
82  
83  
84 28 ▶sub defaults { return %DEFAULTS }
Subroutine defaults: called CC=1 SCAR=0.0
Pod documented
85  
86  
87 280 ▶sub quoted_table { return '`' . $_[0]->{table} . '`' }
Subroutine quoted_table: called CC=1 SCAR=0.0
Pod documented
88  
89  
90 99 ▶sub check_channel {
Subroutine check_channel: called CC=5 SCAR=16.1
Pod documented
91 99 my ($self, $channel) = @_;
92 99 ▶ croak 'a notify channel name must be a non-empty string'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $channel and not ref $channel and length $channel 3 96 99
Condition100%6/6
defined $channel and not ref $channel and length $channel
!ll&&!rl&&r
2196
defined $channel and not ref $channel
!ll&&!rl&&r
1197
MC/DC100%3/3
defined $channel and not ref $channel and length $channel
defined $channel not ref $channel length $channel
Truth table100%4/4
A and not(B) and C
A= defined $channelB= not ref $channelC= length $channel
ABCresult
0XX0
10X0
1100
1111
93 unless defined $channel && !ref $channel && length $channel;
94 96 ▶ croak sprintf(
Branch: 1 branch
BranchTrueFalseTotal
if length $channel > $MAX_CHANNEL 2 94 96
95 "notify channel name '%s...' is %d characters long; the notify table holds "
96 . "at most $MAX_CHANNEL -- refused rather than truncated",
97 substr($channel, 0, 20), length $channel,
98 ) if length $channel > $MAX_CHANNEL;
99 94 return $channel;
100 }
101  
102  
103 5 ▶sub create_table_sql {
Subroutine create_table_sql: called CC=1 SCAR=0.0
Pod documented
104 5 my ($self) = @_;
105 5 my $t = $self->quoted_table;
106 5 return <<"SQL";
107 CREATE TABLE IF NOT EXISTS $t (
108 `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
109 `channel` VARCHAR($MAX_CHANNEL) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
110 `payload` TEXT CHARACTER SET utf8mb4 NOT NULL,
111 `pid` BIGINT UNSIGNED NOT NULL,
112 `created_at` DATETIME(6) NOT NULL,
113 PRIMARY KEY (`id`),
114 KEY `channel_id` (`channel`, `id`),
115 KEY `channel_created_at` (`channel`, `created_at`),
116 KEY `created_at` (`created_at`)
117 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
118 SQL
119 }
120  
121  
122 1 ▶sub drop_table_sql { return 'DROP TABLE IF EXISTS ' . $_[0]->quoted_table }
Subroutine drop_table_sql: called CC=1 SCAR=0.0
Pod documented
123  
124  
125 14 ▶sub notify_sql {
Subroutine notify_sql: called CC=3 SCAR=11.0
Pod documented
126 14 my ($self, $channel, $payload) = @_;
127 14 $self->check_channel($channel);
128 10 ▶ $payload = defined $payload ? "$payload" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $payload ? : 8 2 10
129  
130 10 my $bytes = $payload;
131 10 utf8::upgrade($bytes);
132 10 utf8::encode($bytes);
133 10 ▶ croak sprintf(
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes > $MAX_PAYLOAD 2 8 10
134 'notify payload is %d bytes long in UTF-8; the notify table holds at most '
135 . "$MAX_PAYLOAD -- refused rather than truncated",
136 length $bytes,
137 ) if length $bytes > $MAX_PAYLOAD;
138  
139 return (
140 8 'INSERT INTO ' . $self->quoted_table
141 . ' (`channel`, `payload`, `pid`, `created_at`)'
142 . ' VALUES (?, ?, CONNECTION_ID(), UTC_TIMESTAMP(6))',
143 [ $channel, $payload ],
144 );
145 }
146  
147  
148 85 ▶sub subscribe_sql {
Subroutine subscribe_sql: called CC=1 SCAR=0.0
Pod documented
149 85 my ($self, $channel) = @_;
150 85 $self->check_channel($channel);
151 84 my $t = $self->quoted_table;
152 84 my $us = _micro($self->{lookback});
153 return (
154 84 "SELECT `id`, NULL, NULL, NULL, NULL FROM $t"
155 . " WHERE `channel` = ? AND `created_at` >= UTC_TIMESTAMP(6) - INTERVAL $us MICROSECOND"
156 . " UNION ALL SELECT (SELECT COALESCE(MAX(`id`), 0) FROM $t WHERE `channel` = ?),"
157 . ' NULL, NULL, NULL, ' . _cutoff_sql($us),
158 [ $channel, $channel ],
159 );
160 }
161  
162  
163 83 ▶sub subscribed {
Subroutine subscribed: called CC=5 SCAR=16.4
Pod documented
164 83 my ($self, $channel, $rows) = @_;
165 83 ▶ my ($meta) = grep { ref $_ eq 'ARRAY' && defined $_->[4] } @{ $rows || [] }
Branch: 1 branch
BranchTrueFalseTotal
my($meta) = grep({ref $_ eq "ARRAY" and defined $_->[4];} @{$rows or [];}) or croak("the subscribe statement for channel '${channel}' returned no mark row") 82 1 83
Condition60%3/5
ref $_ eq 'ARRAY' && defined $_->[4]
!ll&&!rl&&r
01282
$rows || []
l!l
830
MC/DC50%1/2
ref $_ eq 'ARRAY' && defined $_->[4]
ref $_ eq 'ARRAY' defined $_->[4]
MC/DC0%0/1
$rows || []
$rows
Truth table66%2/3
A && B
A= ref $_ eq 'ARRAY'B= defined $_->[4]
ABresult
0X0
100
111
Truth table50%1/2
A
A= $rows
Aresult
11
00
166 or croak "the subscribe statement for channel '$channel' returned no mark row";
167  
168 $self->{channels}{$channel} = {
169 mark => defined $meta->[0] ? "$meta->[0]" : '0',
170 cutoff => "$meta->[4]",
171 82 ▶ seen => { map { ("$_->[0]" => 1) } grep { !defined $_->[4] } @$rows },
Branch: 1 branch
BranchTrueFalseTotal
defined $meta->[0] ? : 82 0 82
172 };
173 82 return;
174 }
175  
176  
177 5 ▶sub unsubscribe {
Subroutine unsubscribe: called CC=2 SCAR=7.1
Pod documented
178 5 my ($self, $channel) = @_;
179 5 ▶ delete $self->{channels}{$channel} if defined $channel;
Branch: 1 branch
BranchTrueFalseTotal
if defined $channel 5 0 5
180 5 return;
181 }
182  
183  
184 146 ▶sub channels { return sort keys %{ $_[0]->{channels} } }
Subroutine channels: called CC=1 SCAR=0.0
Pod documented
185  
186  
187 145 ▶sub poll_sql {
Subroutine poll_sql: called CC=3 SCAR=11.0
Pod documented
188 145 my ($self) = @_;
189 145 ▶ my @channels = $self->channels or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@channels) = $self->channels or return 144 1 145
190  
191 144 my (@by_id, @by_time, @bind_id, @bind_time, %token);
192 144 for my $channel (@channels) {
193 151 my $state = $self->{channels}{$channel};
194 151 push @by_id, '(`channel` = ? AND `id` > CAST(? AS UNSIGNED))';
195 151 push @bind_id, $channel, $state->{mark};
196 151 push @by_time, '(`channel` = ? AND `created_at` >= CAST(? AS DATETIME(6)))';
197 151 push @bind_time, $channel, $state->{cutoff};
198 151 $token{$channel} = $state;
199 }
200  
201 144 my $t = $self->quoted_table;
202 144 my $cols = '`id`, `channel`, `payload`, `pid`, NULL';
203 return (
204 "SELECT $cols FROM $t WHERE " . join(' OR ', @by_id)
205 . " UNION ALL SELECT $cols FROM $t WHERE " . join(' OR ', @by_time)
206 144 . ' UNION ALL SELECT NULL, NULL, NULL, NULL, ' . _cutoff_sql(_micro($self->{lookback})),
207 [ @bind_id, @bind_time ],
208 \%token,
209 );
210 }
211  
212  
213 137 ▶sub polled {
Subroutine polled: called CC=17 SCAR=28.4
Pod documented
214 137 my ($self, $token, $rows) = @_;
215 137 ▶ my ($cutoff) = map { "$_->[4]" } grep { ref $_ eq 'ARRAY' && defined $_->[4] } @{ $rows || [] }
Branch: 1 branch
BranchTrueFalseTotal
my($cutoff) = map({"$_->[4]";} grep({ref $_ eq "ARRAY" and defined $_->[4];} @{$rows or [];})) or croak("the poll statement returned no cutoff row") 136 1 137
Condition60%3/5
ref $_ eq 'ARRAY' && defined $_->[4]
!ll&&!rl&&r
0200136
$rows || []
l!l
1370
MC/DC50%1/2
ref $_ eq 'ARRAY' && defined $_->[4]
ref $_ eq 'ARRAY' defined $_->[4]
MC/DC0%0/1
$rows || []
$rows
Truth table66%2/3
A && B
A= ref $_ eq 'ARRAY'B= defined $_->[4]
ABresult
0X0
100
111
Truth table50%1/2
A
A= $rows
Aresult
11
00
216 or croak 'the poll statement returned no cutoff row';
217  
218 136 my %got; # channel => id => row
219 136 for my $row (grep { !defined $_->[4] } @$rows) {
220 199 my ($id, $channel) = @$row;
221 199 ▶ next unless defined $channel && exists $token->{$channel};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $channel and exists $token->{$channel} 2 197 199
Condition66%2/3
defined $channel and exists $token->{$channel}
!ll&&!rl&&r
02197
MC/DC50%1/2
defined $channel and exists $token->{$channel}
defined $channel exists $token->{$channel}
Truth table66%2/3
A and B
A= defined $channelB= exists $token->{$channel}
ABresult
0X0
100
111
222 197 ▶ $got{$channel}{"$id"} //= $row;
Condition66%2/3
$got{$channel}{"$id"} //= $row
l!l&&r!l&&!r
311660
MC/DC0%0/2
$got{$channel}{"$id"} //= $row
$got{$channel}{"$id"} $row
Truth table66%2/3
A //= B
A= $got{$channel}{"$id"}B= $row
ABresult
1X1
011
000
223 }
224  
225 136 my @new;
226 136 for my $channel (keys %$token) {
227 142 my $state = $token->{$channel};
228 142 my $current = $self->{channels}{$channel};
229 142 ▶ next unless $current && refaddr($current) == refaddr($state);
Branch: 1 branch
BranchTrueFalseTotal
unless $current and builtin::refaddr($current) == builtin::refaddr($state) 2 140 142
Condition100%3/3
$current and builtin::refaddr($current) == builtin::refaddr($state)
!ll&&!rl&&r
11140
MC/DC100%2/2
$current and builtin::refaddr($current) == builtin::refaddr($state)
$current builtin::refaddr($current) == builtin::refaddr($state)
Truth table100%3/3
A and B
A= $currentB= builtin::refaddr($current) == builtin::refaddr($state)
ABresult
0X0
100
111
230  
231 140 ▶ my $rows_now = $got{$channel} || {};
Condition100%2/2
$got{$channel} || {}
l!l
6971
MC/DC100%1/1
$got{$channel} || {}
$got{$channel}
Truth table100%2/2
A
A= $got{$channel}
Aresult
11
00
232 140 for my $id (keys %$rows_now) {
233 163 ▶ push @new, $rows_now->{$id} unless $state->{seen}{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $state->{"seen"}{$id} 35 128 163
234 163 ▶ $state->{mark} = $id if _id_cmp($id, $state->{mark}) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if _id_cmp($id, $state->{"mark"}) > 0 26 137 163
235 }
236 140 $state->{seen} = { map { ($_ => 1) } keys %$rows_now };
237 140 ▶ $state->{cutoff} = $cutoff if $cutoff gt $state->{cutoff};
Branch: 1 branch
BranchTrueFalseTotal
if $cutoff gt $state->{"cutoff"} 50 90 140
238 }
239  
240 136 $self->{cleanup_in}--;
241 return [
242 35 ▶ map { [ "$_->[1]", $_->[2] // '', $_->[3] ] }
Condition50%1/2
$_->[2] // ""
l!l
350
MC/DC0%0/1
$_->[2] // ""
$_->[2]
Truth table50%1/2
A
A= $_->[2]
Aresult
11
00
243 136 sort { _id_cmp("$a->[0]", "$b->[0]") } @new
244 ];
245 }
246  
247  
248 76 ▶sub cleanup_sql {
Subroutine cleanup_sql: called CC=3 SCAR=11.0
Pod documented
249 76 my ($self) = @_;
250 76 ▶ return unless $self->{retention} > 0 && $self->{cleanup_in} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"retention"} > 0 and $self->{"cleanup_in"} <= 0 45 31 76
Condition100%3/3
$self->{"retention"} > 0 and $self->{"cleanup_in"} <= 0
!ll&&!rl&&r
14431
MC/DC100%2/2
$self->{"retention"} > 0 and $self->{"cleanup_in"} <= 0
$self->{"retention"} > 0 $self->{"cleanup_in"} <= 0
Truth table100%3/3
A and B
A= $self->{"retention"} > 0B= $self->{"cleanup_in"} <= 0
ABresult
0X0
100
111
251 31 my $us = _micro($self->{retention});
252 return (
253 31 'DELETE FROM ' . $self->quoted_table
254 . " WHERE `created_at` < UTC_TIMESTAMP(6) - INTERVAL $us MICROSECOND"
255 . " LIMIT $self->{cleanup_limit}",
256 [],
257 );
258 }
259  
260  
261 17 ▶sub cleaned {
Subroutine cleaned: called CC=3 SCAR=11.0
Pod documented
262 17 my ($self, $affected) = @_;
263 $self->{cleanup_in} =
264 17 ▶ (defined $affected && $affected >= $self->{cleanup_limit}) ? 0 : $self->_cleanup_every;
Branch: 1 branch
BranchTrueFalseTotal
defined $affected && $affected >= $self->{'cleanup_limit'} ? : 2 15 17
Condition100%3/3
defined $affected and $affected >= $self->{"cleanup_limit"}
!ll&&!rl&&r
692
MC/DC100%2/2
defined $affected and $affected >= $self->{"cleanup_limit"}
defined $affected $affected >= $self->{"cleanup_limit"}
Truth table100%3/3
A and B
A= defined $affectedB= $affected >= $self->{"cleanup_limit"}
ABresult
0X0
100
111
265 17 return;
266 }
267  
268 15 ▶sub _cleanup_every {
Subroutine _cleanup_every: called CC=3 SCAR=11.4
269 15 my ($self) = @_;
270 15 my $polls = int($CLEANUP_PERIOD / $self->{poll_interval});
271 15 ▶ $polls++ if $polls * $self->{poll_interval} < $CLEANUP_PERIOD;
Branch: 1 branch
BranchTrueFalseTotal
if $polls * $self->{"poll_interval"} < $CLEANUP_PERIOD 0 15 15
272 15 ▶ return $polls > 1 ? $polls : 1;
Branch: 1 branch
BranchTrueFalseTotal
$polls > 1 ? : 15 0 15
273 }
274  
275 # Seconds to whole microseconds, for INTERVAL ... MICROSECOND.
276 651 ▶sub _micro { return int($_[0] * 1_000_000 + 0.5) }
Subroutine _micro: called CC=1 SCAR=0.0
277  
278 # The next cutoff, formatted by the server: its clock, fixed width.
279 228 ▶sub _cutoff_sql {
Subroutine _cutoff_sql: called CC=1 SCAR=0.0
280 228 my ($us) = @_;
281 228 return "DATE_FORMAT(UTC_TIMESTAMP(6) - INTERVAL $us MICROSECOND, '$CUTOFF_FORMAT')";
282 }
283  
284 # Compare two BIGINT UNSIGNED ids exactly, as the decimal strings they are.
285 173 ▶sub _id_cmp { return length($_[0]) <=> length($_[1]) || $_[0] cmp $_[1] }
Subroutine _id_cmp: called CC=2 SCAR=6.9
Condition100%3/3
length $_[0] <=> length $_[1] || $_[0] cmp $_[1]
l!l&&r!l&&!r
378947
MC/DC100%2/2
length $_[0] <=> length $_[1] || $_[0] cmp $_[1]
length $_[0] <=> length $_[1] $_[0] cmp $_[1]
Truth table100%3/3
A || B
A= length $_[0] <=> length $_[1]B= $_[0] cmp $_[1]
ABresult
1X1
011
000
286  
287 30 1;
288  
289 __END__
« blib/lib/DBIO/MySQL/Diff/View.pm ↑ Summary blib/lib/DBIO/MySQL/Introspect/Columns.pm »