DiaColloDB/EnumFile.pm

filter: Statementstmt 4.8% 14 / 290 Branchbran 0.0% 0 / 180 Conditioncond 0.0% 0 / 113 MC/DCmcdc 0.0% 0 / 68 Subroutinesub 11.4% 4 / 35 Podpod 96.4% 27 / 28 totaltotal 6.3% 45 / 714 CC 137 SCAR 50.5
CC
137
Cov
2%
s2i
506.0
flush
272.0
re2i
210.0
CRAP 156.2
« DiaColloDB/Upgrade/v0_12_sliceN.pm ↑ Summary DiaColloDB/Profile/Multi.pm »
1 ## -*- Mode: CPerl -*-
2 ## File: DiaColloDB::EnumFile.pm
3 ## Author: Bryan Jurish <moocow@cpan.org>
4 ## Description: collocation db, symbol<->integer enum
5  
6 package DiaColloDB::EnumFile;
7 1 ▶use DiaColloDB::Persistent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use DiaColloDB::Utils qw(:fcntl :file :pack :json :regex);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Fcntl qw(:DEFAULT :seek);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 ##==============================================================================
13 ## Globals & Constants
14  
15 1 our @ISA = qw(DiaColloDB::Persistent);
16  
17 ##==============================================================================
18 ## Constructors etc.
19  
20 ## $cldb = CLASS_OR_OBJECT->new(%args)
21 ## + %args, object structure:
22 ## (
23 ## base => $base, ##-- database basename; use files "${base}.es", "${base}.esx", "${base}.eix", "${base}.hdr"
24 ## perms => $perms, ##-- default: 0666 & ~umask
25 ## flags => $flags, ##-- default: 'r'
26 ## pack_i => $pack_i, ##-- integer pack template (default='N')
27 ## pack_o => $pack_o, ##-- file offset pack template (default='N')
28 ## pack_l => $pack_l, ##-- string-length pack template (default='n')
29 ## pack_s => $pack_s, ##-- string pack template (default=undef) for text i/o
30 ## size => $size, ##-- number of mapped symbols, like scalar(@i2s)
31 ## utf8 => $bool, ##-- true iff strings are stored as utf8 (default, used by re2i())
32 ## ##
33 ## ##-- in-memory construction and caching
34 ## s2i => \%s2i, ##-- maps symbols to integers
35 ## i2s => \@i2s, ##-- maps integers to symbols
36 ## dirty => $bool, ##-- true if in-memory structures are not in-sync with file data
37 ## loaded => $bool, ##-- true if file data has been loaded to memory
38 ## shared => $bool, ##-- true to avoid closing filehandles on close() or DESTROY() (default=false)
39 ## ##
40 ## ##-- pack lengths (after open())
41 ## len_i => $len_i, ##-- packsize($pack_i)
42 ## len_o => $len_o, ##-- packsize($pack_o)
43 ## len_l => $len_l, ##-- packsize($pack_l)
44 ## len_sx => $len_sx, ##-- $len_o + $len_i
45 ## ##
46 ## ##-- filehandles (after open())
47 ## sfh => $sfh, ##-- $base.es : pack("(${pack_l}/A)*", @$i2s)
48 ## ixfh => $ixfh, ##-- $base.eix : [$i] => pack("${pack_o}", $offset_in_sfh_of_string_with_id_i)
49 ## sxfh => $sxfh, ##-- $base.esx : [$j] => pack("${pack_o}${pack_i}", $offset_in_sfh_of_string_with_sortindex_j_and_id_i, $i)
50 ## )
51 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
52 0 my $that = shift;
53 0 ▶ my $enum = bless({
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
54 base => undef,
55 perms => (0666 & ~umask),
56 flags => 'r',
57 utf8 => 1,
58 size => 0,
59 pack_i => 'N',
60 pack_o => 'N',
61 pack_l => 'n',
62 pack_s => undef,
63  
64 s2i => {},
65 i2s => [],
66 dirty=>0,
67 loaded=>0,
68  
69 #len_i => undef,
70 #len_o => undef,
71 #len_l => undef,
72 #len_sx => undef,
73  
74 #sfh =>undef,
75 #ixfh =>undef,
76 #sxfh =>undef,
77  
78 @_, ##-- user arguments
79 },
80 ref($that)||$that);
81 0 $enum->{class} = ref($enum);
82 0 ▶ $enum->{s2i} //= {};
Condition0%0/2
$enum->{"s2i"} //= {}
l!l
00
MC/DC0%0/1
$enum->{"s2i"} //= {}
$enum->{"s2i"}
Truth table0%0/2
A
A= $enum->{"s2i"}
Aresult
11
00
83 0 ▶ $enum->{i2s} //= [];
Condition0%0/2
$enum->{"i2s"} //= []
l!l
00
MC/DC0%0/1
$enum->{"i2s"} //= []
$enum->{"i2s"}
Truth table0%0/2
A
A= $enum->{"i2s"}
Aresult
11
00
84 0 ▶ return defined($enum->{base}) ? $enum->open($enum->{base}) : $enum;
Branch: 1 branch
BranchTrueFalseTotal
defined $enum->{'base'} ? : 0 0 0
85 }
86  
87 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
88 0 ▶ $_[0]->close() if ($_[0]->opened);
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->opened 0 0 0
89 }
90  
91 ## $enum = $enum->promote($class,$force)
92 ## + promote to $class
93 ## + if $force is false (default), promotion to CLASS::MMap will be disabled
94 0 ▶sub promote {
Subroutine promote: not called CC=7 SCAR=40.3
Pod documented
95 0 my ($enum,$class,$force) = @_;
96 0 ▶ return $enum if (UNIVERSAL::isa($enum,$class)
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($enum, $class) or not $force and UNIVERSAL::isa((ref $enum || $enum) . '::MMap', $class) 0 0 0
Condition0%0/9
UNIVERSAL::isa($enum, $class) or not $force and UNIVERSAL::isa((ref $enum || $enum) . '::MMap', $class)
l!l&&r!l&&!r
000
not $force and UNIVERSAL::isa((ref $enum || $enum) . '::MMap', $class)
!ll&&!rl&&r
000
ref $enum || $enum
l!l&&r!l&&!r
000
MC/DC0%0/3
UNIVERSAL::isa($enum, $class) or not $force and UNIVERSAL::isa((ref $enum || $enum) . '::MMap', $class)
UNIVERSAL::isa($enum, $class) not $force UNIVERSAL::isa((ref $enum || $enum) . '::MMap', $class)
MC/DC0%0/2
ref $enum || $enum
ref $enum $enum
Truth table0%0/4
A or not(B) and C
A= UNIVERSAL::isa($enum, $class)B= not $forceC= UNIVERSAL::isa((ref $enum || $enum) . '::MMap', $class)
ABCresult
1XX1
0111
00X0
0100
Truth table0%0/3
A || B
A= ref $enumB= $enum
ABresult
1X1
011
000
97 || (!$force && UNIVERSAL::isa((ref($enum)||$enum)."::MMap", $class)));
98 0 ▶ return $class->new() if (!ref($enum));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $enum 0 0 0
99 0 ▶ %$enum = ((UNIVERSAL::can($class,'new') ? %{$class->new} : qw()),%$enum);
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can($class, 'new') ? : 0 0 0
100 0 return bless($enum,$class);
101 }
102  
103 ##==============================================================================
104 ## I/O
105  
106 ##--------------------------------------------------------------
107 ## I/O: open/close (file)
108  
109 ## $enum_or_undef = $enum->open($base,$flags)
110 ## $enum_or_undef = $enum->open($base)
111 ## $enum_or_undef = $enum->open()
112 ## + opens file(s), clears {loaded} flag
113 0 ▶sub open {
Subroutine open: not called CC=13 SCAR=52.0
Pod documented
114 0 my ($enum,$base,$flags) = @_;
115 0 ▶ $base //= $enum->{base};
Condition0%0/3
$base //= $enum->{"base"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$base //= $enum->{"base"}
$base $enum->{"base"}
Truth table0%0/3
A //= B
A= $baseB= $enum->{"base"}
ABresult
1X1
011
000
116 0 ▶ $flags //= $enum->{flags};
Condition0%0/3
$flags //= $enum->{"flags"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$flags //= $enum->{"flags"}
$flags $enum->{"flags"}
Truth table0%0/3
A //= B
A= $flagsB= $enum->{"flags"}
ABresult
1X1
011
000
117 0 ▶ $enum->close() if ($enum->opened);
Branch: 1 branch
BranchTrueFalseTotal
if $enum->opened 0 0 0
118 0 $enum->{base} = $base;
119 0 $enum->{flags} = $flags = fcflags($flags);
120 0 ▶ if (fcread($flags) && !fctrunc($flags)) {
Branch: 1 branch
BranchTrueFalseTotal
if (fcread($flags) and not fctrunc($flags)) 0 0 0
Condition0%0/3
fcread($flags) and not fctrunc($flags)
!ll&&!rl&&r
000
MC/DC0%0/2
fcread($flags) and not fctrunc($flags)
fcread($flags) not fctrunc($flags)
Truth table0%0/3
A and not(B)
A= fcread($flags)B= not fctrunc($flags)
ABresult
0X0
100
111
121 0 ▶ $enum->loadHeader()
Branch: 1 branch
BranchTrueFalseTotal
$enum->loadHeader or $enum->logconess(qq[failed to load header from '$enum->{"base"}.hdr': $!]) 0 0 0
122 or $enum->logconess("failed to load header from '$enum->{base}.hdr': $!");
123 return $enum->promote($enum->{hclass})->open($base,$flags)
124 0 ▶ if ($enum->{hclass} && !$enum->isa($enum->{hclass})); ##-- auto-promote based on header data
Branch: 1 branch
BranchTrueFalseTotal
if $enum->{"hclass"} and not $enum->isa($enum->{"hclass"}) 0 0 0
Condition0%0/3
$enum->{"hclass"} and not $enum->isa($enum->{"hclass"})
!ll&&!rl&&r
000
MC/DC0%0/2
$enum->{"hclass"} and not $enum->isa($enum->{"hclass"})
$enum->{"hclass"} not $enum->isa($enum->{"hclass"})
Truth table0%0/3
A and not(B)
A= $enum->{"hclass"}B= not $enum->isa($enum->{"hclass"})
ABresult
0X0
100
111
125 }
126  
127 $enum->{sfh} = fcopen("$base.es", $flags, $enum->{perms})
128 0 ▶ or $enum->logconfess("open failed for $base.es: $!");
Branch: 1 branch
BranchTrueFalseTotal
$enum->{"sfh"} = fcopen("$base.es", $flags, $enum->{"perms"}) or $enum->logconfess("open failed for $base.es: $!") 0 0 0
129 $enum->{ixfh} = fcopen("$base.eix", $flags, $enum->{perms})
130 0 ▶ or $enum->logconfess("open failed for $base.eix: $!");
Branch: 1 branch
BranchTrueFalseTotal
$enum->{"ixfh"} = fcopen("$base.eix", $flags, $enum->{"perms"}) or $enum->logconfess("open failed for $base.eix: $!") 0 0 0
131 $enum->{sxfh} = fcopen("$base.esx", $flags, $enum->{perms})
132 0 ▶ or $enum->logconfess("open failed for $base.esx: $!");
Branch: 1 branch
BranchTrueFalseTotal
$enum->{"sxfh"} = fcopen("$base.esx", $flags, $enum->{"perms"}) or $enum->logconfess("open failed for $base.esx: $!") 0 0 0
133 0 binmode($_,':raw') foreach (@$enum{qw(sfh ixfh sxfh)});
134  
135 ##-- pack lengths
136 #use bytes; ##-- deprecated in perl v5.18.2
137 0 $enum->{len_i} = packsize($enum->{pack_i});
138 0 $enum->{len_o} = packsize($enum->{pack_o});
139 0 $enum->{len_l} = packsize($enum->{pack_l});
140 0 $enum->{len_sx} = $enum->{len_o} + $enum->{len_i};
141  
142 ##-- flags
143 0 $enum->{loaded} = 0;
144  
145 0 return $enum;
146 }
147  
148 ## $enum_or_undef = $enum->close()
149 0 ▶sub close {
Subroutine close: not called CC=13 SCAR=52.0
Pod documented
150 0 my $enum = shift;
151 0 ▶ if ($enum->opened && fcwrite($enum->{flags})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enum->opened and fcwrite($enum->{"flags"})) 0 0 0
Condition0%0/3
$enum->opened and fcwrite($enum->{"flags"})
!ll&&!rl&&r
000
MC/DC0%0/2
$enum->opened and fcwrite($enum->{"flags"})
$enum->opened fcwrite($enum->{"flags"})
Truth table0%0/3
A and B
A= $enum->openedB= fcwrite($enum->{"flags"})
ABresult
0X0
100
111
152 0 ▶ $enum->flush() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$enum->flush or return undef 0 0 0
153 }
154 0 ▶ if (!$enum->{shared}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($enum->{"shared"}) 0 0 0
155 0 ▶ !defined($enum->{sxfh}) or $enum->{sxfh}->close() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
not defined $enum->{"sxfh"} or $enum->{"sxfh"}->close or return undef 0 0 0
Condition0%0/3
not defined $enum->{"sxfh"} or $enum->{"sxfh"}->close
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $enum->{"sxfh"} or $enum->{"sxfh"}->close
not defined $enum->{"sxfh"} $enum->{"sxfh"}->close
Truth table0%0/3
not(A) or B
A= not defined $enum->{"sxfh"}B= $enum->{"sxfh"}->close
ABresult
1X1
011
000
156 0 ▶ !defined($enum->{ixfh}) or $enum->{ixfh}->close() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
not defined $enum->{"ixfh"} or $enum->{"ixfh"}->close or return undef 0 0 0
Condition0%0/3
not defined $enum->{"ixfh"} or $enum->{"ixfh"}->close
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $enum->{"ixfh"} or $enum->{"ixfh"}->close
not defined $enum->{"ixfh"} $enum->{"ixfh"}->close
Truth table0%0/3
not(A) or B
A= not defined $enum->{"ixfh"}B= $enum->{"ixfh"}->close
ABresult
1X1
011
000
157 0 ▶ !defined($enum->{sfh}) or $enum->{sfh}->close() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
not defined $enum->{"sfh"} or $enum->{"sfh"}->close or return undef 0 0 0
Condition0%0/3
not defined $enum->{"sfh"} or $enum->{"sfh"}->close
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $enum->{"sfh"} or $enum->{"sfh"}->close
not defined $enum->{"sfh"} $enum->{"sfh"}->close
Truth table0%0/3
not(A) or B
A= not defined $enum->{"sfh"}B= $enum->{"sfh"}->close
ABresult
1X1
011
000
158 }
159 0 delete @$enum{qw(sxfh ixfh sfh)};
160 0 ▶ $enum->{s2i} //= {};
Condition0%0/2
$enum->{"s2i"} //= {}
l!l
00
MC/DC0%0/1
$enum->{"s2i"} //= {}
$enum->{"s2i"}
Truth table0%0/2
A
A= $enum->{"s2i"}
Aresult
11
00
161 0 ▶ $enum->{i2s} //= [];
Condition0%0/2
$enum->{"i2s"} //= []
l!l
00
MC/DC0%0/1
$enum->{"i2s"} //= []
$enum->{"i2s"}
Truth table0%0/2
A
A= $enum->{"i2s"}
Aresult
11
00
162 0 undef $enum->{base};
163 0 return $enum;
164 }
165  
166 ## $bool = $enum->opened()
167 0 ▶sub opened {
Subroutine opened: not called CC=3 SCAR=24.8
Pod documented
168 0 my $enum = shift;
169 return
170 (
171 #defined($enum->{base}) &&
172 defined($enum->{sfh})
173 && defined($enum->{ixfh})
174 && defined($enum->{sxfh})
175 0 ▶ );
Condition0%0/6
defined $enum->{'sfh'} && defined $enum->{'ixfh'} && defined $enum->{'sxfh'}
!ll&&!rl&&r
000
defined $enum->{"sfh"} and defined $enum->{"ixfh"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $enum->{'sfh'} && defined $enum->{'ixfh'} && defined $enum->{'sxfh'}
defined $enum->{"sfh"} defined $enum->{"ixfh"} defined $enum->{'sxfh'}
Truth table0%0/4
A and B && C
A= defined $enum->{"sfh"}B= defined $enum->{"ixfh"}C= defined $enum->{'sxfh'}
ABCresult
0XX0
10X0
1100
1111
176 }
177  
178 ## $bool = $enum->reopen()
179 ## + re-opens datafiles
180 0 ▶sub reopen {
Subroutine reopen: not called CC=5 SCAR=34.0
Pod undocumented
181 0 my $enum = shift;
182 0 ▶ my $base = $enum->{base} || "$enum";
Condition0%0/3
$enum->{'base'} || "$enum"
l!l&&r!l&&!r
000
MC/DC0%0/2
$enum->{'base'} || "$enum"
$enum->{'base'} "$enum"
Truth table0%0/3
A || B
A= $enum->{'base'}B= "$enum"
ABresult
1X1
011
000
183 return (
184 $enum->opened
185 && fh_reopen($enum->{sfh}, "$base.es")
186 && fh_reopen($enum->{ixfh}, "$base.eix")
187 0 ▶ && fh_reopen($enum->{sxfh}, "$base.esx")
Condition0%0/9
$enum->opened && fh_reopen($enum->{'sfh'}, "$base.es") && fh_reopen($enum->{'ixfh'}, "$base.eix") && fh_reopen($enum->{'sxfh'}, "$base.esx")
!ll&&!rl&&r
000
$enum->opened and fh_reopen($enum->{"sfh"}, "$base.es") and fh_reopen($enum->{"ixfh"}, "$base.eix")
!ll&&!rl&&r
000
$enum->opened and fh_reopen($enum->{"sfh"}, "$base.es")
!ll&&!rl&&r
000
MC/DC0%0/4
$enum->opened && fh_reopen($enum->{'sfh'}, "$base.es") && fh_reopen($enum->{'ixfh'}, "$base.eix") && fh_reopen($enum->{'sxfh'}, "$base.esx")
$enum->opened fh_reopen($enum->{"sfh"}, "$base.es") fh_reopen($enum->{"ixfh"}, "$base.eix") fh_reopen($enum->{'sxfh'}, "$base.esx")
Truth table0%0/5
A and B and C && D
A= $enum->openedB= fh_reopen($enum->{"sfh"}, "$base.es")C= fh_reopen($enum->{"ixfh"}, "$base.eix")D= fh_reopen($enum->{'sxfh'}, "$base.esx")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
188 );
189 }
190  
191 ## $bool = $enum->dirty()
192 ## + returns true iff some in-memory structures haven't been flushed to disk
193 0 ▶sub dirty {
Subroutine dirty: not called CC=1 SCAR=6.9
Pod documented
194 0 return $_[0]{dirty}; #@{$_[0]{i2s}} || %{$_[0]{s2i}};
195 }
196  
197 ## $bool = $enum->loaded()
198 ## + returns true iff in-memory structures have been populated from disk
199 0 ▶sub loaded {
Subroutine loaded: not called CC=1 SCAR=6.9
Pod documented
200 0 return $_[0]{loaded};
201 }
202  
203 ## $bool = $enum->rollback()
204 ## + drops in-memory structures
205 ## + invalidates any old references to {s2i}, {i2s} (but doesn't empty them if you need to keep a reference)
206 ## + clears {dirty} flag
207 0 ▶sub rollback {
Subroutine rollback: not called CC=1 SCAR=6.9
Pod documented
208 0 my $enum = shift;
209 0 $enum->{i2s} = [];
210 0 $enum->{s2i} = {};
211 0 $enum->{dirty} = 0;
212 0 return $enum;
213 }
214  
215 ## $bool = $enum->flush()
216 ## $bool = $enum->flush($force)
217 ## + flush in-memory structures to disk
218 ## + no-op unless $force or $enum->dirty() is true
219 ## + clobbers any old disk-file contents with in-memory maps
220 ## + enum must be opened in write-mode
221 ## + invalidates any old references to {s2i}, {i2s} (but doesn't empty them if you need to keep a reference)
222 ## + clears {dirty} flag
223 0 ▶sub flush {
Subroutine flush: not called CC=16 SCAR=56.1
Pod documented
224 0 my ($enum,$force) = @_;
225 0 ▶ return undef if (!$enum->opened || !fcwrite($enum->{flags}));
Branch: 1 branch
BranchTrueFalseTotal
unless $enum->opened and fcwrite($enum->{"flags"}) 0 0 0
Condition0%0/3
$enum->opened and fcwrite($enum->{"flags"})
!ll&&!rl&&r
000
MC/DC0%0/2
$enum->opened and fcwrite($enum->{"flags"})
$enum->opened fcwrite($enum->{"flags"})
Truth table0%0/3
A and B
A= $enum->openedB= fcwrite($enum->{"flags"})
ABresult
0X0
100
111
226 0 ▶ return $enum if (!$force && !$enum->dirty);
Branch: 1 branch
BranchTrueFalseTotal
unless $force or $enum->dirty 0 0 0
Condition0%0/3
$force or $enum->dirty
l!l&&r!l&&!r
000
MC/DC0%0/2
$force or $enum->dirty
$force $enum->dirty
Truth table0%0/3
A or B
A= $forceB= $enum->dirty
ABresult
1X1
011
000
227  
228 ##-- save header
229 0 ▶ $enum->saveHeader()
Branch: 1 branch
BranchTrueFalseTotal
$enum->saveHeader or $enum->logconfess(qq[flush(): failed to store header $enum->{"base"}.hdr: $!]) 0 0 0
230 or $enum->logconfess("flush(): failed to store header $enum->{base}.hdr: $!");
231  
232 #use bytes; ##-- deprecated in perl v5.18.2
233 0 my ($sfh,$ixfh,$sxfh) = @$enum{qw(sfh ixfh sxfh)};
234 0 $sfh->seek(0,SEEK_SET);
235 0 $ixfh->seek(0,SEEK_SET);
236 0 $sxfh->seek(0,SEEK_SET);
237  
238 ##-- dump $base.es, $base.eix
239 #no warnings 'uninitialized';
240 0 my $i2s = $enum->{i2s};
241 0 my $utf8 = $enum->{utf8};
242 0 my ($pack_o,$pack_l,$len_l) = @$enum{qw(pack_o pack_l len_l)};
243 0 my $i2off = []; ##-- >[$i] => $offset
244 0 my $off = 0;
245 0 my $i = 0;
246 0 my ($s);
247 0 foreach (@$i2s) {
248 0 ▶ $s = ($_ //= '');
Condition0%0/2
$_ //= ""
l!l
00
MC/DC0%0/1
$_ //= ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
249 0 ▶ utf8::encode($s) if ($utf8 && utf8::is_utf8($s));
Branch: 1 branch
BranchTrueFalseTotal
if $utf8 and utf8::is_utf8($s) 0 0 0
Condition0%0/3
$utf8 and utf8::is_utf8($s)
!ll&&!rl&&r
000
MC/DC0%0/2
$utf8 and utf8::is_utf8($s)
$utf8 utf8::is_utf8($s)
Truth table0%0/3
A and B
A= $utf8B= utf8::is_utf8($s)
ABresult
0X0
100
111
250 0 ▶ $sfh->print(pack("${pack_l}/A", $s))
Branch: 1 branch
BranchTrueFalseTotal
$sfh->print(pack("$pack_l/A", $s)) or $enum->logconfess(qq[flush(): failed to write string '${s}' at offset $off to $enum->{"base"}.es]) 0 0 0
251 or $enum->logconfess("flush(): failed to write string '$s' at offset $off to $enum->{base}.es");
252 0 ▶ $ixfh->print(pack($pack_o,$off))
Branch: 1 branch
BranchTrueFalseTotal
$ixfh->print(pack($pack_o, $off)) or $enum->logconfess(qq[flush(): failed to write ix-record for id=$i to $enum->{"base"}.eix]) 0 0 0
253 or $enum->logconfess("flush(): failed to write ix-record for id=$i to $enum->{base}.eix");
254 0 push(@$i2off, $off);
255 0 $off += $len_l + length($s);
256 0 ++$i;
257 }
258 0 CORE::truncate($sfh, $sfh->tell());
259 0 CORE::truncate($ixfh, $ixfh->tell());
260  
261 ##-- dump $base.esx
262 0 my $pack_sx = $enum->{pack_o}.$enum->{pack_i};
263 0 foreach $i (sort {$i2s->[$a] cmp $i2s->[$b]} (0..$#$i2s)) {
264 0 ▶ $sxfh->print(pack($pack_sx, $i2off->[$i], $i))
Branch: 1 branch
BranchTrueFalseTotal
$sxfh->print(pack($pack_sx, $i2off->[$i], $i)) or $enum->logconfess(qq[flush(): failed to dump sx-record for id $i to $enum->{"base"}.esx]) 0 0 0
265 or $enum->logconfess("flush(): failed to dump sx-record for id $i to $enum->{base}.esx");
266 }
267 0 CORE::truncate($sxfh, $sxfh->tell());
268  
269 ##-- clear in-memory structures (but don't clobber existing references; used for xenum by DiaColloDB::create())
270 0 $enum->rollback();
271 0 ▶ $enum->reopen() or return undef if ((caller(1))[3] !~ /::close$/);
Branch: 1 branch
BranchTrueFalseTotal
unless (caller 1)[3] =~ /::close$/ 0 0 0
Condition0%0/5
(caller 1)[3] =~ /::close$/ || ($enum->reopen || (return undef))
l!l&&r!l&&!r
000
$enum->reopen or return undef
l!l
00
MC/DC0%0/2
(caller 1)[3] =~ /::close$/ || ($enum->reopen || (return undef))
(caller 1)[3] =~ /::close$/ $enum->reopen
Truth table0%0/3
A || B
A= (caller 1)[3] =~ /::close$/B= $enum->reopen
ABresult
1X1
011
000
272 0 return $enum;
273 }
274  
275  
276 ##--------------------------------------------------------------
277 ## I/O: memory <-> file
278  
279 ## \@i2s = $enum->toArray()
280 ## + array items are still encoded
281 0 ▶sub toArray {
Subroutine toArray: not called CC=7 SCAR=40.3
Pod documented
282 0 my $enum = shift;
283 0 ▶ return $enum->{i2s} if ($enum->loaded || !$enum->opened);
Branch: 1 branch
BranchTrueFalseTotal
if $enum->loaded or not $enum->opened 0 0 0
Condition0%0/3
$enum->loaded or not $enum->opened
l!l&&r!l&&!r
000
MC/DC0%0/2
$enum->loaded or not $enum->opened
$enum->loaded not $enum->opened
Truth table0%0/3
A or not(B)
A= $enum->loadedB= not $enum->opened
ABresult
1X1
011
000
284 #use bytes; ##-- deprecated in perl v5.18.2
285 0 my $pack_l = $enum->{pack_l};
286 0 my $len_l = $enum->{len_l};
287 0 my $sfh = $enum->{sfh};
288 0 my @i2s = qw();
289 0 my ($buf,$len_s);
290 0 ▶ for (CORE::seek($sfh,0,SEEK_SET); !eof($sfh); ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $sfh) 0 0 0
291 0 ▶ CORE::read($sfh, $buf, $len_l)==$len_l
Branch: 1 branch
BranchTrueFalseTotal
read($sfh, $buf, $len_l) == $len_l or $enum->logconfess(qq[toArray(): read() failed on $enum->{"base"}.es for string length at offset ], tell $sfh) 0 0 0
292 or $enum->logconfess("toArray(): read() failed on $enum->{base}.es for string length at offset ", tell($sfh));
293 0 $len_s = unpack($pack_l, $buf);
294  
295 0 ▶ CORE::read($sfh, $buf, $len_s)==$len_s
Branch: 1 branch
BranchTrueFalseTotal
read($sfh, $buf, $len_s) == $len_s or $enum->logconfess(qq[toArray(): read() failed on $enum->{"base"}.es for string of length $len_s at offset ], tell $sfh) 0 0 0
296 or $enum->logconfess("toArray(): read() failed on $enum->{base}.es for string of length $len_s at offset ", tell($sfh));
297 0 push(@i2s, $buf);
298 }
299 0 ▶ push(@i2s, @{$enum->{i2s}}[scalar(@i2s)..$#{$enum->{i2s}}]) if ($enum->dirty);
Branch: 1 branch
BranchTrueFalseTotal
if $enum->dirty 0 0 0
300 0 return \@i2s;
301 }
302  
303 ## $enum = $enum->fromArray(\@i2s)
304 ## + clobbers $enum contents, steals \@i2s
305 0 ▶sub fromArray {
Subroutine fromArray: not called CC=3 SCAR=24.8
Pod documented
306 0 my ($enum,$i2s) = @_;
307 0 $enum->{i2s} = $i2s;
308 0 my $i = 0;
309 0 foreach (@$i2s) {
310 0 ▶ next if (!defined($_));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
311 0 $enum->{s2i}{$_} = $i++;
312 }
313 0 $enum->{size} = scalar(@{$enum->{i2s}});
314 0 $enum->{dirty} = 1;
315 0 return $enum;
316 }
317  
318 ## $enum = $enum->fromHash(\%s2i)
319 ## + clobbers $enum contents, steals \%s2i
320 0 ▶sub fromHash {
Subroutine fromHash: not called CC=1 SCAR=6.9
Pod documented
321 0 my ($enum,$s2i) = @_;
322 0 $enum->{s2i} = $s2i;
323 0 @{$enum->{i2s}}[values %$s2i] = keys %$s2i;
324 0 $enum->{size} = scalar(@{$enum->{i2s}});
325 0 $enum->{dirty} = 1;
326 0 return $enum;
327 }
328  
329  
330 ## $enum = $enum->fromEnum($enum2)
331 ## + clobbers $enum contents, does NOT steal $enum2->{i2s}
332 0 ▶sub fromEnum {
Subroutine fromEnum: not called CC=3 SCAR=24.8
Pod documented
333 0 my ($enum,$e2) = @_;
334 0 ▶ if ($e2->opened && !$e2->loaded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e2->opened and not $e2->loaded) { } 0 0 0
Condition0%0/3
$e2->opened and not $e2->loaded
!ll&&!rl&&r
000
MC/DC0%0/2
$e2->opened and not $e2->loaded
$e2->opened not $e2->loaded
Truth table0%0/3
A and not(B)
A= $e2->openedB= not $e2->loaded
ABresult
0X0
100
111
335 ##-- file->mem
336 0 return $enum->fromArray($e2->toArray);
337 } else {
338 ##-- mem->mem
339 0 @{$enum->{i2s}} = @{$e2->{i2s}};
340 0 %{$enum->{s2i}} = %{$e2->{s2i}};
341 0 $enum->{dirty} = 1;
342 }
343 0 return $enum;
344 }
345  
346 ## $bool = $enum->load()
347 ## + loads files to memory; must be opened
348 0 ▶sub load {
Subroutine load: not called CC=2 SCAR=17.9
Pod documented
349 0 my $enum = shift;
350 0 my $dirty = $enum->{dirty};
351 0 ▶ $enum->fromArray($enum->toArray) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$enum->fromArray($enum->toArray) or return undef 0 0 0
352 0 $enum->{loaded} = 1;
353 0 $enum->{dirty} = $dirty;
354 0 return $enum;
355 }
356  
357 ## $enum = $enum->save()
358 ## $enum = $enum->save($base)
359 ## + saves enum to $base; really just a wrapper for open() and flush()
360 0 ▶sub save {
Subroutine save: not called CC=4 SCAR=30.0
Pod documented
361 0 my ($enum,$base) = @_;
362 0 ▶ $enum->open($base,'rw') if (defined($base));
Branch: 1 branch
BranchTrueFalseTotal
if defined $base 0 0 0
363 0 ▶ $enum->logconfess("save(): cannot save un-opened enum") if (!$enum->opened);
Branch: 1 branch
BranchTrueFalseTotal
unless $enum->opened 0 0 0
364 0 ▶ $enum->flush() or $enum->logconfess("save(): failed to flush to $enum->{base}: $!");
Branch: 1 branch
BranchTrueFalseTotal
$enum->flush or $enum->logconfess(qq[save(): failed to flush to $enum->{"base"}: $!]) 0 0 0
365 0 return $enum;
366 }
367  
368  
369 ##--------------------------------------------------------------
370 ## I/O: header
371 ## + see also DiaColloDB::Persistent
372  
373 ## @keys = $coldb->headerKeys()
374 ## + keys to save as header
375 0 ▶sub headerKeys {
Subroutine headerKeys: not called CC=2 SCAR=17.9
Pod documented
376 0 ▶ return grep {!ref($_[0]{$_}) && $_ !~ m{^(?:flags|perms|base|loaded|dirty|hclass)$}} keys %{$_[0]};
Condition0%0/3
ref $_[0]{$_} || $_ =~ /^(?:flags|perms|base|loaded|dirty|hclass)$/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0]{$_} || $_ =~ /^(?:flags|perms|base|loaded|dirty|hclass)$/
ref $_[0]{$_} $_ =~ /^(?:flags|perms|base|loaded|dirty|hclass)$/
Truth table0%0/3
A || B
A= ref $_[0]{$_}B= $_ =~ /^(?:flags|perms|base|loaded|dirty|hclass)$/
ABresult
1X1
011
000
377 }
378  
379 ## $bool = $enum->loadHeaderData($hdr)
380 ## + instantiates header data from $hdr
381 ## + overrides DiaColloDB::Persistent implementation
382 0 ▶sub loadHeaderData {
Subroutine loadHeaderData: not called CC=4 SCAR=30.0
Pod documented
383 0 my ($enum,$hdr) = @_;
384 0 ▶ if (!defined($hdr) && !fccreat($enum->{flags})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $hdr || fccreat($enum->{'flags'})) { } 0 0 0
elsif (defined $hdr) { } 0 0 0
Condition0%0/3
defined $hdr || fccreat($enum->{'flags'})
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $hdr || fccreat($enum->{'flags'})
defined $hdr fccreat($enum->{'flags'})
Truth table0%0/3
A || B
A= defined $hdrB= fccreat($enum->{'flags'})
ABresult
1X1
011
000
385 0 $enum->logconfess("loadHeaderData() failed to load header data from ", $enum->headerFile, ": $!");
386 }
387 elsif (defined($hdr)) {
388 0 $enum->{hclass} = $hdr->{class}; ##-- save stored header-class
389 0 $enum->SUPER::loadHeaderData($hdr);
390 }
391 0 return $enum;
392 }
393  
394 ## $bool = $enum->saveHeader()
395 ## + inherited from DiaColloDB::Persistent
396  
397 ##--------------------------------------------------------------
398 ## I/O: text
399 ## + largely INHERITED from DiaColloDB::Persistent
400  
401 ## $bool = $obj->loadTextFile($filename_or_handle, %opts)
402 ## + wraps loadTextFh()
403 ## + INHERITED from DiaColloDB::Persistent
404  
405 ## $enum = $CLASS_OR_OBJECT->loadTextFh($fh)
406 ## $enum = $CLASS_OR_OBJECT->loadTextFh($fh, %opts)
407 ## + loads from text file with lines of the form "ID SYMBOL..."
408 ## + clobbers enum contents
409 ## + %opts locally clobber %$enum, especially:
410 ## pack_s => $pack_s
411 0 ▶sub loadTextFh {
Subroutine loadTextFh: not called CC=9 SCAR=45.0
Pod documented
412 0 my ($enum,$fh,%opts) = @_;
413 0 ▶ $enum = $enum->new(%opts) if (!ref($enum));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $enum 0 0 0
414 0 ▶ my $pack_s = exists($opts{pack_s}) ? $opts{pack_s} : $enum->{pack_s};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'pack_s'} ? : 0 0 0
415 0 ▶ my $packsub = $pack_s && !UNIVERSAL::isa($pack_s,'CODE') ? sub { pack($pack_s,split(/\t/,$_[0])) } : $pack_s;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$pack_s && !UNIVERSAL::isa($pack_s, 'CODE') ? : 0 0 0
Condition0%0/3
$pack_s and not UNIVERSAL::isa($pack_s, "CODE")
!ll&&!rl&&r
000
MC/DC0%0/2
$pack_s and not UNIVERSAL::isa($pack_s, "CODE")
$pack_s not UNIVERSAL::isa($pack_s, "CODE")
Truth table0%0/3
A and not(B)
A= $pack_sB= not UNIVERSAL::isa($pack_s, "CODE")
ABresult
0X0
100
111
416 0 my @i2s = qw();
417 0 my ($i,$s);
418 0 ▶ while (defined($_=<$fh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
419 0 chomp;
420 0 ▶ next if (/^%%/ || /^$/);
Branch: 1 branch
BranchTrueFalseTotal
if /^%%/ or /^$/ 0 0 0
Condition0%0/3
/^%%/ or /^$/
l!l&&r!l&&!r
000
MC/DC0%0/2
/^%%/ or /^$/
/^%%/ /^$/
Truth table0%0/3
A or B
A= /^%%/B= /^$/
ABresult
1X1
011
000
421 0 ($i,$s) = split(/\s/,$_,2);
422 0 ▶ $s = $packsub->($s) if ($packsub);
Branch: 1 branch
BranchTrueFalseTotal
if $packsub 0 0 0
423 0 $i2s[$i] = $s;
424 }
425  
426 ##-- clobber enum
427 0 return $enum->fromArray(\@i2s);
428 }
429  
430 ## $bool = $obj->saveTextFile($filename_or_fh, %opts)
431 ## + wraps saveTextFh()
432 ## + INHERITED from DiaColloDB::Persistent
433  
434 ## $bool = $enum->saveTextFh($fh,%opts)
435 ## + save from text file with lines of the form "ID SYMBOL..."
436 ## + %opts locally clobber %$enum, especially:
437 ## pack_s => $pack_s
438 0 ▶sub saveTextFh {
Subroutine saveTextFh: not called CC=7 SCAR=40.3
Pod documented
439 0 my ($enum,$fh,%opts) = @_;
440 0 ▶ my $pack_s = exists($opts{pack_s}) ? $opts{pack_s} : $enum->{pack_s};
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'pack_s'} ? : 0 0 0
441 0 ▶ my $packsub = $pack_s && !UNIVERSAL::isa($pack_s,'CODE') ? sub { join("\t", unpack($pack_s,$_[0])) } : $pack_s;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$pack_s && !UNIVERSAL::isa($pack_s, 'CODE') ? : 0 0 0
Condition0%0/3
$pack_s and not UNIVERSAL::isa($pack_s, "CODE")
!ll&&!rl&&r
000
MC/DC0%0/2
$pack_s and not UNIVERSAL::isa($pack_s, "CODE")
$pack_s not UNIVERSAL::isa($pack_s, "CODE")
Truth table0%0/3
A and not(B)
A= $pack_sB= not UNIVERSAL::isa($pack_s, "CODE")
ABresult
0X0
100
111
442 0 my $i2s = $enum->toArray;
443 0 my $i = 0;
444 0 foreach (@$i2s) {
445 0 ▶ if (defined($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 0 0 0
446 0 ▶ $fh->print($i, "\t", ($packsub ? $packsub->($_) : $_), "\n");
Branch: 1 branch
BranchTrueFalseTotal
$packsub ? : 0 0 0
447 }
448 0 ++$i;
449 }
450 0 return $enum;
451 }
452  
453  
454 ##==============================================================================
455 ## Methods: population (in-memory only)
456  
457 ## $size = $enum->size()
458 ## + wraps {size} key
459 0 ▶sub size { return $_[0]{size}; }
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
460  
461 ## $newsize = $enum->setsize($newsize)
462 ## + realy just wraps {size} key
463 0 ▶sub setsize { return $_[0]{size}=$_[1]; }
Subroutine setsize: not called CC=1 SCAR=6.9
Pod documented
464  
465 ## $newsize = $enum->addSymbols(@symbols)
466 ## $newsize = $enum->addSymbols(\@symbols)
467 ## + adds all symbols in @symbols which don't already exist
468 ## + enum must be loaded to memory
469 0 ▶sub addSymbols {
Subroutine addSymbols: not called CC=4 SCAR=30.0
Pod documented
470 0 my $enum = shift;
471 0 ▶ my $symbols = UNIVERSAL::isa($_[0],'ARRAY') ? $_[0] : \@_;
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], 'ARRAY') ? : 0 0 0
472 0 my $n = $enum->{size};
473 0 my $s2i = $enum->{s2i};
474 0 my $i2s = $enum->{i2s};
475 0 foreach (@$symbols) {
476 0 ▶ next if (exists $s2i->{$_});
Branch: 1 branch
BranchTrueFalseTotal
if exists $s2i->{$_} 0 0 0
477 0 $s2i->{$_} = $n;
478 0 $i2s->[$n] = $_;
479 0 ++$n;
480 }
481 0 $enum->{dirty} = 1;
482 0 return $enum->{size}=$n;
483 }
484  
485 ## $newsize = $enum->appendSymbols(@symbols)
486 ## $newsize = $enum->appendSymbols(\@symbols)
487 ## + adds all symbols in @symbols in order, messily re-mapping them if they already exist
488 0 ▶sub appendSymbols {
Subroutine appendSymbols: not called CC=3 SCAR=24.8
Pod documented
489 0 my $enum = shift;
490 0 ▶ my $symbols = UNIVERSAL::isa($_[0],'ARRAY') ? $_[0] : \@_;
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], 'ARRAY') ? : 0 0 0
491 0 my $n = $enum->{size};
492 0 my $s2i = $enum->{s2i};
493 0 my $i2s = $enum->{i2s};
494 0 foreach (@$symbols) {
495 0 $s2i->{$_} = $n;
496 0 $i2s->[$n] = $_;
497 0 ++$n;
498 }
499 0 $enum->{dirty} = 1;
500 0 return $enum->{size}=$n;
501 }
502  
503 ## $newsize = $enum->addEnum($enum2_or_undef)
504 ## + ensures all symbols from $enum2_or_undef are defined (undef:'')
505 0 ▶sub addEnum {
Subroutine addEnum: not called CC=2 SCAR=17.9
Pod documented
506 0 my ($e1,$e2) = @_;
507 0 ▶ return $e1->addSymbols(defined($e2) ? $e2->toArray : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $e2 ? : 0 0 0
508 }
509  
510 ##==============================================================================
511 ## Methods: lookup
512  
513 ## $s_or_undef = $enum->i2s($i)
514 ## + in-memory cache overrides file contents
515 0 ▶sub i2s {
Subroutine i2s: not called CC=9 SCAR=45.0
Pod documented
516 0 my ($enum,$i) = @_;
517 0 ▶ return undef if ($i >= $enum->{size});
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $enum->{"size"} 0 0 0
518 0 my ($buf,$soff,$slen);
519 0 ▶ return $buf if (defined($buf=$enum->{i2s}[$i]));
Branch: 1 branch
BranchTrueFalseTotal
if defined($buf = $enum->{"i2s"}[$i]) 0 0 0
520  
521 0 ▶ CORE::seek($enum->{ixfh}, $i*$enum->{len_o}, SEEK_SET)
Branch: 1 branch
BranchTrueFalseTotal
seek $enum->{"ixfh"}, $i * $enum->{"len_o"}, 0 or $enum->logconfess(qq[i2s(): seek() failed on $enum->{"base"}.eix for i=$i]) 0 0 0
522 or $enum->logconfess("i2s(): seek() failed on $enum->{base}.eix for i=$i");
523 CORE::read($enum->{ixfh},$buf,$enum->{len_o})==$enum->{len_o}
524 0 ▶ or $enum->logconfess("i2s(): read() failed on $enum->{base}.eix for i=$i");
Branch: 1 branch
BranchTrueFalseTotal
read($enum->{"ixfh"}, $buf, $enum->{"len_o"}) == $enum->{"len_o"} or $enum->logconfess(qq[i2s(): read() failed on $enum->{"base"}.eix for i=$i]) 0 0 0
525 0 $soff = unpack($enum->{pack_o},$buf);
526  
527 0 ▶ CORE::seek($enum->{sfh}, $soff, SEEK_SET)
Branch: 1 branch
BranchTrueFalseTotal
seek $enum->{"sfh"}, $soff, 0 or $enum->logconfess(qq[i2s(): seek() failed on $enum->{"base"}.es for offset $soff]) 0 0 0
528 or $enum->logconfess("i2s(): seek() failed on $enum->{base}.es for offset $soff");
529 CORE::read($enum->{sfh}, $buf,$enum->{len_l})==$enum->{len_l}
530 0 ▶ or $enum->logconfess("i2s(): read() failed on $enum->{base}.es for string length at offset $soff");
Branch: 1 branch
BranchTrueFalseTotal
read($enum->{"sfh"}, $buf, $enum->{"len_l"}) == $enum->{"len_l"} or $enum->logconfess(qq[i2s(): read() failed on $enum->{"base"}.es for string length at offset $soff]) 0 0 0
531 0 $slen = unpack($enum->{pack_l},$buf);
532  
533 0 ▶ CORE::read($enum->{sfh}, $buf, $slen)==$slen
Branch: 1 branch
BranchTrueFalseTotal
read($enum->{"sfh"}, $buf, $slen) == $slen or $enum->logconfess(qq[i2s(): read() failed on $enum->{"base"}.es for string of length $slen at offset $soff]) 0 0 0
534 or $enum->logconfess("i2s(): read() failed on $enum->{base}.es for string of length $slen at offset $soff");
535  
536 0 ▶ utf8::decode($buf) if ($enum->{utf8});
Branch: 1 branch
BranchTrueFalseTotal
if $enum->{"utf8"} 0 0 0
537 0 return $buf;
538 }
539  
540 ## $i_or_undef = $enum->s2i($s)
541 ## $i_or_undef = $enum->s2i($s, $ilo,$ihi)
542 ## + binary search; in-memory cache overrides file contents
543 0 ▶sub s2i {
Subroutine s2i: not called CC=22 SCAR=62.3
Pod documented
544 0 my ($enum,$key,$ilo,$ihi) = @_;
545  
546 0 my ($sxfh,$sfh,$len_sx,$pack_o,$len_o,$pack_l,$len_l) = @$enum{qw(sxfh sfh len_sx pack_o len_o pack_l len_l)};
547 0 ▶ $ilo //= 0;
Condition0%0/2
$ilo //= 0
l!l
00
MC/DC0%0/1
$ilo //= 0
$ilo
Truth table0%0/2
A
A= $ilo
Aresult
11
00
548 0 ▶ $ihi //= $enum->{dirty} ? ((-s $sxfh)/$len_sx) : $enum->{size};
Branch: 1 branch
BranchTrueFalseTotal
$enum->{'dirty'} ? : 0 0 0
Condition0%0/3
$ihi //= $enum->{"dirty"} ? (-s $sxfh) / $len_sx : $enum->{"size"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ihi //= $enum->{"dirty"} ? (-s $sxfh) / $len_sx : $enum->{"size"}
$ihi $enum->{"dirty"} ? (-s $sxfh) / $len_sx : $enum->{"size"}
Truth table0%0/3
A //= B
A= $ihiB= $enum->{"dirty"} ? (-s $sxfh) / $len_sx : $enum->{"size"}
ABresult
1X1
011
000
549  
550 0 my ($imid,$buf,$soff,$slen,$si);
551 0 ▶ return $buf if (defined($buf=$enum->{s2i}{$key}));
Branch: 1 branch
BranchTrueFalseTotal
if defined($buf = $enum->{"s2i"}{$key}) 0 0 0
552  
553 0 ▶ utf8::encode($key) if ($enum->{utf8} && utf8::is_utf8($key));
Branch: 1 branch
BranchTrueFalseTotal
if $enum->{"utf8"} and utf8::is_utf8($key) 0 0 0
Condition0%0/3
$enum->{"utf8"} and utf8::is_utf8($key)
!ll&&!rl&&r
000
MC/DC0%0/2
$enum->{"utf8"} and utf8::is_utf8($key)
$enum->{"utf8"} utf8::is_utf8($key)
Truth table0%0/3
A and B
A= $enum->{"utf8"}B= utf8::is_utf8($key)
ABresult
0X0
100
111
554 0 ▶ while ($ilo < $ihi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ilo < $ihi) 0 0 0
555 0 $imid = ($ihi+$ilo) >> 1;
556  
557 ##-- get sx-record @ $imid
558 0 ▶ CORE::seek($sxfh, $imid*$len_sx, SEEK_SET)
Branch: 1 branch
BranchTrueFalseTotal
seek $sxfh, $imid * $len_sx, 0 or $enum->logconfess(qq[s2i(): seek() failed on $enum->{"base"}.esx for item $imid]) 0 0 0
559 or $enum->logconfess("s2i(): seek() failed on $enum->{base}.esx for item $imid");
560 0 ▶ CORE::read($sxfh, $buf, $len_o)==$len_o
Branch: 1 branch
BranchTrueFalseTotal
read($sxfh, $buf, $len_o) == $len_o or $enum->logconfess(qq[s2i(): read() failed on $enum->{"base"}.esx for item $imid]) 0 0 0
561 or $enum->logconfess("s2i(): read() failed on $enum->{base}.esx for item $imid");
562 0 $soff = unpack($pack_o, $buf);
563  
564 ##-- get string for sx-record
565 0 ▶ CORE::seek($sfh, $soff, SEEK_SET)
Branch: 1 branch
BranchTrueFalseTotal
seek $sfh, $soff, 0 or $enum->logconfess(qq[s2i(): seek() failed on $enum->{"base"}.es for offset $soff]) 0 0 0
566 or $enum->logconfess("s2i(): seek() failed on $enum->{base}.es for offset $soff");
567 0 ▶ CORE::read($sfh, $buf, $len_l)==$len_l
Branch: 1 branch
BranchTrueFalseTotal
read($sfh, $buf, $len_l) == $len_l or $enum->logconfess(qq[s2i(): read() failed on $enum->{"base"}.es for string length at offset $soff]) 0 0 0
568 or $enum->logconfess("s2i(): read() failed on $enum->{base}.es for string length at offset $soff");
569 0 $slen = unpack($pack_l, $buf);
570 0 ▶ CORE::read($sfh, $buf, $slen)==$slen
Branch: 1 branch
BranchTrueFalseTotal
read($sfh, $buf, $slen) == $slen or $enum->logconfess(qq[s2i(): read() failed on $enum->{"base"}.es for string of length $slen at offset $soff]) 0 0 0
571 or $enum->logconfess("s2i(): read() failed on $enum->{base}.es for string of length $slen at offset $soff");
572  
573 0 ▶ if ($buf lt $key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf lt $key) { } 0 0 0
574 0 $ilo = $imid + 1;
575 } else {
576 0 $ihi = $imid;
577 }
578 }
579  
580 ##-- output
581 0 ▶ if ($ilo==$ihi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ilo == $ihi) 0 0 0
582 ##-- get sx-record @ $ilo
583 0 ▶ CORE::seek($sxfh, $ilo*$len_sx, SEEK_SET)
Branch: 1 branch
BranchTrueFalseTotal
seek $sxfh, $ilo * $len_sx, 0 or $enum->logconfess(qq[s2i(): seek() failed on $enum->{"base"}.esx for item $ilo]) 0 0 0
584 or $enum->logconfess("s2i(): seek() failed on $enum->{base}.esx for item $ilo");
585 0 ▶ return undef if ($sxfh->eof);
Branch: 1 branch
BranchTrueFalseTotal
if $sxfh->eof 0 0 0
586 0 ▶ CORE::read($sxfh, $buf, $len_sx)==$len_sx
Branch: 1 branch
BranchTrueFalseTotal
read($sxfh, $buf, $len_sx) == $len_sx or $enum->logconfess(qq[s2i(): read() failed on $enum->{"base"}.esx for item $ilo]) 0 0 0
587 or $enum->logconfess("s2i(): read() failed on $enum->{base}.esx for item $ilo");
588 0 ($soff,$si) = unpack($enum->{pack_o}.$enum->{pack_i}, $buf);
589  
590 ##-- get string for sx-record
591 0 ▶ CORE::seek($sfh, $soff, SEEK_SET)
Branch: 1 branch
BranchTrueFalseTotal
seek $sfh, $soff, 0 or $enum->logconfess(qq[s2i(): seek() failed on $enum->{"base"}.es for offset $soff]) 0 0 0
592 or $enum->logconfess("s2i(): seek() failed on $enum->{base}.es for offset $soff");
593 0 ▶ CORE::read($sfh, $buf, $len_l)==$len_l
Branch: 1 branch
BranchTrueFalseTotal
read($sfh, $buf, $len_l) == $len_l or $enum->logconfess(qq[s2i(): read() failed on $enum->{"base"}.es for string length at offset $soff]) 0 0 0
594 or $enum->logconfess("s2i(): read() failed on $enum->{base}.es for string length at offset $soff");
595 0 $slen = unpack($pack_l, $buf);
596 0 ▶ CORE::read($sfh, $buf, $slen)==$slen
Branch: 1 branch
BranchTrueFalseTotal
read($sfh, $buf, $slen) == $slen or $enum->logconfess(qq[s2i(): read() failed on $enum->{"base"}.es for string of length $slen at offset $soff]) 0 0 0
597 or $enum->logconfess("s2i(): read() failed on $enum->{base}.es for string of length $slen at offset $soff");
598  
599 0 ▶ return $si if ($buf eq $key);
Branch: 1 branch
BranchTrueFalseTotal
if $buf eq $key 0 0 0
600 }
601  
602 0 return undef;
603 }
604  
605 ## \@is = $enum->re2i($regex)
606 ## + gets indices for all strings matching $regex
607 0 ▶sub re2i {
Subroutine re2i: not called CC=14 SCAR=53.5
Pod documented
608 0 my ($enum,$re) = @_;
609 0 my $utf8 = $enum->{utf8};
610  
611 0 ▶ if (!ref($re)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $re) 0 0 0
612 0 ▶ utf8::decode($re) if ($utf8 && !utf8::is_utf8($re));
Branch: 1 branch
BranchTrueFalseTotal
if $utf8 and not utf8::is_utf8($re) 0 0 0
Condition0%0/3
$utf8 and not utf8::is_utf8($re)
!ll&&!rl&&r
000
MC/DC0%0/2
$utf8 and not utf8::is_utf8($re)
$utf8 not utf8::is_utf8($re)
Truth table0%0/3
A and not(B)
A= $utf8B= not utf8::is_utf8($re)
ABresult
0X0
100
111
613 0 $re = regex($re);
614 }
615  
616 0 my $i2s = $enum->{i2s};
617 0 ▶ if ($enum->loaded || !$enum->opened) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enum->loaded or not $enum->opened) 0 0 0
Condition0%0/3
$enum->loaded or not $enum->opened
l!l&&r!l&&!r
000
MC/DC0%0/2
$enum->loaded or not $enum->opened
$enum->loaded not $enum->opened
Truth table0%0/3
A or not(B)
A= $enum->loadedB= not $enum->opened
ABresult
1X1
011
000
618 ##-- easy answer: loaded
619 0 ▶ return [grep {utf8::decode($_) if ($utf8); $i2s->[$_] =~ $re} (0..$#$i2s)];
Branch: 1 branch
BranchTrueFalseTotal
if $utf8 0 0 0
620 }
621  
622 ##-- iteration a la toArray
623 #use bytes; ##-- deprecated in perl v5.18.2
624 0 my $pack_l = $enum->{pack_l};
625 0 my $len_l = $enum->{len_l};
626 0 my $sfh = $enum->{sfh};
627 0 my @is = qw();
628 0 my $i = 0;
629 0 my ($buf,$len_s);
630 0 ▶ for ($i=0, CORE::seek($sfh,0,SEEK_SET); !eof($sfh); ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $sfh) 0 0 0
631 0 ▶ CORE::read($sfh, $buf, $len_l)==$len_l
Branch: 1 branch
BranchTrueFalseTotal
read($sfh, $buf, $len_l) == $len_l or $enum->logconfess(qq[re2i(): read() failed on $enum->{"base"}.es for string length at offset ], tell $sfh) 0 0 0
632 or $enum->logconfess("re2i(): read() failed on $enum->{base}.es for string length at offset ", tell($sfh));
633 0 $len_s = unpack($pack_l, $buf);
634  
635 0 ▶ CORE::read($sfh, $buf, $len_s)==$len_s
Branch: 1 branch
BranchTrueFalseTotal
read($sfh, $buf, $len_s) == $len_s or $enum->logconfess(qq[re2i(): read() failed on $enum->{"base"}.es for string of length $len_s at offset ], tell $sfh) 0 0 0
636 or $enum->logconfess("re2i(): read() failed on $enum->{base}.es for string of length $len_s at offset ", tell($sfh));
637  
638 0 ▶ utf8::decode($buf) if ($utf8);
Branch: 1 branch
BranchTrueFalseTotal
if $utf8 0 0 0
639 0 ▶ push(@is, $i) if ($buf =~ $re);
Branch: 1 branch
BranchTrueFalseTotal
if $buf =~ /$re/ 0 0 0
640 }
641  
642 0 ▶ push(@is, grep {utf8::decode($_) if ($utf8); $i2s->[$_] =~ $re} (((-s $enum->{ixfh})/$enum->{len_o})..$#{$enum->{i2s}})) if ($enum->dirty);
Branch: 2 branches
BranchTrueFalseTotal
if $enum->dirty 0 0 0
if $utf8 0 0 0
643 0 return \@is;
644 }
645  
646  
647 ##==============================================================================
648 ## Footer
649 1 1;
650  
651 __END__
« DiaColloDB/Upgrade/v0_12_sliceN.pm ↑ Summary DiaColloDB/Profile/Multi.pm »