BatchUpdate/Update.pm

filter: Statementstmt 100% 42 / 42 Branchbran 80.0% 8 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 89.7% 61 / 68 CC 9 SCAR 10.2
CC
9
Cov
95%
_build_batches
5.0
batch_key
3.0
_build_resultset
2.0
CRAP 2.8
↑ Summary BatchUpdate.pm »
1 package DBIx::Class::BatchUpdate::Update;
2 1 $DBIx::Class::BatchUpdate::Update::VERSION = '1.003';
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use autobox::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use true;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Storable qw/ nfreeze /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use DBIx::Class::BatchUpdate::Batch;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12  
13 1 has rows => ( is => "ro", required => 1 );
14  
15 1 has resultset => (is => "lazy");
16 sub _build_resultset {
17 2 ▶ my $self = shift;
Subroutine _build_resultset: called CC=2 SCAR=6.9
18 2 ▶ my $row = $self->rows->[0] or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $row = $self->rows->[0] or return undef 1 1 2
19 1 return $row->result_source->resultset();
20 }
21  
22 1 has batches => ( is => "lazy");
23 sub _build_batches {
24 2 ▶ my $self = shift;
Subroutine _build_batches: called CC=5 SCAR=16.2
25 2 ▶ $self->resultset or return [];
Branch: 1 branch
BranchTrueFalseTotal
$self->resultset or return [] 1 1 2
26  
27 1 my $key_batch = {};
28 1 for my $row ($self->rows->elements) {
29 3 my $key_value = { $row->get_dirty_columns };
30 3 ▶ my $batch_key = $self->batch_key($key_value) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $batch_key = $self->batch_key($key_value) or next 0 3 3
31 3 ▶ my $batch = $key_batch->{ $batch_key } //= DBIx::Class::BatchUpdate::Batch->new({
Condition66%2/3
$key_batch->{$batch_key} //= "DBIx::Class::BatchUpdate::Batch"->new({"key_value", $key_value, "resultset", $self->resultset, "key", $batch_key})
l!l&&r!l&&!r
120
MC/DC0%0/2
$key_batch->{$batch_key} //= "DBIx::Class::BatchUpdate::Batch"->new({"key_value", $key_value, "resultset", $self->resultset, "key", $batch_key})
$key_batch->{$batch_key} "DBIx::Class::BatchUpdate::Batch"->new({"key_value", $key_value, "resultset", $self->resultset, "key", $batch_key})
Truth table66%2/3
A //= B
A= $key_batch->{$batch_key}B= "DBIx::Class::BatchUpdate::Batch"->new({"key_value", $key_value, "resultset", $self->resultset, "key", $batch_key})
ABresult
1X1
011
000
32 key_value => $key_value,
33 resultset => $self->resultset,
34 key => $batch_key,
35 });
36 3 $batch->ids->push( $row->id );
37 };
38  
39 # Sort to get some semblance of determinism wrt insert ordering
40 1 return [ sort { $a->key cmp $b->key } $key_batch->values ];
41 }
42  
43 sub batch_key {
44 4 ▶ my $self = shift;
Subroutine batch_key: called CC=3 SCAR=11.0
Pod undocumented
45 4 my ($key_value) = @_;
46 4 ▶ keys %$key_value or return undef;
Branch: 1 branch
BranchTrueFalseTotal
keys %$key_value or return undef 0 4 4
47  
48 # sort hash keys for a stable representation
49 4 local $Storable::canonical = 1;
50 return nfreeze(
51 {
52 # Assume the pk isn't dirty
53 map {
54 4 my $value = $key_value->{$_};
55 7 ▶ $_ => defined($value) ? "$value" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 6 1 7
56 }
57 keys %$key_value,
58 },
59 );
60 }
61  
62 sub update {
63 1 ▶ my $self = shift;
Subroutine update: called CC=2 SCAR=6.9
Pod undocumented
64 1 for my $batch ( $self->batches->elements ) {
65 2 $batch->update();
66 }
67 }
↑ Summary BatchUpdate.pm »