blib/lib/DBIO/Ordered.pm

filter: Statementstmt 75.0% 177 / 236 Branchbran 54.6% 59 / 108 Conditioncond 39.1% 9 / 23 MC/DCmcdc 28.5% 4 / 14 Subroutinesub 86.4% 32 / 37 Podpod 100% 20 / 20 totaltotal 68.7% 301 / 438 CC 67 SCAR 33.2
CC
67
Cov
67%
move_to_group
182.0
move_to
13.6
_is_in_group
11.3
CRAP 27.8
« blib/lib/DBIO/Relationship/Base.pm ↑ Summary blib/lib/DBIO/Test/AsyncHarness.pm »
1 package DBIO::Ordered;
2 # ABSTRACT: Maintain a position column over an ordered list of rows
3  
4 257 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 257 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 257 our $VERSION = '0.900007';
8  
9 257 ▶use base qw( DBIO::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 513 ▶sub add_columns {
Subroutine add_columns: called CC=6 SCAR=18.1
Pod documented
13 513 my ($self, @cols) = @_;
14 513 my @columns;
15  
16 513 ▶ while (my $col = shift @cols) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $col = shift @cols) 3331 513 3844
17 3331 ▶ my $info = ref $cols[0] ? shift @cols : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $cols[0] ? : 3331 0 3331
18  
19 3331 ▶ if (delete $info->{position}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $info->{"position"}) 513 2818 3331
20 513 $info->{_ordered_position} = 1;
21 }
22 3331 ▶ if (delete $info->{grouping}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $info->{"grouping"}) 256 3075 3331
23 256 $info->{_ordered_grouping} = 1;
24 }
25 3331 ▶ if (exists $info->{null_position_value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{"null_position_value"}) 0 3331 3331
26 0 $info->{_ordered_null_position_value} = delete $info->{null_position_value};
27 }
28  
29 3331 push @columns, $col => $info;
30 }
31  
32 513 return $self->next::method(@columns);
33 }
34  
35  
36 1099 ▶sub position_column {
Subroutine position_column: called CC=5 SCAR=18.6
Pod documented
37 1099 my $self = shift;
38 1099 ▶ my $source = ref $self
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 1099 0 1099
39 ? $self->result_source
40 : $self->result_source_instance;
41 1099 my $info = $source->columns_info;
42 1099 for my $col (sort keys %$info) {
43 4690 ▶ return $col if $info->{$col}{_ordered_position};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{$col}{"_ordered_position"} 1099 3591 4690
44 }
45 $self->throw_exception(
46 0 ▶ "No position column defined on " . (ref $self || $self) .
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
47 " -- mark a column with `position => 1` in add_columns"
48 );
49 }
50  
51  
52 89 ▶sub grouping_column {
Subroutine grouping_column: called CC=4 SCAR=14.2
Pod documented
53 89 my $self = shift;
54 89 ▶ my $source = ref $self
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 89 0 89
55 ? $self->result_source
56 : $self->result_source_instance;
57 89 my $info = $source->columns_info;
58 89 my @group = sort grep { $info->{$_}{_ordered_grouping} } keys %$info;
59 89 ▶ return undef if !@group;
Branch: 1 branch
BranchTrueFalseTotal
unless @group 40 49 89
60 49 ▶ return $group[0] if @group == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @group == 1 49 0 49
61 0 return \@group;
62 }
63  
64  
65 0 ▶sub null_position_value {
Subroutine null_position_value: not called CC=2 SCAR=17.9
Pod documented
66 0 my $self = shift;
67 0 my $pos_col = $self->position_column;
68 0 my $col_info = $self->result_source->columns_info->{$pos_col};
69 return exists $col_info->{_ordered_null_position_value}
70 ? $col_info->{_ordered_null_position_value}
71 0 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $col_info->{'_ordered_null_position_value'} ? : 0 0 0
72 }
73  
74  
75 4 ▶sub siblings {
Subroutine siblings: called CC=1 SCAR=0.0
Pod documented
76 4 my $self = shift;
77 4 return $self->_siblings->search({}, { order_by => $self->position_column });
78 }
79  
80  
81 9 ▶sub previous_siblings {
Subroutine previous_siblings: called CC=2 SCAR=7.0
Pod documented
82 9 my $self = shift;
83 9 my $position_column = $self->position_column;
84 9 my $position = $self->get_column($position_column);
85 9 ▶ return ( defined $position
Branch: 1 branch
BranchTrueFalseTotal
defined $position ? : 9 0 9
86 ? $self->_siblings->search({ $position_column => { '<', $position } })
87 : $self->_siblings
88 );
89 }
90  
91  
92 64 ▶sub next_siblings {
Subroutine next_siblings: called CC=2 SCAR=6.9
Pod documented
93 64 my $self = shift;
94 64 my $position_column = $self->position_column;
95 64 my $position = $self->get_column($position_column);
96 64 ▶ return ( defined $position
Branch: 1 branch
BranchTrueFalseTotal
defined $position ? : 63 1 64
97 ? $self->_siblings->search({ $position_column => { '>', $position } })
98 : $self->_siblings
99 );
100 }
101  
102  
103 3 ▶sub previous_sibling {
Subroutine previous_sibling: called CC=2 SCAR=7.0
Pod documented
104 3 my $self = shift;
105 3 my $position_column = $self->position_column;
106 3 my $psib = $self->previous_siblings->search(
107 {}, { rows => 1, order_by => { '-desc' => $position_column } },
108 )->single;
109 3 ▶ return defined $psib ? $psib : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $psib ? : 3 0 3
110 }
111  
112  
113 3 ▶sub first_sibling {
Subroutine first_sibling: called CC=2 SCAR=7.0
Pod documented
114 3 my $self = shift;
115 3 my $position_column = $self->position_column;
116 3 my $fsib = $self->previous_siblings->search(
117 {}, { rows => 1, order_by => { '-asc' => $position_column } },
118 )->single;
119 3 ▶ return defined $fsib ? $fsib : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $fsib ? : 3 0 3
120 }
121  
122  
123 3 ▶sub next_sibling {
Subroutine next_sibling: called CC=2 SCAR=7.0
Pod documented
124 3 my $self = shift;
125 3 my $position_column = $self->position_column;
126 3 my $nsib = $self->next_siblings->search(
127 {}, { rows => 1, order_by => { '-asc' => $position_column } },
128 )->single;
129 3 ▶ return defined $nsib ? $nsib : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $nsib ? : 3 0 3
130 }
131  
132  
133 3 ▶sub last_sibling {
Subroutine last_sibling: called CC=2 SCAR=7.0
Pod documented
134 3 my $self = shift;
135 3 my $position_column = $self->position_column;
136 3 my $lsib = $self->next_siblings->search(
137 {}, { rows => 1, order_by => { '-desc' => $position_column } },
138 )->single;
139 3 ▶ return defined $lsib ? $lsib : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $lsib ? : 3 0 3
140 }
141  
142 55 ▶sub _last_sibling_posval {
Subroutine _last_sibling_posval: called CC=1 SCAR=0.0
143 55 my $self = shift;
144 55 my $position_column = $self->position_column;
145  
146 55 my $cursor = $self->next_siblings->search(
147 {}, { rows => 1, order_by => { '-desc' => $position_column }, select => $position_column },
148 )->cursor;
149  
150 55 my ($pos) = $cursor->next;
151 55 return $pos;
152 }
153  
154  
155 1 ▶sub move_previous {
Subroutine move_previous: called CC=1 SCAR=0.0
Pod documented
156 1 my $self = shift;
157 1 return $self->move_to($self->_position - 1);
158 }
159  
160  
161 4 ▶sub move_next {
Subroutine move_next: called CC=2 SCAR=6.9
Pod documented
162 4 my $self = shift;
163 4 ▶ return 0 unless defined $self->_last_sibling_posval;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_last_sibling_posval 1 3 4
164 3 return $self->move_to($self->_position + 1);
165 }
166  
167  
168 0 ▶sub move_first { return shift->move_to(1) }
Subroutine move_first: not called CC=1 SCAR=6.9
Pod documented
169  
170  
171 50 ▶sub move_last {
Subroutine move_last: called CC=2 SCAR=6.9
Pod documented
172 50 my $self = shift;
173 50 my $last_posval = $self->_last_sibling_posval;
174 50 ▶ return 0 unless defined $last_posval;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $last_posval 2 48 50
175 48 return $self->move_to($self->_position_from_value($last_posval));
176 }
177  
178  
179 65 ▶sub move_to {
Subroutine move_to: called CC=13 SCAR=26.1
Pod documented
180 65 my ($self, $to_position) = @_;
181 65 ▶ $self->throw_exception('move_to: position must be a non-negative integer')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to_position and not ref $to_position and $to_position =~ /\A[0-9]+\z/ 9 56 65
Condition100%6/6
defined $to_position and not ref $to_position and $to_position =~ /\A[0-9]+\z/
!ll&&!rl&&r
4556
defined $to_position and not ref $to_position
!ll&&!rl&&r
1361
MC/DC100%3/3
defined $to_position and not ref $to_position and $to_position =~ /\A[0-9]+\z/
defined $to_position not ref $to_position $to_position =~ /\A[0-9]+\z/
Truth table100%4/4
A and not(B) and C
A= defined $to_positionB= not ref $to_positionC= $to_position =~ /\A[0-9]+\z/
ABCresult
0XX0
10X0
1100
1111
182 unless defined $to_position and !ref $to_position
183 and $to_position =~ /\A[0-9]+\z/;
184 56 ▶ return 0 if ($to_position < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $to_position < 1 1 55 56
185  
186 55 my $position_column = $self->position_column;
187  
188 55 my $is_txn;
189 55 ▶ if ($is_txn = $self->result_source->schema->storage->transaction_depth) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_txn = $self->result_source->schema->storage->transaction_depth) { } 48 7 55
elsif ($self->is_column_changed($position_column)) { } 0 7 7
190 48 ▶ $self->store_column(
Condition33%1/3
($self->result_source->resultset->search($self->_storage_ident_condition, {'rows', 1, 'columns', $position_column})->cursor->next)[0] || $self->throw_exception(sprintf(q[Unable to locate object '%s' in storage - object went ouf of sync...?], $self->ID))
l!l&&r!l&&!r
4800
MC/DC0%0/2
($self->result_source->resultset->search($self->_storage_ident_condition, {'rows', 1, 'columns', $position_column})->cursor->next)[0] || $self->throw_exception(sprintf(q[Unable to locate object '%s' in storage - object went ouf of sync...?], $self->ID))
($self->result_source->resultset->search($self->_storage_ident_condition, {'rows', 1, 'columns', $position_column})->cursor->next)[0] $self->throw_exception(sprintf(q[Unable to locate object '%s' in storage - object went ouf of sync...?], $self->ID))
Truth table33%1/3
A || B
A= ($self->result_source->resultset->search($self->_storage_ident_condition, {'rows', 1, 'columns', $position_column})->cursor->next)[0]B= $self->throw_exception(sprintf(q[Unable to locate object '%s' in storage - object went ouf of sync...?], $self->ID))
ABresult
1X1
011
000
191 $position_column,
192 ( $self->result_source
193 ->resultset
194 ->search($self->_storage_ident_condition, { rows => 1, columns => $position_column })
195 ->cursor
196 ->next
197 )[0] || $self->throw_exception(
198 sprintf "Unable to locate object '%s' in storage - object went ouf of sync...?",
199 $self->ID
200 ),
201 );
202 48 delete $self->{_dirty_columns}{$position_column};
203 }
204 elsif ($self->is_column_changed($position_column)) {
205 0 $self->store_column($position_column, delete $self->{_column_data_in_storage}{$position_column});
206 0 delete $self->{_dirty_columns}{$position_column};
207 }
208  
209 55 my $from_position = $self->_position;
210  
211 55 ▶ if ($from_position == $to_position) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from_position == $to_position) 51 4 55
212 51 return 0;
213 }
214  
215 4 ▶ my $guard = $is_txn ? undef : $self->result_source->schema->txn_scope_guard;
Branch: 1 branch
BranchTrueFalseTotal
$is_txn ? : 0 4 4
216  
217 4 my ($direction, @between);
218 4 ▶ if ($from_position < $to_position) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from_position < $to_position) { } 3 1 4
219 3 $direction = -1;
220 3 @between = map { $self->_position_value($_) } ($from_position + 1, $to_position);
221 }
222 else {
223 1 $direction = 1;
224 1 @between = map { $self->_position_value($_) } ($to_position, $from_position - 1);
225 }
226  
227 4 my $new_pos_val = $self->_position_value($to_position);
228  
229 4 ▶ if (grep { $_ eq $position_column } (map { @$_ } values %{{ $self->result_source->unique_constraints }})) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $position_column;} map({@$_;} values %{+{$self->result_source->unique_constraints};})) 0 4 4
230 0 $self->_ordered_internal_update({ $position_column => $self->null_position_value });
231 }
232  
233 4 $self->_shift_siblings($direction, @between);
234 4 $self->_ordered_internal_update({ $position_column => $new_pos_val });
235  
236 4 ▶ $guard->commit if $guard;
Branch: 1 branch
BranchTrueFalseTotal
if $guard 4 0 4
237 4 return 1;
238 }
239  
240  
241 0 ▶sub move_to_group {
Subroutine move_to_group: not called CC=13 SCAR=52.0
Pod documented
242 0 my ($self, $to_group, $to_position) = @_;
243  
244 0 ▶ unless (ref $to_group eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $to_group eq "HASH") 0 0 0
245 0 my @gcols = $self->_grouping_columns;
246 0 ▶ $self->throw_exception('Single group supplied for a multi-column group identifier') if @gcols > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @gcols > 1 0 0 0
247 0 $to_group = { $gcols[0] => $to_group };
248 }
249  
250 0 my $position_column = $self->position_column;
251  
252 0 ▶ return 0 if (defined($to_position) and $to_position < 1);
Branch: 1 branch
BranchTrueFalseTotal
if defined $to_position and $to_position < 1 0 0 0
Condition0%0/3
defined $to_position and $to_position < 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $to_position and $to_position < 1
defined $to_position $to_position < 1
Truth table0%0/3
A and B
A= defined $to_positionB= $to_position < 1
ABresult
0X0
100
111
253  
254 0 for ($self->_grouping_columns) {
255 0 ▶ if ($self->is_column_changed($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_column_changed($_)) 0 0 0
256 0 $self->store_column($_, delete $self->{_column_data_in_storage}{$_});
257 0 delete $self->{_dirty_columns}{$_};
258 }
259 }
260  
261 0 ▶ if ($self->_is_in_group($to_group)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_in_group($to_group)) 0 0 0
262 0 my $ret;
263 0 ▶ if (defined $to_position) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to_position) 0 0 0
264 0 $ret = $self->move_to($to_position);
265 }
266 0 ▶ return $ret || 0;
Condition0%0/2
$ret || 0
l!l
00
MC/DC0%0/1
$ret || 0
$ret
Truth table0%0/2
A
A= $ret
Aresult
11
00
267 }
268  
269 0 my $guard = $self->result_source->schema->txn_scope_guard;
270  
271 0 $self->move_last;
272  
273 0 $self->set_inflated_columns({ %$to_group, $position_column => undef });
274 0 my $new_group_last_posval = $self->_last_sibling_posval;
275 0 my $new_group_last_position = $self->_position_from_value($new_group_last_posval);
276  
277 0 ▶ if (not defined($to_position) or $to_position > $new_group_last_position) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $to_position or $to_position > $new_group_last_position) { } 0 0 0
Condition0%0/3
not defined $to_position or $to_position > $new_group_last_position
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $to_position or $to_position > $new_group_last_position
not defined $to_position $to_position > $new_group_last_position
Truth table0%0/3
not(A) or B
A= not defined $to_positionB= $to_position > $new_group_last_position
ABresult
1X1
011
000
278 0 ▶ $self->set_column(
Branch: 1 branch
BranchTrueFalseTotal
$new_group_last_position ? : 0 0 0
279 $position_column => $new_group_last_position
280 ? $self->_next_position_value($new_group_last_posval)
281 : $self->_initial_position_value
282 );
283 }
284 else {
285 0 my $bumped_pos_val = $self->_position_value($to_position);
286 0 my @between = map { $self->_position_value($_) } ($to_position, $new_group_last_position);
287 0 $self->_shift_siblings(1, @between);
288 0 $self->set_column($position_column => $bumped_pos_val);
289 }
290  
291 0 $self->_ordered_internal_update;
292 0 $guard->commit;
293 0 return 1;
294 }
295  
296  
297 752 ▶sub insert {
Subroutine insert: called CC=3 SCAR=11.0
Pod documented
298 752 my $self = shift;
299 752 my $position_column = $self->position_column;
300  
301 752 ▶ unless ($self->get_column($position_column)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_column($position_column)) 1 751 752
302 1 my $lsib_posval = $self->_last_sibling_posval;
303 1 ▶ $self->set_column(
Branch: 1 branch
BranchTrueFalseTotal
defined $lsib_posval ? : 0 1 1
304 $position_column => (defined $lsib_posval
305 ? $self->_next_position_value($lsib_posval)
306 : $self->_initial_position_value
307 )
308 );
309 }
310  
311 752 return $self->next::method(@_);
312 }
313  
314  
315 6 ▶sub update {
Subroutine update: called CC=6 SCAR=22.0
Pod documented
316 6 my $self = shift;
317  
318 6 ▶ return $self->next::method(@_) if $self->result_source->schema->{_ORDERED_INTERNAL_UPDATE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->result_source->schema->{"_ORDERED_INTERNAL_UPDATE"} 4 2 6
319  
320 2 my $upd = shift;
321 2 ▶ $self->set_inflated_columns($upd) if $upd;
Branch: 1 branch
BranchTrueFalseTotal
if $upd 2 0 2
322  
323 2 my $position_column = $self->position_column;
324 2 my @group_columns = $self->_grouping_columns;
325  
326 0 my $changed_ordering_cols = { map { $_ => $self->get_column($_) } grep { $self->is_column_changed($_) } ($position_column, @group_columns) };
327  
328 2 ▶ if (! keys %$changed_ordering_cols) {
Branch: 2 branches
BranchTrueFalseTotal
if (not keys %$changed_ordering_cols) { } 2 0 2
elsif (grep {exists $changed_ordering_cols->{$_};} @group_columns) { } 0 0 0
329 2 return $self->next::method(undef, @_);
330 }
331 0 elsif (grep { exists $changed_ordering_cols->{$_} } @group_columns) {
332 $self->move_to_group(
333 { $self->_grouping_clause },
334 (exists $changed_ordering_cols->{$position_column}
335 0 ▶ ? $changed_ordering_cols->{$position_column}
Branch: 1 branch
BranchTrueFalseTotal
exists $changed_ordering_cols->{$position_column} ? : 0 0 0
336 : $self->_position
337 ),
338 );
339 }
340 else {
341 0 $self->move_to($changed_ordering_cols->{$position_column});
342 }
343  
344 0 return $self;
345 }
346  
347  
348 50 ▶sub delete {
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
349 50 my $self = shift;
350 50 my $guard = $self->result_source->schema->txn_scope_guard;
351 50 $self->move_last;
352 50 $self->next::method(@_);
353 50 $guard->commit;
354 50 return $self;
355 }
356  
357 6 ▶sub _track_storage_value {
Subroutine _track_storage_value: called CC=2 SCAR=7.0
358 6 my ($self, $col) = @_;
359 return (
360 $self->next::method($col)
361 ||
362 6 ▶ grep { $_ eq $col } ($self->position_column, $self->_grouping_columns)
Condition66%2/3
$self->next::method($col) || grep({$_ eq $col;} $self->position_column, $self->_grouping_columns)
l!l&&r!l&&!r
042
MC/DC50%1/2
$self->next::method($col) || grep({$_ eq $col;} $self->position_column, $self->_grouping_columns)
$self->next::method($col) grep({$_ eq $col;} $self->position_column, $self->_grouping_columns)
Truth table66%2/3
A || B
A= $self->next::method($col)B= grep({$_ eq $col;} $self->position_column, $self->_grouping_columns)
ABresult
1X1
011
000
363 );
364 }
365  
366  
367 107 ▶sub _position_from_value {
Subroutine _position_from_value: called CC=2 SCAR=7.1
368 107 my ($self, $val) = @_;
369 107 ▶ return 0 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 107 107
370 107 return $val;
371 }
372  
373  
374 12 ▶sub _position_value {
Subroutine _position_value: called CC=1 SCAR=0.0
375 12 my ($self, $pos) = @_;
376 12 return $pos;
377 }
378  
379  
380 257 __PACKAGE__->mk_classdata('_initial_position_value' => 1);
381  
382  
383 0 ▶sub _next_position_value { return $_[1] + 1 }
Subroutine _next_position_value: not called CC=1 SCAR=6.9
384  
385  
386 4 ▶sub _shift_siblings {
Subroutine _shift_siblings: called CC=6 SCAR=18.9
387 4 my ($self, $direction, @between) = @_;
388 4 ▶ return 0 unless $direction;
Branch: 1 branch
BranchTrueFalseTotal
unless $direction 0 4 4
389  
390 4 my $position_column = $self->position_column;
391  
392 4 my ($op, $ord);
393 4 ▶ if ($direction < 0) { $op = '-'; $ord = 'asc' }
Branch: 1 branch
BranchTrueFalseTotal
if ($direction < 0) { } 3 1 4
394 1 else { $op = '+'; $ord = 'desc' }
395  
396 4 my $shift_rs = $self->_group_rs->search({ $position_column => { -between => \@between } });
397  
398 4 my $rsrc = $self->result_source;
399 4 local $rsrc->schema->{_ORDERED_INTERNAL_UPDATE} = 1;
400 4 my @pcols = $rsrc->primary_columns;
401  
402 4 ▶ if (grep { $_ eq $position_column } (map { @$_ } values %{{ $rsrc->unique_constraints }})) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $position_column;} map({@$_;} values %{+{$rsrc->unique_constraints};})) { } 0 4 4
403 0 my $clean_rs = $rsrc->resultset;
404 0 for ($shift_rs->search(
405 {}, { order_by => { "-$ord", $position_column }, select => [$position_column, @pcols] }
406 )->cursor->all) {
407 0 my $pos = shift @$_;
408 0 ▶ $clean_rs->find(@$_)->update({ $position_column => $pos + (($op eq '+') ? 1 : -1) });
Branch: 1 branch
BranchTrueFalseTotal
$op eq '+' ? : 0 0 0
409 }
410 }
411 else {
412 4 my $quoted = $rsrc->storage->sql_maker->_quote($position_column);
413 4 $shift_rs->update({ $position_column => \"$quoted $op 1" });
414 }
415 }
416  
417 81 ▶sub _group_rs {
Subroutine _group_rs: called CC=2 SCAR=6.9
418 81 my $self = shift;
419 81 my $rs = $self->result_source->resultset;
420 # ADR 0045 / karr k325: every sibling resultset and sibling row comes from
421 # here, so this is where a context-bound row hands its pin on (the ->search
422 # below passes it to the clone).
423 81 ▶ $rs->{_async_context} = $self->{_async_context} if $self->{_async_context};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_async_context"} 14 67 81
424 81 return $rs->search({ $self->_grouping_clause });
425 }
426  
427 77 ▶sub _siblings {
Subroutine _siblings: called CC=2 SCAR=6.9
428 77 my $self = shift;
429 77 my $position_column = $self->position_column;
430 77 my $pos;
431 77 ▶ return defined($pos = $self->get_column($position_column))
Branch: 1 branch
BranchTrueFalseTotal
defined($pos = $self->get_column($position_column)) ? : 76 1 77
432 ? $self->_group_rs->search({ $position_column => { '!=' => $pos } })
433 : $self->_group_rs;
434 }
435  
436 59 ▶sub _position {
Subroutine _position: called CC=1 SCAR=0.0
437 59 my $self = shift;
438 59 return $self->_position_from_value($self->get_column($self->position_column));
439 }
440  
441 81 ▶sub _grouping_clause {
Subroutine _grouping_clause: called CC=1 SCAR=0.0
442 81 my ($self) = @_;
443 81 return map { $_ => $self->get_column($_) } $self->_grouping_columns;
444 }
445  
446 89 ▶sub _grouping_columns {
Subroutine _grouping_columns: called CC=3 SCAR=11.2
447 89 my ($self) = @_;
448 89 my $col = $self->grouping_column;
449 0 ▶ if (ref $col eq 'ARRAY') { return @$col }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $col eq 'ARRAY') { } 0 89 89
elsif (defined $col) { } 49 40 89
450 49 elsif (defined $col) { return ($col) }
451 40 else { return () }
452 }
453  
454 0 ▶sub _is_in_group {
Subroutine _is_in_group: not called CC=4 SCAR=24.2
455 0 my ($self, $other) = @_;
456 0 my $current = { $self->_grouping_clause };
457  
458 257 ▶ no warnings qw/uninitialized/;
Subroutine BEGIN: called CC=1 SCAR=0.0
459  
460 0 ▶ return 0 if (
Branch: 1 branch
BranchTrueFalseTotal
if join("\0", sort(keys %$current)) ne join("\0", sort(keys %$other)) 0 0 0
461 join("\x00", sort keys %$current) ne join("\x00", sort keys %$other)
462 );
463 0 for my $key (keys %$current) {
464 0 ▶ return 0 if $current->{$key} ne $other->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $current->{$key} ne $other->{$key} 0 0 0
465 }
466 0 return 1;
467 }
468  
469 4 ▶sub _ordered_internal_update {
Subroutine _ordered_internal_update: called CC=1 SCAR=0.0
470 4 my $self = shift;
471 4 local $self->result_source->schema->{_ORDERED_INTERNAL_UPDATE} = 1;
472 4 return $self->update(@_);
473 }
474  
475 257 1;
476  
477 __END__
« blib/lib/DBIO/Relationship/Base.pm ↑ Summary blib/lib/DBIO/Test/AsyncHarness.pm »