DiaColloDB/Upgrade/v0_04_dlimits.pm

filter: Statementstmt 31.4% 11 / 35 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 37.5% 3 / 8 Podpod 100% 5 / 5 totaltotal 22.6% 19 / 84 CC 13 SCAR 45.5
CC
13
Cov
18%
upgrade
156.0
needed
6.0
toversion
2.0
CRAP 94.7
« DiaColloDB/PackedFile.pm ↑ Summary DiaColloDB/Corpus.pm »
1 ## -*- Mode: CPerl -*-
2 ##
3 ## File: DiaColloDB::Upgrade::v0_04_dlimits.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: DiaColloDB utilities: auto-magic upgrade: v0.04: date-limits @$coldb{qw(xdmin xdmax)}
6  
7 package DiaColloDB::Upgrade::v0_04_dlimits;
8 1 ▶use DiaColloDB::Upgrade::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DiaColloDB::Utils qw(:pack);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 our @ISA = qw(DiaColloDB::Upgrade::Base);
12  
13 ##==============================================================================
14 ## API
15  
16 ## $version = $up->toversion()
17 ## + returns default target version; default just returns $DiaColloDB::VERSION
18 0 ▶sub toversion {
Subroutine toversion: not called CC=1 SCAR=6.9
Pod documented
19 0 return '0.04.000';
20 }
21  
22 ## $bool = $up->needed()
23 ## + returns true iff local index in $dbdir needs upgrade
24 0 ▶sub needed {
Subroutine needed: not called CC=2 SCAR=17.9
Pod documented
25 0 my $up = shift;
26 0 ▶ return !defined($up->{hdr}{xdmin}) || !defined($up->{hdr}{xdmax});
Condition0%0/3
defined $up->{'hdr'}{'xdmin'} && defined $up->{'hdr'}{'xdmax'}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $up->{'hdr'}{'xdmin'} && defined $up->{'hdr'}{'xdmax'}
defined $up->{'hdr'}{'xdmin'} defined $up->{'hdr'}{'xdmax'}
Truth table0%0/3
A && B
A= defined $up->{'hdr'}{'xdmin'}B= defined $up->{'hdr'}{'xdmax'}
ABresult
0X0
100
111
27 }
28  
29 ## $bool = $up->upgrade()
30 ## + performs upgrade
31 0 ▶sub upgrade {
Subroutine upgrade: not called CC=12 SCAR=50.5
Pod documented
32 0 my $up = shift;
33  
34 ##-- backup
35 0 ▶ $up->backup() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$up->backup or return undef 0 0 0
36  
37 ##-- xdmin, xdmax: from xenum
38 0 my $dbdir = $up->{dbdir};
39 0 my $hdr = $up->dbheader;
40 0 ▶ my $xenum = $DiaColloDB::XECLASS->new(base=>"$dbdir/xenum")
Branch: 1 branch
BranchTrueFalseTotal
my $xenum = $DiaColloDB::XECLASS->new("base", "$dbdir/xenum") or $up->logconfess("failed to open (tuple+date) enum $dbdir/xenum.*: $!") 0 0 0
41 or $up->logconfess("failed to open (tuple+date) enum $dbdir/xenum.*: $!");
42 0 my $pack_xdate = '@'.(packsize($hdr->{pack_id}) * scalar(@{$hdr->{attrs}})).$hdr->{pack_date};
43 0 my ($dmin,$dmax) = (undef,undef);
44 0 my ($d);
45 0 foreach (@{$xenum->toArray}) {
46 0 ▶ next if (!$_ || !($d=unpack($pack_xdate,$_))); ##-- ignore null keys and dates
Branch: 1 branch
BranchTrueFalseTotal
unless $_ and $d = unpack($pack_xdate, $_) 0 0 0
Condition0%0/3
$_ and $d = unpack($pack_xdate, $_)
!ll&&!rl&&r
000
MC/DC0%0/2
$_ and $d = unpack($pack_xdate, $_)
$_ $d = unpack($pack_xdate, $_)
Truth table0%0/3
A and B
A= $_B= $d = unpack($pack_xdate, $_)
ABresult
0X0
100
111
47 0 ▶ $dmin = $d if (!defined($dmin) || $d < $dmin);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $dmin or $d < $dmin 0 0 0
Condition0%0/3
not defined $dmin or $d < $dmin
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $dmin or $d < $dmin
not defined $dmin $d < $dmin
Truth table0%0/3
not(A) or B
A= not defined $dminB= $d < $dmin
ABresult
1X1
011
000
48 0 ▶ $dmax = $d if (!defined($dmax) || $d > $dmax);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $dmax or $d > $dmax 0 0 0
Condition0%0/3
not defined $dmax or $d > $dmax
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $dmax or $d > $dmax
not defined $dmax $d > $dmax
Truth table0%0/3
not(A) or B
A= not defined $dmaxB= $d > $dmax
ABresult
1X1
011
000
49 }
50 0 ▶ $dmin //= 0;
Condition0%0/2
$dmin //= 0
l!l
00
MC/DC0%0/1
$dmin //= 0
$dmin
Truth table0%0/2
A
A= $dmin
Aresult
11
00
51 0 ▶ $dmax //= 0;
Condition0%0/2
$dmax //= 0
l!l
00
MC/DC0%0/1
$dmax //= 0
$dmax
Truth table0%0/2
A
A= $dmax
Aresult
11
00
52 0 $up->vlog('info', "extracted date-range \"xdmin\":$dmin, \"xdmax\":$dmax");
53  
54 ##-- update header
55 0 @$hdr{qw(xdmin xdmax)} = ($dmin,$dmax);
56 0 return $up->updateHeader();
57 }
58  
59 ##==============================================================================
60 ## Backups & Rollback
61  
62 ## @files = $up->revert_created()
63 ## + returns list of files created by this upgrade, for use with default rollback() implementation
64 0 ▶sub revert_created {
Subroutine revert_created: not called CC=1 SCAR=6.9
Pod documented
65 0 return qw();
66 }
67  
68 ## @files = $up->revert_updated()
69 ## + returns list of files updated by this upgrade, for use with default rollback() implementation
70 0 ▶sub revert_updated {
Subroutine revert_updated: not called CC=1 SCAR=6.9
Pod documented
71 0 return qw(header.json);
72 }
73  
74  
75 ##==============================================================================
76 ## Footer
77 1 1; ##-- be happy
« DiaColloDB/PackedFile.pm ↑ Summary DiaColloDB/Corpus.pm »