| 1 | # $Id: State.pm 82 2020-05-30 06:14:27Z stro $ | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package CPAN::SQLite::State; | ||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | no warnings qw(redefine); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 7 | our $VERSION = '0.218'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use English qw/-no_match_vars/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use CPAN::SQLite::DBI qw($dbh); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use CPAN::SQLite::DBI::Index; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use CPAN::SQLite::Util qw(has_hash_data print_debug); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 7 | my %tbl2obj; | |||||||||||||||||||||||||||
| 18 | 7 | $tbl2obj{$_} = __PACKAGE__ . '::' . $_ for (qw(dists mods auths info)); | |||||||||||||||||||||||||||
| 19 | 7 | my %obj2tbl = reverse %tbl2obj; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 7 | our $dbh = $CPAN::SQLite::DBI::dbh; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub new { | ||||||||||||||||||||||||||||
| 24 | 1 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | if ($args{setup}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | die "No state information available under setup"; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | my $index = $args{index}; | |||||||||||||||||||||||||||
| 31 | 1 | my @tables = qw(dists mods auths info); | |||||||||||||||||||||||||||
| 32 | 1 | foreach my $table (@tables) { | |||||||||||||||||||||||||||
| 33 | 4 | my $obj = $index->{$table}; | |||||||||||||||||||||||||||
| 34 | 4 | ▶ | die "Please supply a CPAN::SQLite::Index::$table object" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$obj and ref $obj eq "CPAN::SQLite::Index::$table"
MC/DC0%0/2
$obj and ref $obj eq "CPAN::SQLite::Index::$table"
$obj
ref $obj eq "CPAN::SQLite::Index::$table"
Truth table33%1/3
A and B
A= $objB= ref $obj eq "CPAN::SQLite::Index::$table"
| |||||||||||||||||||||||||||||
| 35 | unless ($obj and ref($obj) eq "CPAN::SQLite::Index::$table"); | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 1 | my $cdbi = CPAN::SQLite::DBI::Index->new(%args); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | my $self = { | ||||||||||||||||||||||||||||
| 40 | index => $index, | ||||||||||||||||||||||||||||
| 41 | obj => {}, | ||||||||||||||||||||||||||||
| 42 | cdbi => $cdbi, | ||||||||||||||||||||||||||||
| 43 | reindex => $args{reindex}, | ||||||||||||||||||||||||||||
| 44 | 1 | }; | |||||||||||||||||||||||||||
| 45 | 1 | return bless $self, $class; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub state { | ||||||||||||||||||||||||||||
| 49 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
state: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | unless ($self->create_objs()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | print_debug("Cannot create objects"); | |||||||||||||||||||||||||||
| 52 | 0 | return; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 1 | ▶ | unless ($self->state_info()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | print_debug("Getting state information failed"); | |||||||||||||||||||||||||||
| 56 | 0 | return; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 1 | return 1; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub create_objs { | ||||||||||||||||||||||||||||
| 62 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create_objs: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 1 | my @tables = qw(dists auths mods info); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | foreach my $table (@tables) { | |||||||||||||||||||||||||||
| 66 | 4 | my $obj; | |||||||||||||||||||||||||||
| 67 | 4 | my $pack = $tbl2obj{$table}; | |||||||||||||||||||||||||||
| 68 | 4 | my $index = $self->{index}->{$table}; | |||||||||||||||||||||||||||
| 69 | 4 | ▶ | if ($index and ref($index) eq "CPAN::SQLite::Index::$table") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$index and ref $index eq "CPAN::SQLite::Index::$table"
MC/DC0%0/2
$index and ref $index eq "CPAN::SQLite::Index::$table"
$index
ref $index eq "CPAN::SQLite::Index::$table"
Truth table33%1/3
A and B
A= $indexB= ref $index eq "CPAN::SQLite::Index::$table"
| |||||||||||||||||||||||||||||
| 70 | 4 | my $info = $index->{info}; | |||||||||||||||||||||||||||
| 71 | 4 | ▶ | if ($table ne 'info') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 3 | ▶ | return unless has_hash_data($info); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | $obj = $pack->new( | ||||||||||||||||||||||||||||
| 75 | info => $info, | ||||||||||||||||||||||||||||
| 76 | 4 | cdbi => $self->{cdbi}->{objs}->{$table}); | |||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||
| 78 | 0 | $obj = $pack->new(); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 4 | $self->{obj}->{$table} = $obj; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | foreach my $table (@tables) { | |||||||||||||||||||||||||||
| 84 | 4 | my $obj = $self->{obj}->{$table}; | |||||||||||||||||||||||||||
| 85 | 4 | foreach (@tables) { | |||||||||||||||||||||||||||
| 86 | 16 | ▶ | next if ref($obj) eq $tbl2obj{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 12 | $obj->{obj}->{$_} = $self->{obj}->{$_}; | |||||||||||||||||||||||||||
| 88 | 12 | weaken $obj->{obj}->{$_}; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 1 | return 1; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub state_info { | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
state_info: called CC=7 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 1 | my @methods = qw(ids state); | |||||||||||||||||||||||||||
| 97 | 1 | my @tables = qw(dists auths mods); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 1 | for my $method (@methods) { | |||||||||||||||||||||||||||
| 100 | 2 | for my $table (@tables) { | |||||||||||||||||||||||||||
| 101 | 6 | my $obj = $self->{obj}->{$table}; | |||||||||||||||||||||||||||
| 102 | 6 | ▶ | unless ($obj->$method()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if (my $error = $obj->{error_msg}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | print_debug("Fatal error from ", ref($obj), ": ", $error, $/); | |||||||||||||||||||||||||||
| 105 | 0 | return; | |||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||
| 107 | 0 | my $info = $obj->{info_msg}; | |||||||||||||||||||||||||||
| 108 | 0 | print_debug("Info from ", ref($obj), ": ", $info, $/); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # Check "info" | ||||||||||||||||||||||||||||
| 115 | 1 | ▶ | if (my $obj = $self->{'obj'}->{'info'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 1 | ▶ | return unless $obj->state; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 1 | return 1; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | package CPAN::SQLite::State::auths; | ||||||||||||||||||||||||||||
| 122 | 7 | ▶ | use parent 'CPAN::SQLite::State'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 123 | 7 | ▶ | use CPAN::SQLite::Util qw(has_hash_data print_debug); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | sub new { | ||||||||||||||||||||||||||||
| 126 | 1 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||
| 127 | 1 | my $info = $args{info}; | |||||||||||||||||||||||||||
| 128 | 1 | ▶ | die "No author info available" unless has_hash_data($info); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 1 | my $cdbi = $args{cdbi}; | |||||||||||||||||||||||||||
| 130 | 1 | ▶ | die "No dbi object available" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cdbi and ref $cdbi eq "CPAN::SQLite::DBI::Index::auths"
MC/DC0%0/2
$cdbi and ref $cdbi eq "CPAN::SQLite::DBI::Index::auths"
$cdbi
ref $cdbi eq "CPAN::SQLite::DBI::Index::auths"
Truth table33%1/3
A and B
A= $cdbiB= ref $cdbi eq "CPAN::SQLite::DBI::Index::auths"
| |||||||||||||||||||||||||||||
| 131 | unless ($cdbi and ref($cdbi) eq 'CPAN::SQLite::DBI::Index::auths'); | ||||||||||||||||||||||||||||
| 132 | 1 | my $self = { | |||||||||||||||||||||||||||
| 133 | info => $info, | ||||||||||||||||||||||||||||
| 134 | insert => {}, | ||||||||||||||||||||||||||||
| 135 | update => {}, | ||||||||||||||||||||||||||||
| 136 | delete => {}, | ||||||||||||||||||||||||||||
| 137 | ids => {}, | ||||||||||||||||||||||||||||
| 138 | obj => {}, | ||||||||||||||||||||||||||||
| 139 | cdbi => $cdbi, | ||||||||||||||||||||||||||||
| 140 | error_msg => '', | ||||||||||||||||||||||||||||
| 141 | info_msg => '', | ||||||||||||||||||||||||||||
| 142 | }; | ||||||||||||||||||||||||||||
| 143 | 1 | return bless $self, $class; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | sub ids { | ||||||||||||||||||||||||||||
| 147 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
ids: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||
| 148 | 1 | my $cdbi = $self->{cdbi}; | |||||||||||||||||||||||||||
| 149 | 1 | ▶ | $self->{ids} = $cdbi->fetch_ids() or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 0 | $self->{error_msg} = $cdbi->{error_msg}; | |||||||||||||||||||||||||||
| 151 | 0 | return; | |||||||||||||||||||||||||||
| 152 | }; | ||||||||||||||||||||||||||||
| 153 | 1 | return 1; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | sub state { | ||||||||||||||||||||||||||||
| 157 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
state: called CC=8 SCAR=29.5
| |||||||||||||||||||||||||||||
| 158 | 1 | my $auth_ids = $self->{ids}; | |||||||||||||||||||||||||||
| 159 | 1 | ▶ | return unless my $dist_obj = $self->{obj}->{dists}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 1 | my $dist_update = $dist_obj->{update}; | |||||||||||||||||||||||||||
| 161 | 1 | my $dist_insert = $dist_obj->{insert}; | |||||||||||||||||||||||||||
| 162 | 1 | my $dists = $dist_obj->{info}; | |||||||||||||||||||||||||||
| 163 | 1 | my ($update, $insert); | |||||||||||||||||||||||||||
| 164 | 1 | ▶ | if (has_hash_data($dist_insert)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | foreach my $distname (keys %{$dist_insert}) { | |||||||||||||||||||||||||||
| 167 | 0 | my $cpanid = $dists->{$distname}->{cpanid}; | |||||||||||||||||||||||||||
| 168 | 0 | ▶ | if (my $auth_id = $auth_ids->{$cpanid}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | $update->{$cpanid} = $auth_id; | |||||||||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||||||||||
| 171 | 0 | $insert->{$cpanid}++; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | 1 | ▶ | if (has_hash_data($dist_update)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | foreach my $distname (keys %{$dist_update}) { | |||||||||||||||||||||||||||
| 177 | 0 | my $cpanid = $dists->{$distname}->{cpanid}; | |||||||||||||||||||||||||||
| 178 | 0 | ▶ | if (my $auth_id = $auth_ids->{$cpanid}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 0 | $update->{$cpanid} = $auth_id; | |||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||
| 181 | 0 | $insert->{$cpanid}++; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | 1 | $self->{update} = $update; | |||||||||||||||||||||||||||
| 186 | 1 | $self->{insert} = $insert; | |||||||||||||||||||||||||||
| 187 | 1 | return 1; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | package CPAN::SQLite::State::dists; | ||||||||||||||||||||||||||||
| 191 | 7 | ▶ | use parent 'CPAN::SQLite::State'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 192 | 7 | ▶ | use CPAN::SQLite::Util qw(vcmp has_hash_data print_debug); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | sub new { | ||||||||||||||||||||||||||||
| 195 | 1 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||
| 196 | 1 | my $info = $args{info}; | |||||||||||||||||||||||||||
| 197 | 1 | ▶ | die "No dist info available" unless has_hash_data($info); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 1 | my $cdbi = $args{cdbi}; | |||||||||||||||||||||||||||
| 199 | 1 | ▶ | die "No dbi object available" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cdbi and ref $cdbi eq "CPAN::SQLite::DBI::Index::dists"
MC/DC0%0/2
$cdbi and ref $cdbi eq "CPAN::SQLite::DBI::Index::dists"
$cdbi
ref $cdbi eq "CPAN::SQLite::DBI::Index::dists"
Truth table33%1/3
A and B
A= $cdbiB= ref $cdbi eq "CPAN::SQLite::DBI::Index::dists"
| |||||||||||||||||||||||||||||
| 200 | unless ($cdbi and ref($cdbi) eq 'CPAN::SQLite::DBI::Index::dists'); | ||||||||||||||||||||||||||||
| 201 | 1 | my $self = { | |||||||||||||||||||||||||||
| 202 | info => $info, | ||||||||||||||||||||||||||||
| 203 | insert => {}, | ||||||||||||||||||||||||||||
| 204 | update => {}, | ||||||||||||||||||||||||||||
| 205 | delete => {}, | ||||||||||||||||||||||||||||
| 206 | ids => {}, | ||||||||||||||||||||||||||||
| 207 | versions => {}, | ||||||||||||||||||||||||||||
| 208 | obj => {}, | ||||||||||||||||||||||||||||
| 209 | cdbi => $cdbi, | ||||||||||||||||||||||||||||
| 210 | error_msg => '', | ||||||||||||||||||||||||||||
| 211 | info_msg => '', | ||||||||||||||||||||||||||||
| 212 | reindex => undef, | ||||||||||||||||||||||||||||
| 213 | }; | ||||||||||||||||||||||||||||
| 214 | 1 | return bless $self, $class; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | sub ids { | ||||||||||||||||||||||||||||
| 218 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
ids: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||
| 219 | 1 | my $cdbi = $self->{cdbi}; | |||||||||||||||||||||||||||
| 220 | 1 | ▶ | ($self->{ids}, $self->{versions}) = $cdbi->fetch_ids() or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | $self->{error_msg} = $cdbi->{error_msg}; | |||||||||||||||||||||||||||
| 222 | 0 | return; | |||||||||||||||||||||||||||
| 223 | }; | ||||||||||||||||||||||||||||
| 224 | 1 | return 1; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | sub state { | ||||||||||||||||||||||||||||
| 228 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
state: called CC=10 SCAR=32.0
| |||||||||||||||||||||||||||||
| 229 | 1 | my $dist_versions = $self->{versions}; | |||||||||||||||||||||||||||
| 230 | 1 | my $dists = $self->{info}; | |||||||||||||||||||||||||||
| 231 | 1 | my $dist_ids = $self->{ids}; | |||||||||||||||||||||||||||
| 232 | 1 | my ($insert, $update, $delete); | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 1 | my $reindex = $self->{reindex}; | |||||||||||||||||||||||||||
| 235 | 1 | ▶ | if (defined $reindex) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 0 | ▶ | my @dists = ref($reindex) eq 'ARRAY' ? @$reindex : ($reindex); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 0 | foreach my $distname (@dists) { | |||||||||||||||||||||||||||
| 238 | 0 | my $id = $dist_ids->{$distname}; | |||||||||||||||||||||||||||
| 239 | 0 | ▶ | if (not defined $id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 0 | print_debug(qq{"$distname" does not have an id: reindexing ignored\n}); | |||||||||||||||||||||||||||
| 241 | 0 | next; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | 0 | $update->{$distname} = $id; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | 0 | $self->{update} = $update; | |||||||||||||||||||||||||||
| 246 | 0 | return 1; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 1 | foreach my $distname (keys %$dists) { | |||||||||||||||||||||||||||
| 250 | 92 | ▶ | if (not defined $dist_versions->{$distname}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 251 | 0 | $insert->{$distname}++; | |||||||||||||||||||||||||||
| 252 | } elsif (vcmp($dists->{$distname}->{dist_vers}, $dist_versions->{$distname}) > 0) { | ||||||||||||||||||||||||||||
| 253 | 0 | $update->{$distname} = $dist_ids->{$distname}; | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | 1 | $self->{update} = $update; | |||||||||||||||||||||||||||
| 257 | 1 | $self->{insert} = $insert; | |||||||||||||||||||||||||||
| 258 | 1 | foreach my $distname (keys %$dist_versions) { | |||||||||||||||||||||||||||
| 259 | 92 | ▶ | next if $dists->{$distname}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 0 | $delete->{$distname} = $dist_ids->{$distname}; | |||||||||||||||||||||||||||
| 261 | 0 | print_debug("Will delete $distname\n"); | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | 1 | $self->{delete} = $delete; | |||||||||||||||||||||||||||
| 264 | 1 | return 1; | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | package CPAN::SQLite::State::mods; | ||||||||||||||||||||||||||||
| 268 | 7 | ▶ | use parent 'CPAN::SQLite::State'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 269 | 7 | ▶ | use CPAN::SQLite::Util qw(has_hash_data print_debug); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | sub new { | ||||||||||||||||||||||||||||
| 272 | 1 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||
| 273 | 1 | my $info = $args{info}; | |||||||||||||||||||||||||||
| 274 | 1 | ▶ | die "No module info available" unless has_hash_data($info); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 1 | my $cdbi = $args{cdbi}; | |||||||||||||||||||||||||||
| 276 | 1 | ▶ | die "No dbi object available" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cdbi and ref $cdbi eq "CPAN::SQLite::DBI::Index::mods"
MC/DC0%0/2
$cdbi and ref $cdbi eq "CPAN::SQLite::DBI::Index::mods"
$cdbi
ref $cdbi eq "CPAN::SQLite::DBI::Index::mods"
Truth table33%1/3
A and B
A= $cdbiB= ref $cdbi eq "CPAN::SQLite::DBI::Index::mods"
| |||||||||||||||||||||||||||||
| 277 | unless ($cdbi and ref($cdbi) eq 'CPAN::SQLite::DBI::Index::mods'); | ||||||||||||||||||||||||||||
| 278 | 1 | my $self = { | |||||||||||||||||||||||||||
| 279 | info => $info, | ||||||||||||||||||||||||||||
| 280 | insert => {}, | ||||||||||||||||||||||||||||
| 281 | update => {}, | ||||||||||||||||||||||||||||
| 282 | delete => {}, | ||||||||||||||||||||||||||||
| 283 | ids => {}, | ||||||||||||||||||||||||||||
| 284 | obj => {}, | ||||||||||||||||||||||||||||
| 285 | cdbi => $cdbi, | ||||||||||||||||||||||||||||
| 286 | error_msg => '', | ||||||||||||||||||||||||||||
| 287 | info_msg => '', | ||||||||||||||||||||||||||||
| 288 | }; | ||||||||||||||||||||||||||||
| 289 | 1 | return bless $self, $class; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | sub ids { | ||||||||||||||||||||||||||||
| 293 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
ids: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||
| 294 | 1 | my $cdbi = $self->{cdbi}; | |||||||||||||||||||||||||||
| 295 | 1 | ▶ | $self->{ids} = $cdbi->fetch_ids() or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 0 | $self->{error_msg} = $cdbi->{error_msg}; | |||||||||||||||||||||||||||
| 297 | 0 | return; | |||||||||||||||||||||||||||
| 298 | }; | ||||||||||||||||||||||||||||
| 299 | 1 | return 1; | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | sub state { | ||||||||||||||||||||||||||||
| 303 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
state: called CC=15 SCAR=45.8
| |||||||||||||||||||||||||||||
| 304 | 1 | my $mod_ids = $self->{ids}; | |||||||||||||||||||||||||||
| 305 | 1 | ▶ | return unless my $dist_obj = $self->{obj}->{dists}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | 1 | my $dists = $dist_obj->{info}; | |||||||||||||||||||||||||||
| 307 | 1 | my $dist_update = $dist_obj->{update}; | |||||||||||||||||||||||||||
| 308 | 1 | my $dist_insert = $dist_obj->{insert}; | |||||||||||||||||||||||||||
| 309 | 1 | my ($update, $insert, $delete); | |||||||||||||||||||||||||||
| 310 | 1 | my $cdbi = $self->{cdbi}; | |||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 1 | ▶ | if (has_hash_data($dist_insert)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 0 | foreach my $distname (keys %{$dist_insert}) { | |||||||||||||||||||||||||||
| 314 | 0 | foreach my $module (keys %{ $dists->{$distname}->{modules} }) { | |||||||||||||||||||||||||||
| 315 | 0 | $insert->{$module}++; | |||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | 1 | ▶ | if (has_hash_data($dist_update)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 320 | 0 | foreach my $distname (keys %{$dist_update}) { | |||||||||||||||||||||||||||
| 321 | 0 | foreach my $module (keys %{ $dists->{$distname}->{modules} }) { | |||||||||||||||||||||||||||
| 322 | 0 | my $mod_id = $mod_ids->{$module}; | |||||||||||||||||||||||||||
| 323 | 0 | ▶ | if ($mod_id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | 0 | $update->{$module} = $mod_id; | |||||||||||||||||||||||||||
| 325 | } else { | ||||||||||||||||||||||||||||
| 326 | 0 | $insert->{$module}++; | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 1 | ▶ | if (has_hash_data($dist_update)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 0 | my $sql = q{SELECT mod_id,mod_name from mods,dists WHERE dists.dist_id = mods.dist_id and dists.dist_id = ?}; | |||||||||||||||||||||||||||
| 334 | 0 | ▶ | my $sth = $dbh->prepare($sql) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | 0 | $cdbi->db_error(); | |||||||||||||||||||||||||||
| 336 | 0 | $self->{error_msg} = $cdbi->{error_msg}; | |||||||||||||||||||||||||||
| 337 | 0 | return; | |||||||||||||||||||||||||||
| 338 | }; | ||||||||||||||||||||||||||||
| 339 | 0 | my $dist_ids = $dist_obj->{ids}; | |||||||||||||||||||||||||||
| 340 | 0 | foreach my $distname (keys %{$dist_update}) { | |||||||||||||||||||||||||||
| 341 | 0 | my %mods = (); | |||||||||||||||||||||||||||
| 342 | 0 | %mods = map { $_ => 1 } keys %{ $dists->{$distname}->{modules} }; | |||||||||||||||||||||||||||
| 343 | 0 | ▶ | $sth->execute($dist_ids->{$distname}) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 0 | $cdbi->db_error($sth); | |||||||||||||||||||||||||||
| 345 | 0 | $self->{error_msg} = $cdbi->{error_msg}; | |||||||||||||||||||||||||||
| 346 | 0 | return; | |||||||||||||||||||||||||||
| 347 | }; | ||||||||||||||||||||||||||||
| 348 | 0 | ▶ | while (my ($mod_id, $mod_name) = $sth->fetchrow_array) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | 0 | ▶ | next if $mods{$mod_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 0 | $delete->{$mod_name} = $mod_id; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | 0 | $sth->finish; | |||||||||||||||||||||||||||
| 354 | 0 | undef $sth; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 1 | $self->{update} = $update; | |||||||||||||||||||||||||||
| 358 | 1 | $self->{insert} = $insert; | |||||||||||||||||||||||||||
| 359 | 1 | $self->{delete} = $delete; | |||||||||||||||||||||||||||
| 360 | 1 | return 1; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | package CPAN::SQLite::State::info; | ||||||||||||||||||||||||||||
| 364 | 7 | ▶ | use parent 'CPAN::SQLite::State'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 365 | 7 | ▶ | use CPAN::SQLite::Util qw(has_hash_data print_debug); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | sub new { | ||||||||||||||||||||||||||||
| 368 | 1 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 369 | 1 | my $cdbi = $args{cdbi}; | |||||||||||||||||||||||||||
| 370 | 1 | ▶ | die "No dbi object available" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cdbi and ref $cdbi eq "CPAN::SQLite::DBI::Index::info"
MC/DC0%0/2
$cdbi and ref $cdbi eq "CPAN::SQLite::DBI::Index::info"
$cdbi
ref $cdbi eq "CPAN::SQLite::DBI::Index::info"
Truth table33%1/3
A and B
A= $cdbiB= ref $cdbi eq "CPAN::SQLite::DBI::Index::info"
| |||||||||||||||||||||||||||||
| 371 | unless ($cdbi and ref($cdbi) eq 'CPAN::SQLite::DBI::Index::info'); | ||||||||||||||||||||||||||||
| 372 | 1 | my $self = { | |||||||||||||||||||||||||||
| 373 | info => '', | ||||||||||||||||||||||||||||
| 374 | insert => {}, | ||||||||||||||||||||||||||||
| 375 | update => {}, | ||||||||||||||||||||||||||||
| 376 | delete => {}, | ||||||||||||||||||||||||||||
| 377 | ids => {}, | ||||||||||||||||||||||||||||
| 378 | obj => {}, | ||||||||||||||||||||||||||||
| 379 | cdbi => $cdbi, | ||||||||||||||||||||||||||||
| 380 | error_msg => '', | ||||||||||||||||||||||||||||
| 381 | info_msg => '', | ||||||||||||||||||||||||||||
| 382 | }; | ||||||||||||||||||||||||||||
| 383 | 1 | return bless $self, $class; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | sub state { | ||||||||||||||||||||||||||||
| 387 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
state: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 1 | return 1; | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | package CPAN::SQLite::State; | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 7 | 1; | |||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | __END__ | ||||||||||||||||||||||||||||