blib/script/sasbactrl

filter: Statementstmt 42.5% 258 / 606 Branchbran 25.8% 133 / 514 Conditioncond 16.9% 42 / 248 MC/DCmcdc 4.1% 6 / 144 Subroutinesub 84.2% 16 / 19 Podpod n/a totaltotal 29.7% 455 / 1531 SCAR 86.8
CC
134
Cov
32%
refreshOSD
1807.7
policy
702.0
tdist
156.0
CRAP 5867.1
« blib/lib/SeeAlso/Source/BeaconAggregator/Maintenance.pm ↑ Summary blib/lib/SeeAlso/Source/BeaconAggregator.pm »
1 #!/usr/local/bin/perl -w
2 # $Id: $
3 27 ▶use lib "./lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 27 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 27 ▶use HTTP::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 27 ▶use SeeAlso::Identifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 27 ▶use SeeAlso::Source::BeaconAggregator::Maintenance;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 27 our $VERSION = '0.2_90';
15  
16 ##### Compatibility
17 27 ▶use SeeAlso::Identifier::GND;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 27 ▶if ( $SeeAlso::Identifier::GND::VERSION eq "0.54" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SeeAlso::Identifier::GND::VERSION eq "0.54") 0 27 27
19 27 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 0 ▶ eval <<'XxX' or die "tweak failed: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval "#!!! Have to tweak internals of SeeAlso::Identifier::GND for successful operation !!!\n *SeeAlso::Identifier::GND::canonical = \\&SeeAlso::Identifier::GND::normalized;\n *SeeAlso::Identifier::GND::hash = \\&SeeAlso::Identifier::GND::indexed;\n#!!! !!!#\n" or die "tweak failed: $@" 0 0 0
21 #!!! Have to tweak internals of SeeAlso::Identifier::GND for successful operation !!!
22 *SeeAlso::Identifier::GND::canonical = \&SeeAlso::Identifier::GND::normalized;
23 *SeeAlso::Identifier::GND::hash = \&SeeAlso::Identifier::GND::indexed;
24 #!!! !!!#
25 XxX
26 }
27 #####
28  
29 27 my $verbose = 1;
30 27 my $ignore_header_errors = 0;
31 27 my $action = "list";
32 27 my $dbroot = "./beacondbs";
33 27 my ($dsn, $cache_size, @pragmas, @presets, @idfilters, $idfinish);
34 27 my ($distinct, $force, $keeposd, $quiet, $dbfile, $itype, $redirs);
35  
36 # Application constants
37 27 our $EXAMPLEGOAL = 100; # don't attempt to find examples with higher hit count
38  
39 27 our $RETRYWAIT = 213*60; # w/o #REVISIT hint: never attempt more often (3h33')
40 27 our $NOREVISITWAIT = 1344*60; # w/o #REVISIT hint: never revisit sooner (22h22')
41  
42 27 our $REVISITFORCE = 4*30*24*3600; # with #REVISIT hint: force revisit after (4m)
43 27 our $NOREVISITFORCE = 4*7*24*3600; # w/o #REVISIT hint: force revisit after (4w)
44  
45 =head1 NAME
46  
47 sasbactrl - command line interface to SeeAlso::Source::BeaconAggregator and
48 auxiliary classes
49  
50 =head1 SYNOPSIS
51  
52 sasbactrl [Options] [Action [Args ...]]
53  
54 Actions and Arguments:
55 init [--[no]redirs]
56 [--itype type] Set up Database for dsn (dbroot must exist)
57  
58 load alias [uri [file]]
59 update [pattern | seqno_or_alias [uri]]
60  
61 status [seqno/alias/pattern] parts of "list" and "headers"
62  
63 unload seqno/alias/pattern
64 purge seqno/alias/pattern
65 list [seqno/alias/pattern]
66  
67 headers [seqno/alias/pattern]
68 header seqno/alias/pattern [field=val ...]
69  
70 dumposd show OpenSearchDescription
71 refreshosd refresh (then show) OpenSearchDescription
72  
73 dumpmeta [cgi_base_url ...] show beacon header
74 beacon cgi_base_url [uAformatname]
75  
76 setmeta "field: val" ["field: val" ...]
77 loadmeta header_template_file load OSD and Beacon meta constants
78  
79 idststat [seqno/alias/pattern]
80 idcounts [identifier/pattern]
81 idlist [identifier/pattern]
82 incidence [identifier/pattern]
83  
84 admin [field[=value]] list/get/set admin properties:
85 DATA_VERSION
86 IDENTIFIER_CLASS
87  
88 deflate Apply VACUUM and REINDEX on SqLite Db
89  
90 version gives versions numbers of involved modules
91  
92 noop do nothing (e.g. if --pragma's do all the work)
93  
94 Options:
95 (--dbfile | --dsn )
96 --force
97 --keeposd
98 --verbose|--quiet
99 --itype
100 --dbroot ($dbroot)
101 --ignore-header-errors [for update and load]
102 --distinct [for idcounts and idstat]
103  
104 --whitelist RE for [update and load]
105 --blacklist RE for [update and load]
106  
107 --preset HEADER=value [for "beacon", repeatable]
108  
109 --pragma [SQLite pragma] (repeatable)
110 --cache_size [SQLite pragma value]
111 =cut
112  
113 =head1 OPTIONS
114  
115 =head2 Global options for (almost) all types of actions
116  
117 =over 8
118  
119 =item B<--dbfile> I<filename>
120  
121 Name of database file relative to C<dbroot>
122  
123 =item B<--dsn> I<basename>
124  
125 Database file will be the file I<basename-db> in folder I<basename>,
126 giving SQLite enough headroom for temporary files.
127 Relative to C<dbroot>.
128  
129  
130 =item B<--dbroot>
131  
132 Prefix for --dbfile or --dsn (relative paths only)
133  
134  
135 =item B<--force>
136  
137 Use with care.
138  
139 =item B<--verbose>
140  
141 Sometimes shows more.
142  
143 =item B<--quiet>
144  
145 Sometimes shows less.
146  
147 =item B<--itype>
148  
149 Identifier type (corresponding subclass of SeeAlso::Identifier must be installed)
150  
151 =item B<--redirs=[0|1]>
152  
153 Prepare additional redirection index
154  
155 =item --ignore-header-errors
156  
157 [for update and load]
158  
159 =item --distinct
160  
161 [for idcounts and idstat]
162  
163 =back
164  
165 =cut
166  
167 GetOptions (
168 'verbose+' => \$verbose,
169 'quiet+' => \$quiet,
170 'distinct' => \$distinct,
171 'force' => \$force,
172 'keeposd' => \$keeposd,
173 'ignore-header-errors' => \$ignore_header_errors,
174 'redirs!' => \$redirs,
175 'itype=s' => \$itype,
176 'dbfile=s' => \$dbfile,
177 'dbroot=s' => \$dbroot,
178 'cache_size=s' => \$cache_size,
179 'pragma=s' => \@pragmas,
180 'preset=s' => \@presets,
181 1 ▶ 'whitelist=s' => sub { push(@idfilters, "m\x0e$_[1]\x0e && return \@_;"); $idfinish = 'undef'; },
Subroutine __ANON__: called CC=1 SCAR=0.0
182 1 ▶ 'blacklist=s' => sub { push(@idfilters, "m\x0e$_[1]\x0e && return undef;"); $idfinish = '@_'; },
Subroutine __ANON__: called CC=1 SCAR=0.0
183 27 ▶ 'dsn=s' => \$dsn,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("verbose+", \$verbose, "quiet+", \$quiet, "distinct", \$distinct, "force", \$force, "keeposd", \$keeposd, "ignore-header-errors", \$ignore_header_errors, "redirs!", \$redirs, "itype=s", \$itype, "dbfile=s", \$dbfile, "dbroot=s", \$dbroot, "cache_size=s", \$cache_size, "pragma=s", \@pragmas, "preset=s", \@presets, "whitelist=s", sub { push @idfilters, "m\cN$_[1]\cN && return \@_;"; $idfinish = "undef"; } , "blacklist=s", sub { push @idfilters, "m\cN$_[1]\cN && return undef;"; $idfinish = "\@_"; } , "dsn=s", \$dsn) or pod2usage({"-message", "Invalid option encountered", "-exitval", 2}) 0 27 27
184 ) or pod2usage({-message => 'Invalid option encountered', -exitval => 2});
185  
186 27 ▶if ( @ARGV && $ARGV[0] !~ /^-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV and not $ARGV[0] =~ /^-/) 25 2 27
Condition66%2/3
@ARGV and not $ARGV[0] =~ /^-/
!ll&&!rl&&r
2025
MC/DC50%1/2
@ARGV and not $ARGV[0] =~ /^-/
@ARGV not $ARGV[0] =~ /^-/
Truth table66%2/3
A and not(B)
A= @ARGVB= not $ARGV[0] =~ /^-/
ABresult
0X0
100
111
187 25 $action = shift @ARGV;
188 25 $action =~ s/\s$//;
189 }
190  
191 27 ▶$verbose = 0 if $quiet;
Branch: 1 branch
BranchTrueFalseTotal
if $quiet 0 27 27
192 27 ▶$dbroot ||= "";
Condition50%1/2
$dbroot ||= ""
l!l
270
MC/DC0%0/1
$dbroot ||= ""
$dbroot
Truth table50%1/2
A
A= $dbroot
Aresult
11
00
193 27 ▶$dbfile ||= "";
Condition50%1/2
$dbfile ||= ""
l!l
027
MC/DC0%0/1
$dbfile ||= ""
$dbfile
Truth table50%1/2
A
A= $dbfile
Aresult
11
00
194 27 ▶$dsn ||= "";
Condition100%2/2
$dsn ||= ""
l!l
261
MC/DC100%1/1
$dsn ||= ""
$dsn
Truth table100%2/2
A
A= $dsn
Aresult
11
00
195  
196 27 my $filtersub;
197 27 ▶if ( @idfilters ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@idfilters) 2 25 27
198 2 $filtersub = eval "sub { local(\$_) = \@_; @idfilters ; return $idfinish;}";
199 }
200  
201 27 ▶local($|) = 1 if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 27 0 27
202  
203 27 ▶my %passopts = (
Branch: 5 branches
BranchTrueFalseTotal
$distinct ? : 2 25 27
$force ? : 4 23 27
$verbose ? : 27 0 27
$ignore_header_errors ? : 0 27 27
$filtersub ? : 2 25 27
204 ($distinct ? ( 'distinct' => $distinct) : ()),
205 ($force ? ( 'force' => $force) : ()),
206 ($verbose ? ( 'verbose' => $verbose) : ()),
207 ($ignore_header_errors ? ( 'ignore-header-errors' => $ignore_header_errors) : ()),
208 ($filtersub ? ( 'filter' => $filtersub) : ()),
209 );
210  
211  
212 27 ▶if ( $dsn ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dsn) 26 1 27
213 26 ▶ die "dbroot directory $dbroot does not exist" unless -d $dbroot;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dbroot 1 25 26
214 25 ▶ $dbroot .= "/" unless $dbroot =~ m!/$!;
Branch: 1 branch
BranchTrueFalseTotal
unless $dbroot =~ m[/$] 25 0 25
215 25 ▶ if ( -d $dbroot && ( ! -d "$dbroot$dsn" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dbroot and not -d "$dbroot$dsn") 0 25 25
Condition33%1/3
-d $dbroot and not -d "$dbroot$dsn"
!ll&&!rl&&r
0250
MC/DC0%0/2
-d $dbroot and not -d "$dbroot$dsn"
-d $dbroot not -d "$dbroot$dsn"
Truth table33%1/3
A and not(B)
A= -d $dbrootB= not -d "$dbroot$dsn"
ABresult
0X0
100
111
216 0 ▶ if ( $action eq "init" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'init') { } 0 0 0
217 0 print "Will create database ${dsn}-db in $dbroot$dsn";
218 0 ▶ mkdir "$dbroot$dsn" or die "failed creating database dir $dbroot$dsn";
Branch: 1 branch
BranchTrueFalseTotal
mkdir "$dbroot$dsn" or die "failed creating database dir $dbroot$dsn" 0 0 0
219 }
220 else {
221 0 die "no database initialised for dsn $dsn in $dbroot tree"};
222 }
223 }
224  
225 26 ▶$itype ||= "";
Condition50%1/2
$itype ||= ""
l!l
026
MC/DC0%0/1
$itype ||= ""
$itype
Truth table50%1/2
A
A= $itype
Aresult
11
00
226 26 my $iclass;
227 26 ▶if ( $itype ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itype) { } 0 26 26
228 0 my $package = "SeeAlso::Identifier::".$itype;
229 0 eval {
230 0 (my $pkgpath = $package) =~ s=::=/=g; # require needs path...
231 0 require "$pkgpath.pm";
232 0 import $package;
233 };
234 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
235 0 die "sorry: Identifier Class $package cannot be imported\n$@"};
236 0 $iclass = $package->new(); # don't test the outcome (blessed scalar!)
237 0 ▶ die "sorry: cannot setup instance for Identifier Class $package" unless defined $iclass;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $iclass 0 0 0
238 }
239 else {
240 # $iclass = SeeAlso::Identifier->new(); # don't set, let it auto-initialize
241 };
242  
243 26 ▶my $db = SeeAlso::Source::BeaconAggregator::Maintenance->new(
Branch: 4 branches
BranchTrueFalseTotal
my $db = "SeeAlso::Source::BeaconAggregator::Maintenance"->new("dbroot", $dbroot, $dbfile ? ("file", $dbfile) : (), $dsn ? ("dsn", $dsn) : (), ref $iclass ? ("identifierClass", $iclass) : (), "accept", {"VERSION", qr/0\.[12]|1.0/, "FORMAT", "^([GP]ND-)?B(?i:EACON)(\\s+[vV]?1.0)?\$"}, "verbose", $verbose) or die "could not open database $dsn / $dbfile" 1 25 26
$dbfile ? : 0 26 26
$dsn ? : 25 1 26
ref $iclass ? : 0 26 26
244 'dbroot' => $dbroot,
245 $dbfile ? ('file' => $dbfile) : (),
246 $dsn ? ('dsn' => $dsn) : (),
247 ref($iclass) ? ('identifierClass' => $iclass) : (),
248 'accept' => {
249 'VERSION' => qr'0\.[12]|1.0',
250 'FORMAT' => '^([GP]ND-)?B(?i:EACON)(\s+[vV]?1.0)?$'},
251 'verbose' => $verbose,
252 ) or die "could not open database $dsn / $dbfile";
253  
254 25 ▶$db->{dbh}->do("PRAGMA cache_size = $cache_size;") or die "could not set cache_size to $cache_size" if defined $cache_size;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cache_size 1 24 25
Condition60%3/5
defined $cache_size && ($db->{'dbh'}->do("PRAGMA cache_size = $cache_size;") || die("could not set cache_size to $cache_size"))
!ll&&!rl&&r
2410
$db->{"dbh"}->do("PRAGMA cache_size = $cache_size;") or die "could not set cache_size to $cache_size"
l!l
10
MC/DC0%0/2
defined $cache_size && ($db->{'dbh'}->do("PRAGMA cache_size = $cache_size;") || die("could not set cache_size to $cache_size"))
defined $cache_size $db->{"dbh"}->do("PRAGMA cache_size = $cache_size;")
Truth table33%1/3
A && B
A= defined $cache_sizeB= $db->{"dbh"}->do("PRAGMA cache_size = $cache_size;")
ABresult
0X0
100
111
255  
256 25 foreach my $pragma ( @pragmas ) {
257 9 $pragma =~ s/^(['"])(.+)\1$/$2/;
258 9 $pragma =~ s/\s*;\s*$//;
259 # print "execute 'PRAGMA $pragma;':\n" if $verbose;
260 9 ▶ my $prows = $db->{dbh}->selectall_arrayref("PRAGMA $pragma;") or warn "trouble executing 'PRAGMA $pragma;'";
Branch: 1 branch
BranchTrueFalseTotal
my $prows = $db->{"dbh"}->selectall_arrayref("PRAGMA $pragma;") or warn "trouble executing 'PRAGMA $pragma;'" 0 9 9
261 # my $i;
262 9 foreach my $rowref ( @$prows ) {
263 # warn "[".++$i."] - "."@$rowref\n";
264 6 print "@$rowref\n";
265 };
266 };
267  
268 =head2 Actions
269  
270 These are typically an interface to methods of SeeAlso::Source::BeaconAggregator::Maintenance
271 or of SeeAlso::Source::BeaconAggregator::Publisher
272  
273 =over 8
274  
275 =item C<init>
276  
277 Creates a database with the necessary tables
278  
279 =cut
280  
281 25 ▶if ( $action eq "init" ) {
Branch: 20 branches
BranchTrueFalseTotal
if ($action eq 'init') { } 0 25 25
elsif ($action eq 'list') { } 1 24 25
elsif ($action eq 'status') { } 0 24 24
elsif ($action eq 'headers') { } 0 24 24
elsif ($action eq 'header') { } 0 24 24
elsif ($action eq 'load') { } 1 23 24
elsif ($action eq 'update') { } 4 19 23
elsif ($action eq 'unload' or $action eq 'purge') { } 0 19 19
elsif ($action eq 'idstat') { } 2 17 19
elsif ($action eq 'idcounts') { } 2 15 17
elsif ($action eq 'idlist') { } 2 13 15
elsif ($action eq 'incidence') { } 1 12 13
elsif ($action eq 'dumpmeta' or $action eq 'beacon') { } 1 11 12
elsif ($action eq 'setmeta') { } 0 11 11
elsif ($action eq 'loadmeta') { } 0 11 11
elsif ($action eq 'dumposd' or $action eq 'refreshosd') { } 0 11 11
elsif ($action eq 'admin') { } 1 10 11
elsif ($action eq 'deflate') { } 0 10 10
elsif ($action eq 'version') { } 1 9 10
elsif ($action eq 'noop') { } 9 0 9
282 0 ▶ $db->init(
Branch: 2 branches
BranchTrueFalseTotal
$db->init(defined $redirs ? ("prepareRedirs", $redirs) : ()) or die "could not setup database structure" 0 0 0
defined $redirs ? : 0 0 0
283 ((defined $redirs) ? ( 'prepareRedirs' => $redirs) : ()),
284 ) or die("could not setup database structure")}
285  
286 =item C<list>
287  
288 Interface to the C<listCollections()> method.
289  
290 List all loaded beacon files with identifier counts.
291  
292 The optional parameter may specify a SQL-Pattern to restrict
293 the result.
294  
295 =cut
296  
297 elsif ( $action eq "list" ) {
298 1 my $seqno_or_alias = shift @ARGV;
299 1 ▶ while (my ($sq, $alias, $uri, $mtime, $counti, $countu) = $db->listCollections($seqno_or_alias)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $db->listCollections($seqno_or_alias)) 2 1 3
300 2 my $mt = lct($mtime);
301 2 ▶ $counti ||= 0;
Condition50%1/2
$counti ||= 0
l!l
20
MC/DC0%0/1
$counti ||= 0
$counti
Truth table50%1/2
A
A= $counti
Aresult
11
00
302 2 ▶ $countu ||= 0;
Condition50%1/2
$countu ||= 0
l!l
20
MC/DC0%0/1
$countu ||= 0
$countu
Truth table50%1/2
A
A= $countu
Aresult
11
00
303 2 ▶ my $count = ($counti == $countu) ? $countu : "$countu/$counti";
Branch: 1 branch
BranchTrueFalseTotal
$counti == $countu ? : 2 0 2
304 2 print "$sq\t$alias\t$mt\t($count)\n\t$uri\n";
305 };
306 }
307  
308 =item C<status>
309  
310 Prints the complete administrative fields and beacon fields and overview
311 of the revisit policy for the beacon source(s) given by the first argument.
312  
313 The first argument may be empty or a pattern to produce the information for
314 more than one source.
315  
316 =cut
317  
318 elsif ( $action eq "status" ) {
319 0 my $seqno_or_alias = shift @ARGV;
320 0 binmode(STDOUT, ":utf8");
321  
322 0 printf("Load status for %s (%s)\n", $dsn, lct($^T));
323  
324 0 ▶ while ( my ($hashref, $metaref) = $db->headers($seqno_or_alias) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $db->headers($seqno_or_alias)) 0 0 0
325 0 ▶ last unless defined $hashref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hashref 0 0 0
326 printf("\n#%u\t%s\t%s\t%s\t(%u/%u i/u)\n", $metaref->{_seqno},
327 $metaref->{_alias} || "",
328 $metaref->{_sort} || "",
329 $metaref->{_mtime} || "???",
330 0 ▶ $metaref->{_counti} || 0, $metaref->{_countu} || 0);
Condition0%0/10
$metaref->{'_alias'} || ''
l!l
00
$metaref->{'_sort'} || ''
l!l
00
$metaref->{'_mtime'} || '???'
l!l
00
$metaref->{'_counti'} || 0
l!l
00
$metaref->{'_countu'} || 0
l!l
00
MC/DC0%0/1
$metaref->{'_alias'} || ''
$metaref->{'_alias'}
MC/DC0%0/1
$metaref->{'_sort'} || ''
$metaref->{'_sort'}
MC/DC0%0/1
$metaref->{'_mtime'} || '???'
$metaref->{'_mtime'}
MC/DC0%0/1
$metaref->{'_counti'} || 0
$metaref->{'_counti'}
MC/DC0%0/1
$metaref->{'_countu'} || 0
$metaref->{'_countu'}
Truth table0%0/2
A
A= $metaref->{'_alias'}
Aresult
11
00
Truth table0%0/2
A
A= $metaref->{'_sort'}
Aresult
11
00
Truth table0%0/2
A
A= $metaref->{'_mtime'}
Aresult
11
00
Truth table0%0/2
A
A= $metaref->{'_counti'}
Aresult
11
00
Truth table0%0/2
A
A= $metaref->{'_countu'}
Aresult
11
00
331  
332 0 ▶ printf(" < \t%s\n", $hashref->{FEED}) if $hashref->{FEED};
Branch: 1 branch
BranchTrueFalseTotal
if $hashref->{"FEED"} 0 0 0
333 0 ▶ printf(" << \t%s\n", $metaref->{_uri} || "???") unless $hashref->{FEED} && $metaref->{_uri} && ($hashref->{FEED} eq $metaref->{_uri});
Branch: 1 branch
BranchTrueFalseTotal
unless $hashref->{"FEED"} and $metaref->{"_uri"} and $hashref->{"FEED"} eq $metaref->{"_uri"} 0 0 0
Condition0%0/8
$hashref->{"FEED"} and $metaref->{"_uri"} and $hashref->{"FEED"} eq $metaref->{"_uri"}
!ll&&!rl&&r
000
$hashref->{"FEED"} and $metaref->{"_uri"}
!ll&&!rl&&r
000
$metaref->{'_uri'} || '???'
l!l
00
MC/DC0%0/3
$hashref->{"FEED"} and $metaref->{"_uri"} and $hashref->{"FEED"} eq $metaref->{"_uri"}
$hashref->{"FEED"} $metaref->{"_uri"} $hashref->{"FEED"} eq $metaref->{"_uri"}
MC/DC0%0/1
$metaref->{'_uri'} || '???'
$metaref->{'_uri'}
Truth table0%0/4
A and B and C
A= $hashref->{"FEED"}B= $metaref->{"_uri"}C= $hashref->{"FEED"} eq $metaref->{"_uri"}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/2
A
A= $metaref->{'_uri'}
Aresult
11
00
334 0 ▶ printf(" <<< \t%s\n", $metaref->{_ruri} || "???") unless $metaref->{_uri} && $metaref->{_ruri} && ($metaref->{_uri} eq $metaref->{_ruri});
Branch: 1 branch
BranchTrueFalseTotal
unless $metaref->{"_uri"} and $metaref->{"_ruri"} and $metaref->{"_uri"} eq $metaref->{"_ruri"} 0 0 0
Condition0%0/8
$metaref->{"_uri"} and $metaref->{"_ruri"} and $metaref->{"_uri"} eq $metaref->{"_ruri"}
!ll&&!rl&&r
000
$metaref->{"_uri"} and $metaref->{"_ruri"}
!ll&&!rl&&r
000
$metaref->{'_ruri'} || '???'
l!l
00
MC/DC0%0/3
$metaref->{"_uri"} and $metaref->{"_ruri"} and $metaref->{"_uri"} eq $metaref->{"_ruri"}
$metaref->{"_uri"} $metaref->{"_ruri"} $metaref->{"_uri"} eq $metaref->{"_ruri"}
MC/DC0%0/1
$metaref->{'_ruri'} || '???'
$metaref->{'_ruri'}
Truth table0%0/4
A and B and C
A= $metaref->{"_uri"}B= $metaref->{"_ruri"}C= $metaref->{"_uri"} eq $metaref->{"_ruri"}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/2
A
A= $metaref->{'_ruri'}
Aresult
11
00
335 0 ▶ printf(" ! \t%s\n", $metaref->{_admin}) if $metaref->{_admin};
Branch: 1 branch
BranchTrueFalseTotal
if $metaref->{"_admin"} 0 0 0
336  
337 0 my @dates;
338 my %stamps;
339 0 ▶ if ( $stamps{"stime"} = HTTP::Date::str2time($hashref->{TIMESTAMP}, "GMT") || 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stamps{'stime'} = &HTTP::Date::str2time($hashref->{'TIMESTAMP'}, 'GMT') || 0) { } 0 0 0
Condition0%0/2
&HTTP::Date::str2time($hashref->{'TIMESTAMP'}, 'GMT') || 0
l!l
00
MC/DC0%0/1
&HTTP::Date::str2time($hashref->{'TIMESTAMP'}, 'GMT') || 0
&HTTP::Date::str2time($hashref->{'TIMESTAMP'}, 'GMT')
Truth table0%0/2
A
A= &HTTP::Date::str2time($hashref->{'TIMESTAMP'}, 'GMT')
Aresult
11
00
340 0 push(@dates, [2, "TIMESTAMP header", $stamps{"stime"}, ""])}
341 else {
342 0 push(@dates, [0, "[no TIMESTAMP header]", 0, ""])};
343  
344 0 ▶ if ( $stamps{"rtime"} = HTTP::Date::str2time($hashref->{REVISIT}, "GMT") || 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stamps{'rtime'} = &HTTP::Date::str2time($hashref->{'REVISIT'}, 'GMT') || 0) { } 0 0 0
Condition0%0/2
&HTTP::Date::str2time($hashref->{'REVISIT'}, 'GMT') || 0
l!l
00
MC/DC0%0/1
&HTTP::Date::str2time($hashref->{'REVISIT'}, 'GMT') || 0
&HTTP::Date::str2time($hashref->{'REVISIT'}, 'GMT')
Truth table0%0/2
A
A= &HTTP::Date::str2time($hashref->{'REVISIT'}, 'GMT')
Aresult
11
00
345 0 push(@dates, [2, "REVISIT header", $stamps{"rtime"}, ""])}
346 else {
347 0 push(@dates, [8, "[no REVISIT header]", 0, ""])};
348
349 0 ▶ $stamps{"mtime"} = HTTP::Date::str2time($metaref->{_mtime}, "GMT") || 0;
Condition0%0/2
&HTTP::Date::str2time($metaref->{'_mtime'}, 'GMT') || 0
l!l
00
MC/DC0%0/1
&HTTP::Date::str2time($metaref->{'_mtime'}, 'GMT') || 0
&HTTP::Date::str2time($metaref->{'_mtime'}, 'GMT')
Truth table0%0/2
A
A= &HTTP::Date::str2time($metaref->{'_mtime'}, 'GMT')
Aresult
11
00
350 0 push(@dates, [2, "Current copy modified", $stamps{"mtime"}, ""]);
351  
352 0 ▶ $stamps{"ftime"}= HTTP::Date::str2time($metaref->{_ftime}, "GMT") || 0;
Condition0%0/2
&HTTP::Date::str2time($metaref->{'_ftime'}, 'GMT') || 0
l!l
00
MC/DC0%0/1
&HTTP::Date::str2time($metaref->{'_ftime'}, 'GMT') || 0
&HTTP::Date::str2time($metaref->{'_ftime'}, 'GMT')
Truth table0%0/2
A
A= &HTTP::Date::str2time($metaref->{'_ftime'}, 'GMT')
Aresult
11
00
353 0 my $fstat = $metaref->{_fstat};
354 0 push(@dates, [2, "Current copy loaded", $stamps{"ftime"}, $fstat]);
355  
356 0 ▶ $stamps{"utime"} = HTTP::Date::str2time($metaref->{_utime}, "GMT") || 0;
Condition0%0/2
&HTTP::Date::str2time($metaref->{'_utime'}, 'GMT') || 0
l!l
00
MC/DC0%0/1
&HTTP::Date::str2time($metaref->{'_utime'}, 'GMT') || 0
&HTTP::Date::str2time($metaref->{'_utime'}, 'GMT')
Truth table0%0/2
A
A= &HTTP::Date::str2time($metaref->{'_utime'}, 'GMT')
Aresult
11
00
357 0 my $ustat = $metaref->{_ustat};
358 0 push(@dates, [2, "Last update attempt", $stamps{"utime"}, $ustat]);
359  
360 0 my($forced, $xtime, $statref) = policy(\%stamps);
361
362 0 ▶ my $xstime = $stamps{"mtime"} || $stamps{"stime"};
Condition0%0/3
$stamps{'mtime'} || $stamps{'stime'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$stamps{'mtime'} || $stamps{'stime'}
$stamps{'mtime'} $stamps{'stime'}
Truth table0%0/3
A || B
A= $stamps{'mtime'}B= $stamps{'stime'}
ABresult
1X1
011
000
363 0 printf(" - Age: %s %s %s\n", tdist($^T -$xstime));
364 0 foreach ( @$statref ) {
365 0 my ($stamp, undef, $message) = @$_;
366 0 ▶ my $sign = ($stamp < $^T) ? "+" : "-";
Branch: 1 branch
BranchTrueFalseTotal
$stamp < $^T ? : 0 0 0
367 0 ▶ $sign = "o" if ($sign eq "-") and ($message =~ /^\+/);
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "-" and $message =~ /^\+/ 0 0 0
Condition0%0/3
$sign eq "-" and $message =~ /^\+/
!ll&&!rl&&r
000
MC/DC0%0/2
$sign eq "-" and $message =~ /^\+/
$sign eq "-" $message =~ /^\+/
Truth table0%0/3
A and B
A= $sign eq "-"B= $message =~ /^\+/
ABresult
0X0
100
111
368 0 printf(" (%s) Reload condition: %s: %s %s\n", $sign, $message, tdist($stamp -$^T));
369 0 ▶ next if $stamp < $^T; # dont list past events
Branch: 1 branch
BranchTrueFalseTotal
if $stamp < $^T 0 0 0
370 0 ▶ next if $message =~ /^-/; # suppress REVISIT pleonasm
Branch: 1 branch
BranchTrueFalseTotal
if $message =~ /^-/ 0 0 0
371 0 $message =~ s/ policy.*$//;
372 0 $message =~ s/^\W//;
373 0 push(@dates, [2, $message, $stamp, ""]);
374 };
375  
376 0 ▶ if ( $forced > 0 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($forced > 0) { } 0 0 0
elsif ($xtime > $^T) { } 0 0 0
elsif ($forced) { } 0 0 0
377 0 push(@dates, [9, "[Reload forced]", 0, ""])}
378 elsif ( $xtime > $^T ) {
379 0 push(@dates, [9, "=> next revisit after", $xtime, ""])}
380 elsif ( $forced ) {
381 0 push(@dates, [9, "=> Ready for reload!", 0, ""])}
382 else {
383 0 push(@dates, [9, "=> Ready for revisit", 0, ""])};
384  
385 0 ▶ foreach my $lineref ( sort { $a->[0] <=> $b->[0]
Branch: 1 branch
BranchTrueFalseTotal
$main::a->[0] <=> $main::b->[0] or $main::a->[2] <=> $main::b->[2] or $main::a->[1] cmp $main::b->[1] 0 0 0
Condition0%0/3
$main::a->[0] <=> $main::b->[0] or $main::a->[2] <=> $main::b->[2]
l!l&&r!l&&!r
000
MC/DC0%0/2
$main::a->[0] <=> $main::b->[0] or $main::a->[2] <=> $main::b->[2]
$main::a->[0] <=> $main::b->[0] $main::a->[2] <=> $main::b->[2]
Truth table0%0/3
A or B
A= $main::a->[0] <=> $main::b->[0]B= $main::a->[2] <=> $main::b->[2]
ABresult
1X1
011
000
386 || $a->[2] <=> $b->[2]
387 || $a->[1] cmp $b->[1]
388 } @dates ) {
389 0 ▶ if ( my $stat = $lineref->[3] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stat = $lineref->[3]) { } 0 0 0
390 0 $stat =~ s/replaced/rpl/;
391 0 $stat =~ s/deleted/del/;
392 0 $stat =~ s/duplicate/dup/;
393 0 $stat =~ s/ignored/ign/;
394 0 $stat =~ s/invalid/inv/;
395 0 ▶ printf(" * %-24s %30s\t%s %s %s\n **\t[%s]\n", $lineref->[1], lct($lineref->[2]), ($lineref->[2] ? @{[tdist($lineref->[2] -$^T)]}[0..2] : ("", "", "")), $stat);
Branch: 1 branch
BranchTrueFalseTotal
$lineref->[2] ? : 0 0 0
396 }
397 else {
398 0 ▶ printf(" * %-24s %30s\t%s %s %s\n", $lineref->[1], lct($lineref->[2]), ($lineref->[2] ? tdist($lineref->[2] -$^T) : ("", "", "")));
Branch: 1 branch
BranchTrueFalseTotal
$lineref->[2] ? : 0 0 0
399 };
400 };
401 }
402 }
403  
404 =item C<headers>
405  
406 Interface to the C<headers()> method.
407  
408 Prints all OSD fields and then all beacon fields.
409  
410 The first argument is a sequence number, alias or pattern.
411  
412 See C<header> for restricting output to individual fields.
413  
414 =cut
415  
416 elsif ( $action eq "headers" ) {
417 0 my $seqno_or_alias = shift @ARGV;
418 0 binmode(STDOUT, ":utf8");
419  
420 0 ▶ while ( my ($hashref, $metaref) = $db->headers($seqno_or_alias) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $db->headers($seqno_or_alias)) 0 0 0
421 0 ▶ last unless defined $hashref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hashref 0 0 0
422 0 print "\n";
423 0 ▶ while (my ($key, $val) = each %$hashref ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$hashref) 0 0 0
424 0 ▶ next unless defined $val && $val && $val !~ /^\s+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and $val and not $val =~ /^\s+$/ 0 0 0
Condition0%0/6
defined $val and $val and not $val =~ /^\s+$/
!ll&&!rl&&r
000
defined $val and $val
!ll&&!rl&&r
000
MC/DC0%0/3
defined $val and $val and not $val =~ /^\s+$/
defined $val $val not $val =~ /^\s+$/
Truth table0%0/4
A and B and not(C)
A= defined $valB= $valC= not $val =~ /^\s+$/
ABCresult
0XX0
10X0
1100
1111
425 0 print "#$key: $val\n";
426 };
427 0 ▶ while (my ($key, $val) = each %$metaref ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$metaref) 0 0 0
428 ####### TEMP CODE _count #########
429 0 ▶ next if $key eq "_count";
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "_count" 0 0 0
430 0 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
431 0 print "$key - $val\n";
432 };
433 0 print "\n";
434 };
435 }
436  
437  
438 =item C<header>
439  
440 Interface to the C<headerfield()> method.
441  
442 The first parameter is a mandatory and specifies a sequence number,
443 alias or pattern (e.g. "C<%>") to operate on.
444  
445 Further arguments are of the form I<fieldname> or I<fieldname>=C<value>
446 (value may be empty):
447 For each of these arguments output a line consisting of the field name, " - "
448 and the list of all values encountered. Subsequently, if the assignment form of the
449 argument is given, the corresponding field is set to C<value> for all
450 sequences met.
451  
452 Otherwise (no list of field names or assignments is specified), output will be
453 a list of all I<alias> fields, roughly corresponding to C<headerfield "%" _alias>.
454  
455 See C<headers> for listing all fields defined for given sequences.
456  
457 =cut
458  
459 elsif ( $action eq "header" ) {
460 0 ▶ my $seqno_or_alias = shift @ARGV or die "Please specify alias or number";
Branch: 1 branch
BranchTrueFalseTotal
my $seqno_or_alias = shift @ARGV or die "Please specify alias or number" 0 0 0
461 0 ▶ if ( @ARGV ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) { } 0 0 0
462 0 my $did = 0;
463 0 ▶ while ( scalar @ARGV && (my $field = shift @ARGV) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ARGV and my $field = shift @ARGV) 0 0 0
Condition0%0/3
scalar @ARGV and my $field = shift @ARGV
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @ARGV and my $field = shift @ARGV
scalar @ARGV my $field = shift @ARGV
Truth table0%0/3
A and B
A= scalar @ARGVB= my $field = shift @ARGV
ABresult
0X0
100
111
464 0 my($key, $val) = split(/=/, $field, 2);
465 0 my($rows, @vals) = $db->headerfield($seqno_or_alias, $key, $val);
466 0 ▶ print "$key - @vals\n" if @vals && $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if @vals and $verbose 0 0 0
Condition0%0/3
@vals and $verbose
!ll&&!rl&&r
000
MC/DC0%0/2
@vals and $verbose
@vals $verbose
Truth table0%0/3
A and B
A= @valsB= $verbose
ABresult
0X0
100
111
467 0 ▶ $did ++ if (defined $val) && $rows && (defined $vals[0]) && ($val ne $vals[0]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $val and $rows and defined $vals[0] and $val ne $vals[0] 0 0 0
Condition0%0/9
defined $val and $rows and defined $vals[0] and $val ne $vals[0]
!ll&&!rl&&r
000
defined $val and $rows and defined $vals[0]
!ll&&!rl&&r
000
defined $val and $rows
!ll&&!rl&&r
000
MC/DC0%0/4
defined $val and $rows and defined $vals[0] and $val ne $vals[0]
defined $val $rows defined $vals[0] $val ne $vals[0]
Truth table0%0/5
A and B and C and D
A= defined $valB= $rowsC= defined $vals[0]D= $val ne $vals[0]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
468 };
469 0 ▶ if ( $did ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($did) 0 0 0
470 0 print "Changed $did fields for $seqno_or_alias\n";
471 0 ▶ refreshOSD(0) unless $keeposd;
Branch: 1 branch
BranchTrueFalseTotal
unless $keeposd 0 0 0
472 };
473 }
474 else { # Simply dump a list of aliases
475 0 my($rows, @vals) = $db->headerfield($seqno_or_alias, "_alias");
476 0 print "@vals\n"
477 };
478 }
479  
480 =item C<load>
481  
482 load I<alias>, I<uri>, I<datafile>
483  
484 Interface to the C<loadFile()> or C<update()> methods
485  
486 Load beacon data from Uri (if I<uri> is given) or physical file
487 from disk (I<datafile> must be given).
488  
489 The beacon file will under the alias I<alias> be ready for
490 later updates.
491  
492  
493 =cut
494  
495 elsif ( $action eq "load" ) {
496 1 ▶ my $alias = shift @ARGV || "";
Condition50%1/2
shift @ARGV || ''
l!l
10
MC/DC0%0/1
shift @ARGV || ''
shift @ARGV
Truth table50%1/2
A
A= shift @ARGV
Aresult
11
00
497 1 ▶ my $uri = shift @ARGV || "";
Condition50%1/2
shift @ARGV || ''
l!l
10
MC/DC0%0/1
shift @ARGV || ''
shift @ARGV
Truth table50%1/2
A
A= shift @ARGV
Aresult
11
00
498 1 my ($cn, $cc);
499 1 ▶ if ( my $datafile = shift @ARGV ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $datafile = shift @ARGV) { } 1 0 1
elsif ($uri) { } 0 0 0
500 1 ($cn, $cc) = $db->loadFile($datafile, {_alias => $alias, _uri => $uri}, %passopts)}
501 elsif ( $uri ) {
502 0 ▶ ($cn, $cc) = $db->update($alias || $uri, {_uri => $uri}, %passopts)}
Condition0%0/3
$alias || $uri
l!l&&r!l&&!r
000
MC/DC0%0/2
$alias || $uri
$alias $uri
Truth table0%0/3
A || B
A= $aliasB= $uri
ABresult
1X1
011
000
503 else {
504 0 die ("Please specify an uri and optionally a beacon data file")};
505 1 ▶ die "Load failed\n" unless $cn;
Branch: 1 branch
BranchTrueFalseTotal
unless $cn 0 1 1
506 1 print "Collection Number $cn ($cc records)\n";
507 1 ▶ refreshOSD($force) unless $keeposd;
Branch: 1 branch
BranchTrueFalseTotal
unless $keeposd 1 0 1
508 }
509  
510 =item C<update>
511  
512 Interface to the C<update()> method
513  
514 (Re)load beacon files with known URIs according
515 to the following policy: Respect the #REVISIT hint, assume a #REVISIT
516 period of 24h for beacon files without. Wait at least 5% of the file's
517 age (difference between last updateate attempt and modification time)
518 before trying again. Wait at least 4h anyway. However force reload
519 after a couple of months.
520  
521 The C<update> method itself detects illegal headers and if the
522 beacon file was modified at all and may skip loading the file.
523 Use the C<--force> option to override the test on modification time
524 or clear the C<_mtime> field.
525  
526 When called with no arguments, update B<all> beacon files.
527  
528 =cut
529  
530 elsif ( $action eq "update" ) {
531 4 my $seqno_or_alias = shift @ARGV;
532 4 my $did;
533 4 ▶ if ( $seqno_or_alias ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seqno_or_alias) { } 4 0 4
534 4 ▶ my $uri = shift @ARGV || "";
Condition100%2/2
shift @ARGV || ''
l!l
13
MC/DC100%1/1
shift @ARGV || ''
shift @ARGV
Truth table100%2/2
A
A= shift @ARGV
Aresult
11
00
535 4 ▶ if ( $uri ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri) { } 1 3 4
536 1 ▶ die "no wildcards allowed in seqno_or_alias when uri is provided: $seqno_or_alias" if $seqno_or_alias =~ /%/;
Branch: 1 branch
BranchTrueFalseTotal
if $seqno_or_alias =~ /%/ 0 1 1
537 1 ▶ print "\n==> $seqno_or_alias ($uri) <==\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 1 0 1
538 1 my ($cn, $cc) = $db->update($seqno_or_alias, {_uri => $uri}, %passopts);
539 1 ▶ if ( $cn ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cn) 1 0 1
540 1 $did ++;
541 1 ▶ print "Collection Number $cn ($cc records)\n" if $cn;
Branch: 1 branch
BranchTrueFalseTotal
if $cn 1 0 1
542 }
543 }
544 else {
545 3 my $aliasref = $db->RepoCols("_alias", $seqno_or_alias);
546 3 ▶ foreach ( map {$_->[0]} sort {$a->[1] cmp $b->[1] || $a->[0] <=> $b->[0]} map{[$_, $aliasref->{$_} || ""]} keys %$aliasref ) {
Branch: 1 branch
BranchTrueFalseTotal
$main::a->[1] cmp $main::b->[1] or $main::a->[0] <=> $main::b->[0] 0 0 0
Condition50%1/2
$aliasref->{$_} || ''
l!l
30
MC/DC0%0/1
$aliasref->{$_} || ''
$aliasref->{$_}
Truth table50%1/2
A
A= $aliasref->{$_}
Aresult
11
00
547 3 my $item = $aliasref->{$_};
548 3 ▶ print "\n==> $item (auto) <==\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 3 0 3
549 3 my ($cn, $cc) = $db->update($item, {}, %passopts);
550 3 ▶ if ( $cn ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cn) 3 0 3
551 3 printf "%2u: %s successfully updated (new SeqNo %u, %u records)\n", ++$did, $aliasref->{$_}, $cn, $cc}
552 };
553 };
554 }
555 else {
556 0 my $aliasref = $db->RepoCols("_alias");
557 0 my $uriref = $db->RepoCols("_uri");
558 0 my ($revisitref, $updateref, $fetchedref, $modifiedref, $timestampref);
559  
560 0 ▶ $revisitref = $db->RepoCols("REVISIT") || 0;
Condition0%0/2
$db->RepoCols('REVISIT') || 0
l!l
00
MC/DC0%0/1
$db->RepoCols('REVISIT') || 0
$db->RepoCols('REVISIT')
Truth table0%0/2
A
A= $db->RepoCols('REVISIT')
Aresult
11
00
561 0 ▶ $updateref = $db->RepoCols("_utime") || 0;
Condition0%0/2
$db->RepoCols('_utime') || 0
l!l
00
MC/DC0%0/1
$db->RepoCols('_utime') || 0
$db->RepoCols('_utime')
Truth table0%0/2
A
A= $db->RepoCols('_utime')
Aresult
11
00
562 0 ▶ $fetchedref = $db->RepoCols("_ftime") || 0;
Condition0%0/2
$db->RepoCols('_ftime') || 0
l!l
00
MC/DC0%0/1
$db->RepoCols('_ftime') || 0
$db->RepoCols('_ftime')
Truth table0%0/2
A
A= $db->RepoCols('_ftime')
Aresult
11
00
563 0 ▶ $modifiedref = $db->RepoCols("_mtime") || 0;
Condition0%0/2
$db->RepoCols('_mtime') || 0
l!l
00
MC/DC0%0/1
$db->RepoCols('_mtime') || 0
$db->RepoCols('_mtime')
Truth table0%0/2
A
A= $db->RepoCols('_mtime')
Aresult
11
00
564 0 ▶ $timestampref = $db->RepoCols("TIMESTAMP") || 0;
Condition0%0/2
$db->RepoCols('TIMESTAMP') || 0
l!l
00
MC/DC0%0/1
$db->RepoCols('TIMESTAMP') || 0
$db->RepoCols('TIMESTAMP')
Truth table0%0/2
A
A= $db->RepoCols('TIMESTAMP')
Aresult
11
00
565  
566 0 foreach ( sort {$a <=> $b} keys %$aliasref ) {
567 0 my $linestart = "";
568 0 my $visible;
569 0 ▶ if ( $verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) { } 0 0 0
570 0 print "\n==> $aliasref->{$_} <==\n";
571 0 $visible = 1;
572 }
573 else {
574 0 $linestart =sprintf("%-10s - ", $aliasref->{$_})};
575 0 ▶ unless ( $uriref->{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($uriref->{$_}) 0 0 0
576 0 print $linestart."no uri known -> skipped\n";
577 0 next;
578 };
579 my %stamps = (
580 "stime" => $timestampref->{$_},
581 "mtime" => $modifiedref->{$_},
582 "ftime" => $fetchedref->{$_},
583 "utime" => $updateref->{$_},
584 0 "rtime" => $revisitref->{$_},
585 );
586 0 ▶ my $xstime = $stamps{"mtime"} || $stamps{"stime"}; # prefer "last modified" in favor of #TIMESTAMP
Condition0%0/3
$stamps{'mtime'} || $stamps{'stime'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$stamps{'mtime'} || $stamps{'stime'}
$stamps{'mtime'} $stamps{'stime'}
Truth table0%0/3
A || B
A= $stamps{'mtime'}B= $stamps{'stime'}
ABresult
1X1
011
000
587 0 my $age = join("", (tdist($^T -$xstime))[0,1]);
588  
589 0 my @states;
590 0 ▶ push(@states, sprintf("[%-26s %30s]\n", "Current Revisit hint", lct($stamps{"rtime"}))) if $stamps{"rtime"};
Branch: 1 branch
BranchTrueFalseTotal
if $stamps{"rtime"} 0 0 0
591 0 ▶ push(@states, sprintf("[%-26s %30s]\n", "Last action performed", lct($stamps{"utime"}))) if $stamps{"utime"};
Branch: 1 branch
BranchTrueFalseTotal
if $stamps{"utime"} 0 0 0
592 0 ▶ push(@states, sprintf("[%-26s %30s]\n", "Current copy loaded", lct($stamps{"ftime"}))) if $stamps{"ftime"};
Branch: 1 branch
BranchTrueFalseTotal
if $stamps{"ftime"} 0 0 0
593 0 ▶ push(@states, sprintf("[%-26s %30s]\n", "Current copy modified", lct($stamps{"mtime"}))) if $stamps{"mtime"};
Branch: 1 branch
BranchTrueFalseTotal
if $stamps{"mtime"} 0 0 0
594 0 ▶ push(@states, sprintf("[%-26s %30s]\n", "Current timestamp header", lct($stamps{"stime"}))) if $stamps{"stime"};
Branch: 1 branch
BranchTrueFalseTotal
if $stamps{"stime"} 0 0 0
595  
596 0 my $forcereload;
597 0 ▶ unless ( $force ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($force) 0 0 0
598 0 ▶ if ( $verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
599 0 print @states;
600 0 $visible = 1;
601 };
602  
603 0 my ($xtime, $statref);
604 0 ($forcereload, $xtime, $statref) = policy(\%stamps);
605 0 ▶ unless ( $forcereload ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($forcereload) 0 0 0
606 0 my($status, $info) = ("" x 2);
607 0 foreach ( @$statref ) {
608 0 my ($stamp, $code, $message) = @$_;
609 0 ▶ next if $stamp < $^T;
Branch: 1 branch
BranchTrueFalseTotal
if $stamp < $^T 0 0 0
610 0 ▶ next if $message =~ /^\+/;
Branch: 1 branch
BranchTrueFalseTotal
if $message =~ /^\+/ 0 0 0
611 0 $message =~ s/^\W//;
612 0 $message =~ s/ policy//;
613 0 ($status, $info) = ($code, $message);
614 0 ▶ if ( $verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
615 0 printf "[%4s] %-20s %30s -> skipped\n", $status, $info, lct($stamp);
616 0 $visible = 1;
617 }
618 };
619  
620 0 ▶ if ( $xtime > $^T ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xtime > $^T) 0 0 0
621 0 ▶ unless ( $verbose or ($quiet && $quiet > 1) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($verbose or $quiet and $quiet > 1) 0 0 0
Condition0%0/6
$verbose or $quiet and $quiet > 1
l!l&&r!l&&!r
000
$quiet and $quiet > 1
!ll&&!rl&&r
000
MC/DC0%0/3
$verbose or $quiet and $quiet > 1
$verbose $quiet $quiet > 1
Truth table0%0/4
A or B and C
A= $verboseB= $quietC= $quiet > 1
ABCresult
1XX1
0111
00X0
0100
622 0 printf ("%s[%4s] next %30s (age: %s, %s)\n", $linestart, $status, lct($xtime), $age, $info);
623 0 $visible = 1;
624 };
625 0 next;
626 };
627 }
628 };
629  
630 0 ▶ if ( !$verbose ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $verbose) { } 0 0 0
elsif ($force) { } 0 0 0
631 0 ▶ unless ( $quiet && $quiet > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($quiet and $quiet > 1) 0 0 0
Condition0%0/3
$quiet and $quiet > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$quiet and $quiet > 1
$quiet $quiet > 1
Truth table0%0/3
A and B
A= $quietB= $quiet > 1
ABresult
0X0
100
111
632 0 ▶ printf("%s[%4s] curr %30s (age: %s, %s)\n", $linestart, "LOAD", lct(($stamps{"stime"} && ($stamps{"stime"} < $stamps{"mtime"})) ? $stamps{"stime"} : $stamps{"mtime"}), $age, "will reload");
Branch: 1 branch
BranchTrueFalseTotal
$stamps{'stime'} && $stamps{'stime'} < $stamps{'mtime'} ? : 0 0 0
Condition0%0/3
$stamps{"stime"} and $stamps{"stime"} < $stamps{"mtime"}
!ll&&!rl&&r
000
MC/DC0%0/2
$stamps{"stime"} and $stamps{"stime"} < $stamps{"mtime"}
$stamps{"stime"} $stamps{"stime"} < $stamps{"mtime"}
Truth table0%0/3
A and B
A= $stamps{"stime"}B= $stamps{"stime"} < $stamps{"mtime"}
ABresult
0X0
100
111
633 0 $visible = 1;
634 }
635 }
636 elsif ( $force ) {
637 0 print @states;
638 0 $visible = 1;
639 };
640 0 ▶ my ($cn, $cc) = $db->update($aliasref->{$_}, {}, %passopts, ($forcereload ? ( 'force' => 1) : ()), 'nostat' => 1);
Branch: 1 branch
BranchTrueFalseTotal
$forcereload ? : 0 0 0
641 0 ▶ if ( $cn ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cn) 0 0 0
642 0 printf "%2u: %s successfully updated (new SeqNo %u, %u records)\n", ++$did, $aliasref->{$_}, $cn, $cc;
643 0 $visible = 1;
644 # refreshOSD(0) unless $keeposd; # will be done anyway since $did true now
645 };
646 0 ▶ print " ***\n" unless $visible;
Branch: 1 branch
BranchTrueFalseTotal
unless $visible 0 0 0
647 };
648 };
649 4 ▶ if ( $did or $force ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($did or $force) 4 0 4
Condition33%1/3
$did or $force
l!l&&r!l&&!r
400
MC/DC0%0/2
$did or $force
$did $force
Truth table33%1/3
A or B
A= $didB= $force
ABresult
1X1
011
000
650 4 ▶ refreshOSD( $force ? 1 : 0)};
Branch: 1 branch
BranchTrueFalseTotal
$force ? : 4 0 4
651 }
652  
653 =item C<purge>
654  
655 Interface to the <purge()> method.
656  
657 Clears all beacon data for the seqnos or aliases given by
658 the first argument: The beacon source with its metadata
659 remains known to the database.
660  
661 The argument may be a pattern, but the C<--force>
662 option is needed if actually more than one beacon file is
663 to be purged).
664  
665 OSD fields are rebuild if something was done or C<--force>
666 is given.
667  
668 =item C<unload>
669  
670 Interface to the <unload()> method.
671  
672 Clears all beacon data B<and> removes the listed headers
673 for the seqnos or aliases given by the first argument:
674 Any knowledge of the beacon source is effectively deleted
675 from the database.
676  
677 The argument may be a pattern, but the C<--force>
678 option is needed if actually more than one beacon file is
679 to be unloaded.
680  
681 OSD fields are rebuild if something was done or C<--force>
682 is given.
683  
684 =cut
685 ▶elsif ( ($action eq "unload") or ($action eq "purge") ) {
Condition33%1/3
$action eq "unload" or $action eq "purge"
l!l&&r!l&&!r
0019
MC/DC0%0/2
$action eq "unload" or $action eq "purge"
$action eq "unload" $action eq "purge"
Truth table33%1/3
A or B
A= $action eq "unload"B= $action eq "purge"
ABresult
1X1
011
000
686 0 ▶ my $seqno_or_alias = shift @ARGV or die "Please specify alias, pattern or SeqNo";
Branch: 1 branch
BranchTrueFalseTotal
my $seqno_or_alias = shift @ARGV or die "Please specify alias, pattern or SeqNo" 0 0 0
687 0 ▶ if ( $db->$action($seqno_or_alias, %passopts) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db->$action($seqno_or_alias, %passopts)) { } 0 0 0
688 0 ▶ refreshOSD(1) unless $keeposd}
Branch: 1 branch
BranchTrueFalseTotal
unless $keeposd 0 0 0
689 else {
690 0 warn "did not do anything\n";
691 0 ▶ refreshOSD($force) if $force and !$keeposd;
Branch: 1 branch
BranchTrueFalseTotal
if $force and not $keeposd 0 0 0
Condition0%0/3
$force and not $keeposd
!ll&&!rl&&r
000
MC/DC0%0/2
$force and not $keeposd
$force not $keeposd
Truth table0%0/3
A and not(B)
A= $forceB= not $keeposd
ABresult
0X0
100
111
692 };
693 }
694  
695 =item C<idstat>
696  
697 Interface to the C<idStat()> method.
698  
699 Counts indentifiers, optionally only from those beacon files with seqno or alias restricted by the first argument.
700  
701 Recognized options are C<distinct> and C<verbose>.
702  
703 =cut
704  
705 elsif ( $action eq "idstat" ) {
706 2 print $db->idStat($ARGV[0], %passopts)." identifiers\n";}
707  
708 =item C<idcounts>
709  
710 Interface to the C<idCounts()> method.
711  
712 Counts identifiers, optionally only these identifiers which
713 match the pattern given by the first argument.
714  
715 Recognized options are C<distinct> and C<verbose>.
716  
717  
718 =cut
719  
720 elsif ( $action eq "idcounts" ) {
721 2 ▶ while (my (@list) = $db->idCounts($ARGV[0], %passopts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@list) = $db->idCounts($ARGV[0], %passopts)) 10 2 12
722 10 print "@list\n"};
723 }
724  
725 =item C<idlist>
726  
727 Interface to the C<idList()> method.
728  
729 For each identifier output a complicated list of the corresponding entries.
730 Optionally only these identifiers which match the pattern given
731 by the first argument are shown.
732  
733 =cut
734  
735 elsif ( $action eq "idlist" ) {
736 2 binmode (STDOUT, ":utf8");
737 2 ▶ while (my (@list) = $db->idList(@ARGV)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@list) = $db->idList(@ARGV)) 8 2 10
738 8 my $id = shift @list;
739 8 print "$id";
740 8 local($") = ",";
741 8 foreach my $rowref ( @list ) {
742 13 ▶ pop @$rowref while @$rowref && (! defined $rowref->[$#{$rowref}]);
Branch: 1 branch
BranchTrueFalseTotal
@$rowref and not defined $$rowref[$#{$rowref;}] and do { pop @$rowref } 0 13 13
Condition33%1/3
@$rowref and not defined $$rowref[$#{$rowref;}]
!ll&&!rl&&r
0130
MC/DC0%0/2
@$rowref and not defined $$rowref[$#{$rowref;}]
@$rowref not defined $$rowref[$#{$rowref;}]
Truth table33%1/3
A and not(B)
A= @$rowrefB= not defined $$rowref[$#{$rowref;}]
ABresult
0X0
100
111
743 13 ▶ my @pretty = map { (defined $_) ? $_ : "" } @$rowref;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 65 0 65
744 13 print "\t@pretty";
745 }
746 8 print "\n";
747 };
748 }
749  
750 =item C<incidence>
751  
752 Interpretation of the C<idList()> method.
753  
754 For each identifier output a sorted list of aliases (or seqnos).
755  
756 =cut
757  
758 elsif ( $action eq "incidence" ) {
759 1 binmode (STDOUT, ":utf8");
760 1 my $aliasref = $db->RepoCols("_alias");
761 1 ▶ while (my (@list) = $db->idList(@ARGV)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@list) = $db->idList(@ARGV)) 7 1 8
762 7 my $id = shift @list;
763 7 my %sources;
764 7 foreach my $rowref ( @list ) {
765 10 my $seqno = $rowref->[0];
766 10 ▶ $sources{$aliasref->{$seqno} || "<$seqno>"} ++;
Condition50%1/2
$aliasref->{$seqno} || "<$seqno>"
l!l
100
MC/DC0%0/1
$aliasref->{$seqno} || "<$seqno>"
$aliasref->{$seqno}
Truth table50%1/2
A
A= $aliasref->{$seqno}
Aresult
11
00
767 };
768 7 my @sorted = sort keys %sources;
769 7 local($") = " ";
770 7 print "$id\|".(scalar @sorted)."\|@sorted\n";
771 };
772 }
773  
774 =item C<dumpmeta>
775  
776 Interface to the C<dumpmeta> method.
777  
778 Lists all header fields from the database.
779  
780  
781 =item C<beacon>
782  
783 Interface to the C<beacon()> method.
784  
785 Produces a beacon file (header fields plus beacon entries)
786 for the database.
787  
788 The Base URL for the service to be denoted is mandatory as
789 first parameter.
790  
791 =cut
792  
793 ▶elsif ( ($action eq "dumpmeta") or ($action eq "beacon") ) {
Condition66%2/3
$action eq "dumpmeta" or $action eq "beacon"
l!l&&r!l&&!r
0111
MC/DC50%1/2
$action eq "dumpmeta" or $action eq "beacon"
$action eq "dumpmeta" $action eq "beacon"
Truth table66%2/3
A or B
A= $action eq "dumpmeta"B= $action eq "beacon"
ABresult
1X1
011
000
794 1 binmode(STDOUT, ":utf8");
795 1 my $cgibase = shift @ARGV;
796 1 ▶ unless ( $cgibase ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cgibase) 0 1 1
797 0 ▶ if ( $action eq "beacon" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'beacon') { } 0 0 0
798 0 die "ERROR: You MUST provide a cgi base address\n"}
799 else {
800 0 warn "WARNING: You will have to provide a cgi base address\n"}
801 };
802 1 ▶ require SeeAlso::Source::BeaconAggregator::Publisher or die "could not require Publisher extension";
Branch: 1 branch
BranchTrueFalseTotal
require SeeAlso::Source::BeaconAggregator::Publisher or die "could not require Publisher extension" 0 1 1
803 1 SeeAlso::Source::BeaconAggregator::Publisher->activate(); # "recast" all objects
804 1 my $preset = {'FORMAT' => 'BEACON', 'VERSION' => '0.1'};
805 1 foreach my $pset ( @presets ) {
806 1 $pset =~ s/^(['"])([^=]+)\1\s*=/$2=/;
807 1 $pset =~ s/=\s*(['"])([^=]+)\1$/=$2/;
808 1 $pset =~ s/^(['"])(.+)\1$/$2/;
809 1 ▶ if ( $pset =~ /^([A-Z]+)\s*=\s*(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pset =~ /^([A-Z]+)\s*=\s*(.*)$/) { } 1 0 1
810 1 $preset->{$1} = $2}
811 else {
812 0 warn "ignoring --preset $pset\n"};
813 }
814 1 my ( $error, $headerref) = $db->$action($cgibase, @ARGV, $preset);
815 1 ▶ if ( $headerref && ($action eq "dumpmeta") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headerref and $action eq "dumpmeta") 0 1 1
Condition33%1/3
$headerref and $action eq "dumpmeta"
!ll&&!rl&&r
010
MC/DC0%0/2
$headerref and $action eq "dumpmeta"
$headerref $action eq "dumpmeta"
Truth table33%1/3
A and B
A= $headerrefB= $action eq "dumpmeta"
ABresult
0X0
100
111
816 0 print @$headerref};
817 }
818  
819 =item C<setmeta>
820  
821 Set OSD or beacon meta fields for the database.
822  
823 =cut
824  
825 elsif ( $action eq "setmeta" ) {
826 0 foreach ( @ARGV ) {
827 0 ▶ if ( /^#([A-Z][A-Z0-9-]*)(?::\s*(.*))?$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^#([A-Z][A-Z0-9-]*)(?::\s*(.*))?$/) { } 0 0 0
elsif (/^([A-Z][\w-]+)(?::\s*(.*))?$/) { } 0 0 0
828 0 my ($key, $val) = ($1, $2);
829 0 my $success;
830 0 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
831 0 $success = $db->setBeaconMeta($key, $val)}
832 else {
833 0 $success = $db->clearBeaconMeta($key)};
834 0 ▶ print "#$key processed\n" if $success and $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $success and $verbose 0 0 0
Condition0%0/3
$success and $verbose
!ll&&!rl&&r
000
MC/DC0%0/2
$success and $verbose
$success $verbose
Truth table0%0/3
A and B
A= $successB= $verbose
ABresult
0X0
100
111
835 }
836 elsif ( /^([A-Z][\w-]+)(?::\s*(.*))?$/ ) {
837 0 my ($key, $val) = ($1, $2);
838 0 my $success;
839 0 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
840 0 $success = $db->addOSD($key, $val)}
841 else {
842 0 $success = $db->clearOSD($key)};
843 0 ▶ print "$key processed\n" if $success and $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $success and $verbose 0 0 0
Condition0%0/3
$success and $verbose
!ll&&!rl&&r
000
MC/DC0%0/2
$success and $verbose
$success $verbose
Truth table0%0/3
A and B
A= $successB= $verbose
ABresult
0X0
100
111
844 }
845 else {
846 0 warn "cannot parse: >$_<"}
847 }
848 }
849  
850 =item C<loadmeta>
851  
852 Completely exchanges the OSD and beacon meta fields for the
853 database by the contents of the file given as first argument.
854  
855 =cut
856  
857 elsif ( $action eq "loadmeta" ) {
858 0 ▶ my $tplfile = shift @ARGV or die "please supply a template file";
Branch: 1 branch
BranchTrueFalseTotal
my $tplfile = shift @ARGV or die "please supply a template file" 0 0 0
859 0 ▶ open(TPL, "<:utf8", $tplfile) or die "cannot open template file $tplfile";
Branch: 1 branch
BranchTrueFalseTotal
open TPL, "<:utf8", $tplfile or die "cannot open template file $tplfile" 0 0 0
860 0 my ($didosd, $didmeta) = (0, 0);
861 0 ▶ while ( <TPL> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline TPL)) 0 0 0
862 0 ▶ if ( /^#([A-Z][A-Z0-9-]*):\s*(.*)$/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^#([A-Z][A-Z0-9-]*):\s*(.*)$/) { } 0 0 0
elsif (/^([A-Z][\w-]+):\s*(.*)$/) { } 0 0 0
elsif (/^\s*$/) { } 0 0 0
863 0 my ($key, $val) = ($1, $2);
864 0 ▶ unless ( $didmeta ++ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($didmeta++) 0 0 0
865 0 $db->clearBeaconMeta($_) foreach $db->beaconfields()};
866 0 ▶ $db->setBeaconMeta($key, $val) if $val; # set!
Branch: 1 branch
BranchTrueFalseTotal
if $val 0 0 0
867 }
868 elsif ( /^([A-Z][\w-]+):\s*(.*)$/ ) {
869 0 my ($key, $val) = ($1, $2);
870 0 ▶ unless ( $didosd ++ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($didosd++) 0 0 0
871 0 $db->clearOSD($_) foreach $db->osdKeys()};
872 0 ▶ $db->addOSD($key, $val) if $val; # add!
Branch: 1 branch
BranchTrueFalseTotal
if $val 0 0 0
873 }
874 elsif ( /^\s*$/ ) { # don't care
875 }
876 else {
877 0 warn "cannot parse: >$_<"}
878 }
879 0 close(TPL);
880 0 ▶ if ( $didosd ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($didosd) { } 0 0 0
elsif ($didmeta) { } 0 0 0
881 0 ▶ refreshOSD(1) unless $keeposd}
Branch: 1 branch
BranchTrueFalseTotal
unless $keeposd 0 0 0
882 elsif ( $didmeta ) {
883 0 ▶ refreshOSD($force) unless $keeposd};
Branch: 1 branch
BranchTrueFalseTotal
unless $keeposd 0 0 0
884 }
885  
886 =item C<dumposd>
887  
888 Shows Open Search Description.
889  
890 =item C<refreshosd>
891  
892 Recalculates default Open Search Description (list constituents as
893 description, give counts, find examples, ...)
894  
895  
896 =cut
897 ▶elsif ( ($action eq "dumposd") or ($action eq "refreshosd") ) {
Condition33%1/3
$action eq "dumposd" or $action eq "refreshosd"
l!l&&r!l&&!r
0011
MC/DC0%0/2
$action eq "dumposd" or $action eq "refreshosd"
$action eq "dumposd" $action eq "refreshosd"
Truth table33%1/3
A or B
A= $action eq "dumposd"B= $action eq "refreshosd"
ABresult
1X1
011
000
898 0 ▶ refreshOSD(1) if $action eq "refreshosd";
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "refreshosd" 0 0 0
899 0 binmode(STDOUT, ":utf8");
900 0 ▶ if ( my $resultref = $db->OSDValues() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $resultref = $db->OSDValues) 0 0 0
901 0 foreach ( sort keys %$resultref ) {
902 0 print "$_ => ";
903 0 ▶ if ( !defined $resultref->{$_} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $resultref->{$_}) { } 0 0 0
elsif (not ref $resultref->{$_}) { } 0 0 0
904 0 print "<undef>"}
905 elsif ( !ref($resultref->{$_}) ) {
906 0 print ">".$resultref->{$_}."<"}
907 else {
908 0 foreach my $item ( @{$resultref->{$_}} ) {
909 0 print "\n- ";
910 0 ▶ if ( !defined $item ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $item) { } 0 0 0
911 0 print "<undef>"}
912 else {
913 0 print ">$item<"}
914 }
915 }
916 0 print "\n";
917 }
918 };
919 }
920  
921 =item header
922  
923 =cut
924  
925 elsif ( $action eq "admin" ) {
926 1 ▶ if ( scalar @ARGV ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ARGV) { } 0 1 1
927 0 my $did = 0;
928 0 ▶ while ( scalar @ARGV && (my $field = shift @ARGV) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ARGV and my $field = shift @ARGV) 0 0 0
Condition0%0/3
scalar @ARGV and my $field = shift @ARGV
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @ARGV and my $field = shift @ARGV
scalar @ARGV my $field = shift @ARGV
Truth table0%0/3
A and B
A= scalar @ARGVB= my $field = shift @ARGV
ABresult
0X0
100
111
929 0 my($key, $val) = split(/=/, $field, 2);
930 0 my $oldval = $db->admin($key, $val);
931 0 ▶ $oldval = "{undef}" unless defined $oldval;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $oldval 0 0 0
932 0 ▶ my $changed = ((defined $val) && ($oldval ne $val)) ? "old value $oldval changed" : $oldval;
Branch: 1 branch
BranchTrueFalseTotal
defined $val && $oldval ne $val ? : 0 0 0
Condition0%0/3
defined $val and $oldval ne $val
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $oldval ne $val
defined $val $oldval ne $val
Truth table0%0/3
A and B
A= defined $valB= $oldval ne $val
ABresult
0X0
100
111
933 0 print "$key - $changed\n";
934 };
935 }
936 else {
937 1 my $admref = $db->admin();
938 1 foreach ( sort keys %$admref ) {
939 4 print "$_ : $admref->{$_}\n"}
940 }
941 }
942  
943 =item C<deflate>
944  
945 Interface to the C<deflate()> method (DEFLATE+REINDEX+ANALYZE the
946 SQLite database);
947  
948 =cut
949  
950 elsif ( $action eq "deflate" ) {
951 0 $db->deflate}
952  
953  
954 =item C<version>
955  
956 Dump some version numbers
957  
958 =cut
959  
960 elsif ( $action eq "version" ) {
961 1 print "sasbactrl version $VERSION\n";
962 1 print "SeeAlso::Source::BeaconAggregator version $SeeAlso::Source::BeaconAggregator::VERSION\n";
963 1 print "SeeAlso::Source::BeaconAggregator::Maintenance version $SeeAlso::Source::BeaconAggregator::Maintenance::VERSION\n";
964 1 print "SeeAlso::Identifier version $SeeAlso::Identifier::VERSION\n";
965 1 print "SeeAlso::Identifier::GND version $SeeAlso::Identifier::GND::VERSION\n";
966 }
967  
968 =item C<noop>
969  
970 Do nothing (you may want for exit status or use some --pragma's)
971  
972 =cut
973  
974 elsif ( $action eq "noop" ) {
975 9 ▶ print "OK!\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 9 0 9
976 }
977  
978 =back
979  
980 =cut
981  
982 else {
983 0 pod2usage({-message => "Unsupported action '$action'", -exitval => 3})}
984  
985  
986  
987 sub refreshOSD { #
988 # if ( $keeposd ) {
989 # print "NOT refreshing OSD data\n" if $verbose;
990 # return 0;
991 # }
992 5 ▶ my ($doexamples) = @_;
Subroutine refreshOSD: called CC=96 SCAR=75.0
993 5 my $anyref = $db->RepoCols();
994 5 my $repcnt = scalar keys %$anyref;
995 5 print "Refreshing OSD data from $repcnt sources: ";
996  
997 5 ▶ print "DateModified... " if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 5 0 5
998 5 $db->setOSD("DateModified", time());
999  
1000 5 my $gcounti = $db->admin('gcounti');
1001 5 ▶ unless ( $gcounti ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gcounti) 0 5 5
1002 0 ▶ $gcounti = $db->idStat(undef, distinct => 0) || 0;
Condition0%0/2
$db->idStat(undef, 'distinct', 0) || 0
l!l
00
MC/DC0%0/1
$db->idStat(undef, 'distinct', 0) || 0
$db->idStat(undef, 'distinct', 0)
Truth table0%0/2
A
A= $db->idStat(undef, 'distinct', 0)
Aresult
11
00
1003 0 ▶ $gcounti && $db->admin('gcounti', $gcounti) unless $keeposd;
Branch: 1 branch
BranchTrueFalseTotal
unless $keeposd 0 0 0
Condition0%0/6
$keeposd || $gcounti && $db->admin('gcounti', $gcounti)
l!l&&r!l&&!r
000
$gcounti and $db->admin("gcounti", $gcounti)
!ll&&!rl&&r
000
MC/DC0%0/3
$keeposd || $gcounti && $db->admin('gcounti', $gcounti)
$keeposd $gcounti $db->admin("gcounti", $gcounti)
Truth table0%0/4
A || B and C
A= $keeposdB= $gcountiC= $db->admin("gcounti", $gcounti)
ABCresult
1XX1
0111
00X0
0100
1004 };
1005 5 my $gcountu = $db->admin('gcountu');
1006 5 ▶ unless ( $gcountu ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gcountu) 0 5 5
1007 0 ▶ $gcountu = $db->idStat(undef, distinct => 1) || 0;
Condition0%0/2
$db->idStat(undef, 'distinct', 1) || 0
l!l
00
MC/DC0%0/1
$db->idStat(undef, 'distinct', 1) || 0
$db->idStat(undef, 'distinct', 1)
Truth table0%0/2
A
A= $db->idStat(undef, 'distinct', 1)
Aresult
11
00
1008 0 ▶ $gcountu && $db->admin('gcountu', $gcountu) unless $keeposd;
Branch: 1 branch
BranchTrueFalseTotal
unless $keeposd 0 0 0
Condition0%0/6
$keeposd || $gcountu && $db->admin('gcountu', $gcountu)
l!l&&r!l&&!r
000
$gcountu and $db->admin("gcountu", $gcountu)
!ll&&!rl&&r
000
MC/DC0%0/3
$keeposd || $gcountu && $db->admin('gcountu', $gcountu)
$keeposd $gcountu $db->admin("gcountu", $gcountu)
Truth table0%0/4
A || B and C
A= $keeposdB= $gcountuC= $db->admin("gcountu", $gcountu)
ABCresult
1XX1
0111
00X0
0100
1009 };
1010  
1011 5 ▶ print "collect Descriptions... " if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 5 0 5
1012 5 my $exclprefix = " [excluding: ";
1013 5 my %descr;
1014 5 my $countref = $db->RepoCols("_countu");
1015 5 my $aliasref = $db->RepoCols("_alias");
1016 5 my $sortref = $db->RepoCols("_sort");
1017 5 foreach ( keys %$aliasref ) {
1018 15 ▶ $sortref->{$_} ||= $aliasref->{$_}};
Condition33%1/3
$sortref->{$_} ||= $aliasref->{$_}
l!l&&r!l&&!r
0150
MC/DC0%0/2
$sortref->{$_} ||= $aliasref->{$_}
$sortref->{$_} $aliasref->{$_}
Truth table33%1/3
A ||= B
A= $sortref->{$_}B= $aliasref->{$_}
ABresult
1X1
011
000
1019 5 my $textref = $db->RepoCols("NAME");
1020 5 foreach ( keys %$textref ) {
1021 15 ▶ $descr{$_} ||= $textref->{$_} if defined $textref->{$_}};
Branch: 1 branch
BranchTrueFalseTotal
if defined $textref->{$_} 5 10 15
Condition33%1/3
$descr{$_} ||= $textref->{$_}
l!l&&r!l&&!r
050
MC/DC0%0/2
$descr{$_} ||= $textref->{$_}
$descr{$_} $textref->{$_}
Truth table33%1/3
A ||= B
A= $descr{$_}B= $textref->{$_}
ABresult
1X1
011
000
1022 5 $textref = $db->RepoCols("DESCRIPTION");
1023 5 foreach ( keys %$textref ) {
1024 15 ▶ $descr{$_} ||= $textref->{$_} if defined $textref->{$_}};
Branch: 1 branch
BranchTrueFalseTotal
if defined $textref->{$_} 5 10 15
Condition33%1/3
$descr{$_} ||= $textref->{$_}
l!l&&r!l&&!r
500
MC/DC0%0/2
$descr{$_} ||= $textref->{$_}
$descr{$_} $textref->{$_}
Truth table33%1/3
A ||= B
A= $descr{$_}B= $textref->{$_}
ABresult
1X1
011
000
1025 5 $textref = $db->RepoCols("INSTITUTION");
1026 5 foreach ( keys %$textref ) {
1027 15 ▶ $descr{$_} ||= $textref->{$_} if defined $textref->{$_}};
Branch: 1 branch
BranchTrueFalseTotal
if defined $textref->{$_} 0 15 15
Condition0%0/3
$descr{$_} ||= $textref->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$descr{$_} ||= $textref->{$_}
$descr{$_} $textref->{$_}
Truth table0%0/3
A ||= B
A= $descr{$_}B= $textref->{$_}
ABresult
1X1
011
000
1028 5 $textref = $db->RepoCols("FEED");
1029 5 foreach ( keys %$textref ) {
1030 15 ▶ $descr{$_} ||= $textref->{$_} if defined $textref->{$_}};
Branch: 1 branch
BranchTrueFalseTotal
if defined $textref->{$_} 0 15 15
Condition0%0/3
$descr{$_} ||= $textref->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$descr{$_} ||= $textref->{$_}
$descr{$_} $textref->{$_}
Truth table0%0/3
A ||= B
A= $descr{$_}B= $textref->{$_}
ABresult
1X1
011
000
1031 5 $textref = $db->RepoCols("_alias");
1032 5 foreach ( keys %$textref ) {
1033 15 ▶ $descr{$_} ||= "Listed by $textref->{$_}" if defined $textref->{$_}};
Branch: 1 branch
BranchTrueFalseTotal
if defined $textref->{$_} 15 0 15
Condition100%2/2
$descr{$_} ||= "Listed by $textref->{$_}"
l!l
510
MC/DC100%1/1
$descr{$_} ||= "Listed by $textref->{$_}"
$descr{$_}
Truth table100%2/2
A
A= $descr{$_}
Aresult
11
00
1034 5 foreach ( keys %$countref ) {
1035 15 ▶ next unless $descr{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $descr{$_} 0 15 15
1036 15 ▶ if ( $countref->{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($countref->{$_}) { } 15 0 15
1037 15 $descr{$_} .= " [".$countref->{$_}."]"}
1038 else {
1039 0 ▶ print $exclprefix . ($aliasref->{$_} || $_) if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
Condition0%0/3
$aliasref->{$_} || $_
l!l&&r!l&&!r
000
MC/DC0%0/2
$aliasref->{$_} || $_
$aliasref->{$_} $_
Truth table0%0/3
A || B
A= $aliasref->{$_}B= $_
ABresult
1X1
011
000
1040 0 $exclprefix = ", ";
1041 0 delete $descr{$_};
1042 };
1043 };
1044 5 ▶ print "] ... " if $verbose && $exclprefix eq ", ";
Branch: 1 branch
BranchTrueFalseTotal
if $verbose and $exclprefix eq ", " 0 5 5
Condition33%1/3
$verbose and $exclprefix eq ", "
!ll&&!rl&&r
050
MC/DC0%0/2
$verbose and $exclprefix eq ", "
$verbose $exclprefix eq ", "
Truth table33%1/3
A and B
A= $verboseB= $exclprefix eq ", "
ABresult
0X0
100
111
1045 5 my $rcount = scalar keys %descr;
1046 5 ▶ print "set Descriptions... " if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 5 0 5
1047 $db->setOSD("Description", "Currently serving $gcountu distinct identifiers from $rcount beacon sources:\n -- "
1048 5 ▶ .join(".\n -- ", map { $descr{$_} } sort { (($countref->{$b}||-1) <=> ($countref->{$a}||-1)) || ($sortref->{$a} cmp $sortref->{$b}) } keys %descr)
Branch: 1 branch
BranchTrueFalseTotal
($countref->{$b} || -1) <=> ($countref->{$a} || -1) or $sortref->{$a} cmp $sortref->{$b} 4 10 14
Condition50%2/4
$countref->{$b} || -1
l!l
140
$countref->{$a} || -1
l!l
140
MC/DC0%0/1
$countref->{$b} || -1
$countref->{$b}
MC/DC0%0/1
$countref->{$a} || -1
$countref->{$a}
Truth table50%1/2
A
A= $countref->{$b}
Aresult
11
00
Truth table50%1/2
A
A= $countref->{$a}
Aresult
11
00
1049 );
1050  
1051 5 my $srcref = $db->RepoCols("FEED");
1052 5 ▶ my @vals = map { ($_ && /\S/) ? ($_) : () } values %$srcref;
Branch: 1 branch
BranchTrueFalseTotal
$_ && /\S/ ? : 0 15 15
Condition33%1/3
$_ and /\S/
!ll&&!rl&&r
1500
MC/DC0%0/2
$_ and /\S/
$_ /\S/
Truth table33%1/3
A and B
A= $_B= /\S/
ABresult
0X0
100
111
1053 5 ▶ print "set Sources... " if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 5 0 5
1054 5 $db->setOSD("Source", @vals);
1055  
1056 5 ▶ unless ( $doexamples ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doexamples) 1 4 5
1057 1 print "(skipping examples) ... done\n";
1058 1 return 1;
1059 };
1060  
1061 4 ▶ return 1 unless $repcnt; # no repositories => no examples
Branch: 1 branch
BranchTrueFalseTotal
unless $repcnt 0 4 4
1062  
1063 4 ▶ print "Examples from Sources [" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 4 0 4
1064 4 $db->clearOSD("Examples");
1065 4 my (%seen, %covered);
1066 4 my $explref = $db->RepoCols("EXAMPLES");
1067 4 my $max = 0;
1068 4 foreach my $sq ( sort {$b <=> $a} keys %$explref ) {
1069 12 my $expl = $explref->{$sq};
1070 12 ▶ next unless defined $expl;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expl 12 0 12
1071 0 ▶ print "$sq:" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1072 0 my $cnt = 0;
1073 0 ▶ foreach my $id ( sort {$b cmp $a} map { $_ ? $_ : () } split(/\s*\|\s*/, $expl) ) {
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
1074 0 ▶ print "." if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1075 0 my ($normid, @sequences) = $db->idList($id);
1076 0 ▶ if ( $normid ) { # flush iterator
Branch: 1 branch
BranchTrueFalseTotal
if ($normid) { } 0 0 0
1077 0 ▶ warn "assertion failed (examples from seqno $sq): multiple lists for $id" while $db->idList(); # Flush iterator
Branch: 1 branch
BranchTrueFalseTotal
$db->idList and do { warn "assertion failed (examples from seqno $sq): multiple lists for $id" } 0 0 0
1078 }
1079 else {
1080 0 print "\n\t[normalizing example >$id< for seqno $sq failed!]\n";
1081 0 $db->addOSD("Examples", "$id");
1082 0 ▶ warn "assertion failed (examples from seqno $sq): multiple lists for $id" while $db->idList(); # Flush iterator
Branch: 1 branch
BranchTrueFalseTotal
$db->idList and do { warn "assertion failed (examples from seqno $sq): multiple lists for $id" } 0 0 0
1083 0 next;
1084 };
1085 #warn "$sq: $id already seen" if $seen{$normid};
1086 0 ▶ next if $seen{$normid}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$normid}++ 0 0 0
1087 0 my ($i, $j, $new) = (0, 0, 0);
1088 0 foreach my $seqref ( @sequences ) {
1089 0 $i ++;
1090 0 ▶ $j += ($seqref->[1] || 1);
Condition0%0/2
$seqref->[1] || 1
l!l
00
MC/DC0%0/1
$seqref->[1] || 1
$seqref->[1]
Truth table0%0/2
A
A= $seqref->[1]
Aresult
11
00
1091 0 ▶ next if $covered{$seqref->[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $covered{$seqref->[0]} 0 0 0
1092 #warn "$sq: yet uncovered $seqref->[0] for $id/$normid";
1093 0 $new = $covered{$seqref->[0]} = 1;
1094 };
1095 #warn "$sq: all covered for $id/$normid" unless $new;
1096 0 ▶ next unless $new;
Branch: 1 branch
BranchTrueFalseTotal
unless $new 0 0 0
1097 0 ▶ print "+" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1098 0 $db->addOSD("Examples", "$id|$i/$j");
1099 0 ▶ $max = $i if $i > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $i > $max 0 0 0
1100 0 last;
1101 };
1102 0 ▶ print " " if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1103 };
1104  
1105 4 ▶ print "] ... Examples by coincidence" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 4 0 4
1106 4 my $k = sprintf("%.0f", exp(log($repcnt)*4/5)); # 4 out of 5, 23 out of 50, 40 out of 100
1107 4 ▶ $k = $EXAMPLEGOAL if $EXAMPLEGOAL and ($k > $EXAMPLEGOAL);
Branch: 1 branch
BranchTrueFalseTotal
if $main::EXAMPLEGOAL and $k > $main::EXAMPLEGOAL 0 4 4
Condition33%1/3
$main::EXAMPLEGOAL and $k > $main::EXAMPLEGOAL
!ll&&!rl&&r
040
MC/DC0%0/2
$main::EXAMPLEGOAL and $k > $main::EXAMPLEGOAL
$main::EXAMPLEGOAL $k > $main::EXAMPLEGOAL
Truth table33%1/3
A and B
A= $main::EXAMPLEGOALB= $k > $main::EXAMPLEGOAL
ABresult
0X0
100
111
1108 4 ▶ print " [goal: clusters of size >$k:" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 4 0 4
1109 4 my $eref;
1110 4 ▶ my $i = $max || 0;
Condition50%1/2
$max || 0
l!l
04
MC/DC0%0/1
$max || 0
$max
Truth table50%1/2
A
A= $max
Aresult
11
00
1111 4 my $j = $i +1;
1112 4 my $sthcache = "";
1113 4 ▶ print " $i" if $i && $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $i and $verbose 0 4 4
Condition33%1/3
$i and $verbose
!ll&&!rl&&r
400
MC/DC0%0/2
$i and $verbose
$i $verbose
Truth table33%1/3
A and B
A= $iB= $verbose
ABresult
0X0
100
111
1114 4 ▶ while ( ($j <= $k) and (my $tmperef = $db->findExample($j, 0, $sthcache)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $k and my $tmperef = $db->findExample($j, 0, $sthcache)) 8 4 12
Condition66%2/3
$j <= $k and my $tmperef = $db->findExample($j, 0, $sthcache)
!ll&&!rl&&r
408
MC/DC50%1/2
$j <= $k and my $tmperef = $db->findExample($j, 0, $sthcache)
$j <= $k my $tmperef = $db->findExample($j, 0, $sthcache)
Truth table66%2/3
A and B
A= $j <= $kB= my $tmperef = $db->findExample($j, 0, $sthcache)
ABresult
0X0
100
111
1115 8 $eref = $tmperef;
1116 8 $eref->{response} =~ /^(\d+)\b/;
1117 8 ▶ my $this = $1 || $j;
Condition33%1/3
$1 || $j
l!l&&r!l&&!r
800
MC/DC0%0/2
$1 || $j
$1 $j
Truth table33%1/3
A || B
A= $1B= $j
ABresult
1X1
011
000
1118 8 ▶ print " $this" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 8 0 8
1119 8 $i = $this;
1120 8 $j = $this +1;
1121 };
1122 4 ▶ print "= $eref->{id}" if $verbose && $eref;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose and $eref 4 0 4
Condition33%1/3
$verbose and $eref
!ll&&!rl&&r
004
MC/DC0%0/2
$verbose and $eref
$verbose $eref
Truth table33%1/3
A and B
A= $verboseB= $eref
ABresult
0X0
100
111
1123 4 ▶ print "]" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 4 0 4
1124 4 ▶ while ( $i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i) 4 0 4
1125 4 ▶ print " ($i)" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 4 0 4
1126 4 ▶ if ( $eref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eref) 4 0 4
1127 4 ▶ $seen{$eref->{id}} || $db->addOSD("Examples", $eref->{id}."|".$eref->{response})};
Branch: 1 branch
BranchTrueFalseTotal
$seen{$eref->{"id"}} or $db->addOSD("Examples", $eref->{"id"} . '|' . $eref->{"response"}) 4 0 4
1128 4 ▶ last if $i <= $EXAMPLEGOAL; # no more examples if max is max...
Branch: 1 branch
BranchTrueFalseTotal
if $i <= $main::EXAMPLEGOAL 4 0 4
1129 0 ▶ $i = $EXAMPLEGOAL if $EXAMPLEGOAL and ($i > $EXAMPLEGOAL);
Branch: 1 branch
BranchTrueFalseTotal
if $main::EXAMPLEGOAL and $i > $main::EXAMPLEGOAL 0 0 0
Condition0%0/3
$main::EXAMPLEGOAL and $i > $main::EXAMPLEGOAL
!ll&&!rl&&r
000
MC/DC0%0/2
$main::EXAMPLEGOAL and $i > $main::EXAMPLEGOAL
$main::EXAMPLEGOAL $i > $main::EXAMPLEGOAL
Truth table0%0/3
A and B
A= $main::EXAMPLEGOALB= $i > $main::EXAMPLEGOAL
ABresult
0X0
100
111
1130 0 ▶ print "[10?]" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1131 ($eref = $db->findExample($i, 10, $sthcache)) ? $db->addOSD("Examples", $eref->{id}."|".$eref->{response})
1132 0 ▶ : (($eref = $db->findExample($i, 1, $sthcache)) && $db->addOSD("Examples", $eref->{id}."|".$eref->{response}),
Branch: 1 branch
BranchTrueFalseTotal
($eref = $db->findExample($i, 10, $sthcache)) ? : 0 0 0
Condition0%0/3
$eref = $db->findExample($i, 1, $sthcache) and $db->addOSD("Examples", $eref->{"id"} . '|' . $eref->{"response"})
!ll&&!rl&&r
000
MC/DC0%0/2
$eref = $db->findExample($i, 1, $sthcache) and $db->addOSD("Examples", $eref->{"id"} . '|' . $eref->{"response"})
$eref = $db->findExample($i, 1, $sthcache) $db->addOSD("Examples", $eref->{"id"} . '|' . $eref->{"response"})
Truth table0%0/3
A and B
A= $eref = $db->findExample($i, 1, $sthcache)B= $db->addOSD("Examples", $eref->{"id"} . '|' . $eref->{"response"})
ABresult
0X0
100
111
1133 last);
1134 0 ▶ print "[100?]" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1135 0 ▶ ($eref = $db->findExample($i, 100, $sthcache)) ? $db->addOSD("Examples", $eref->{id}."|".$eref->{response}) : last;
Branch: 1 branch
BranchTrueFalseTotal
($eref = $db->findExample($i, 100, $sthcache)) ? : 0 0 0
1136 0 ▶ print "[1000?]" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1137 0 ▶ ($eref = $db->findExample($i, 1000, $sthcache)) ? $db->addOSD("Examples", $eref->{id}."|".$eref->{response}) : last;
Branch: 1 branch
BranchTrueFalseTotal
($eref = $db->findExample($i, 1000, $sthcache)) ? : 0 0 0
1138 0 ▶ print "[10000?]" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1139 0 ▶ ($eref = $db->findExample($i, 10000, $sthcache)) ? $db->addOSD("Examples", $eref->{id}."|".$eref->{response}) : last;
Branch: 1 branch
BranchTrueFalseTotal
($eref = $db->findExample($i, 10000, $sthcache)) ? : 0 0 0
1140 0 ▶ print "[100000?]" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1141 0 ▶ ($eref = $db->findExample($i, 100000, $sthcache)) ? $db->addOSD("Examples", $eref->{id}."|".$eref->{response}) : last;
Branch: 1 branch
BranchTrueFalseTotal
($eref = $db->findExample($i, 100000, $sthcache)) ? : 0 0 0
1142 0 ▶ print "[1000000?]" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
1143 0 ▶ ($eref = $db->findExample($i, 1000000, $sthcache)) ? $db->addOSD("Examples", $eref->{id}."|".$eref->{response}) : last;
Branch: 1 branch
BranchTrueFalseTotal
($eref = $db->findExample($i, 1000000, $sthcache)) ? : 0 0 0
1144 0 $i = 0;
1145 };
1146 4 print " done\n";
1147 4 return 1;
1148 }
1149  
1150 sub policy {
1151 0 ▶ my ($st) = @_;
Subroutine policy: not called CC=26 SCAR=65.5
1152 0 my @xstat; # future events
1153 # 1a. timestamps deleted: force reload
1154 0 ▶ if ( !$st->{"ftime"} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $st->{'ftime'}) { } 0 0 0
elsif (not $st->{'mtime'}) { } 0 0 0
1155 0 push(@xstat, [$^T, 'FORCE', "!reload forced (no _ftime)"]);
1156 }
1157 elsif ( !$st->{"mtime"} ) {
1158 0 push(@xstat, [$^T, 'FORCE', "!reload forced (no _mtime)"]);
1159 };
1160  
1161 # 1b. force reload by time conditions
1162 0 ▶ my $polmax = $st->{"rtime"} ? $REVISITFORCE : $NOREVISITFORCE;
Branch: 1 branch
BranchTrueFalseTotal
$st->{'rtime'} ? : 0 0 0
1163 0 ▶ push(@xstat, [$st->{"ftime"} +$polmax, 'DATE', sprintf("+forced reload policy %.1fw", $polmax/3600/24/7)]) if $st->{"ftime"};
Branch: 1 branch
BranchTrueFalseTotal
if $st->{"ftime"} 0 0 0
1164  
1165 0 ▶ if ( $st->{"rtime"} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($st->{'rtime'}) { } 0 0 0
elsif ($st->{'ftime'}) { } 0 0 0
1166 # 2. revisit reasoning: Hold/force reload
1167 0 my $text;
1168 0 ▶ if ( $^T < $st->{"rtime"} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($^T < $st->{'rtime'}) { } 0 0 0
elsif ($st->{'ftime'} and $st->{'ftime'} < $st->{'rtime'}) { } 0 0 0
1169 0 $text = "-Respect"}
1170 ▶ elsif ( $st->{"ftime"} && ($st->{"ftime"} < $st->{"rtime"}) ) { # force if never fetched after $rtime
Condition0%0/3
$st->{"ftime"} and $st->{"ftime"} < $st->{"rtime"}
!ll&&!rl&&r
000
MC/DC0%0/2
$st->{"ftime"} and $st->{"ftime"} < $st->{"rtime"}
$st->{"ftime"} $st->{"ftime"} < $st->{"rtime"}
Truth table0%0/3
A and B
A= $st->{"ftime"}B= $st->{"ftime"} < $st->{"rtime"}
ABresult
0X0
100
111
1171 0 $text = "+Expired"}
1172 else {
1173 0 $text = "*Stale*"};
1174 0 ▶ my $sxtime = $st->{"stime"} || $st->{"mtime"}; # prefer TIMESTAMP for difference to REVISIT
Condition0%0/3
$st->{'stime'} || $st->{'mtime'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$st->{'stime'} || $st->{'mtime'}
$st->{'stime'} $st->{'mtime'}
Truth table0%0/3
A || B
A= $st->{'stime'}B= $st->{'mtime'}
ABresult
1X1
011
000
1175 0 push(@xstat, [$st->{"rtime"}, 'RVST', sprintf("%s REVISIT hint (%s %s)", $text ,tdist($st->{"rtime"} -$sxtime))]);
1176  
1177 0 ▶ if ( $text =~ /Stale/ ) { # additional age reasoning if Stale Revisit hint
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /Stale/) 0 0 0
1178 # 2a. wait at least 5% of age as concluded from expired revisit hint
1179 0 my $delta = ($st->{"ftime"} -$st->{"rtime"}) / 20;
1180 0 push(@xstat, [$st->{"ftime"} +$delta, 'FREQ', sprintf("age policy 5%% (%s %s)", tdist($delta))]);
1181 }
1182 }
1183 elsif ( $st->{"ftime"} ) {
1184 # 3. reasoning on file age and update frequency
1185 0 ▶ if ( my $xstime = $st->{"mtime"} || $st->{"stime"} ) { # prefer "last modified" over #TIMESTAMP
Branch: 1 branch
BranchTrueFalseTotal
if (my $xstime = $st->{"mtime"} || $st->{"stime"}) 0 0 0
Condition0%0/3
$st->{'mtime'} || $st->{'stime'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$st->{'mtime'} || $st->{'stime'}
$st->{'mtime'} $st->{'stime'}
Truth table0%0/3
A || B
A= $st->{'mtime'}B= $st->{'stime'}
ABresult
1X1
011
000
1186 # 3a. wait at least 5% of age as concluded from last fetch
1187 0 my $delta = ($st->{"ftime"} -$xstime) / 20;
1188 0 push(@xstat, [$st->{"ftime"} +$delta, 'FREQ', sprintf("age policy 5%% (%s %s)", tdist($delta))]);
1189 };
1190
1191 # 3b. wait at least $NOREVISITWAIT before reload
1192 0 my $btime = $st->{"ftime"};
1193 # try to get close to mtime
1194 0 ▶ $btime = $st->{"mtime"} if $st->{"mtime"} && ($st->{"ftime"} -$st->{"mtime"} < $NOREVISITWAIT);
Branch: 1 branch
BranchTrueFalseTotal
if $st->{"mtime"} and $st->{"ftime"} - $st->{"mtime"} < $main::NOREVISITWAIT 0 0 0
Condition0%0/3
$st->{"mtime"} and $st->{"ftime"} - $st->{"mtime"} < $main::NOREVISITWAIT
!ll&&!rl&&r
000
MC/DC0%0/2
$st->{"mtime"} and $st->{"ftime"} - $st->{"mtime"} < $main::NOREVISITWAIT
$st->{"mtime"} $st->{"ftime"} - $st->{"mtime"} < $main::NOREVISITWAIT
Truth table0%0/3
A and B
A= $st->{"mtime"}B= $st->{"ftime"} - $st->{"mtime"} < $main::NOREVISITWAIT
ABresult
0X0
100
111
1195 0 push(@xstat, [$btime +$NOREVISITWAIT, 'WAIT', sprintf("revisit policy %.1fh", $NOREVISITWAIT/3600)]);
1196 };
1197  
1198 # 4. wait at least $RETRYWAIT before next attempt
1199 0 ▶ push(@xstat, [$st->{"utime"} +$RETRYWAIT, 'WAIT', sprintf("retry policy %.1fh", $RETRYWAIT/3600)]) if $st->{"utime"};
Branch: 1 branch
BranchTrueFalseTotal
if $st->{"utime"} 0 0 0
1200  
1201 0 my ($forced, $xtime, $maxtime) = (0, 0, 0);
1202 0 my @conds;
1203 0 foreach ( sort {$a->[0] <=> $b->[0]} @xstat ) {
1204 0 my($stamp, $code, $message) = @$_;
1205 0 ▶ $forced = 1 if $message =~ /^!/;
Branch: 1 branch
BranchTrueFalseTotal
if $message =~ /^!/ 0 0 0
1206 0 ▶ if ( $stamp < $^T ) { # expired conditions
Branch: 1 branch
BranchTrueFalseTotal
if ($stamp < $^T) { } 0 0 0
1207 0 ▶ $forced ||= -1 if $message =~ /^\+/;
Branch: 1 branch
BranchTrueFalseTotal
if $message =~ /^\+/ 0 0 0
Condition0%0/2
$forced ||= -1
l!l
00
MC/DC0%0/1
$forced ||= -1
$forced
Truth table0%0/2
A
A= $forced
Aresult
11
00
1208 0 push(@conds, [$stamp, $code, $message]);
1209 0 $xtime = $stamp;
1210 }
1211 else {
1212 0 push(@conds, [$stamp, $code, $message]);
1213 0 ▶ if ( $message =~ /^\+/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($message =~ /^\+/) { } 0 0 0
elsif ($maxtime) { } 0 0 0
1214 0 ▶ $maxtime ||= $stamp}
Condition0%0/3
$maxtime ||= $stamp
l!l&&r!l&&!r
000
MC/DC0%0/2
$maxtime ||= $stamp
$maxtime $stamp
Truth table0%0/3
A ||= B
A= $maxtimeB= $stamp
ABresult
1X1
011
000
1215 elsif ( $maxtime ) {
1216 0 $xtime = $maxtime}
1217 else {
1218 0 ▶ $forced = 0 if $forced < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $forced < 0 0 0 0
1219 0 $xtime = $stamp;
1220 }
1221 }
1222 };
1223 0 return ($forced, $xtime, \@conds);
1224 }
1225  
1226 sub lct {
1227 2 ▶ return "---" unless $_[0];
Subroutine lct: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 2 2
1228 2 ▶ if ( $_[0] =~ /^\d+(\.\d+)?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+(\.\d+)?$/) { } 2 0 2
1229 2 return strftime("%a, %F %T %z", localtime($_[0]))}
1230 else {
1231 0 return strftime("%a, %F %T %z", localtime(HTTP::Date::str2time($_[0], "GMT")))};
1232 }
1233  
1234 sub tdist {
1235 0 ▶ local($_) = @_;
Subroutine tdist: not called CC=12 SCAR=50.5
1236 0 my $vz = "+";
1237 0 ▶ if ( $_ < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ < 0) 0 0 0
1238 0 $_ = -$_;
1239 0 $vz = "-";
1240 };
1241 0 my @elems = ();
1242  
1243 0 unshift(@elems, ($_ % 60)."s");
1244 0 ▶ $_ = int($_ / 60) or return vzfix($vz, @elems);
Branch: 1 branch
BranchTrueFalseTotal
$_ = int $_ / 60 or return vzfix($vz, @elems) 0 0 0
1245  
1246 0 unshift(@elems, ($_ % 60)."m");
1247 0 ▶ $_ = int($_ / 60) or return vzfix($vz, @elems);
Branch: 1 branch
BranchTrueFalseTotal
$_ = int $_ / 60 or return vzfix($vz, @elems) 0 0 0
1248  
1249 0 unshift(@elems, ($_ % 24)."h");
1250 0 ▶ $_ = int($_ / 24) or return vzfix($vz, @elems);
Branch: 1 branch
BranchTrueFalseTotal
$_ = int $_ / 24 or return vzfix($vz, @elems) 0 0 0
1251  
1252 0 my ($y, $m, $w);
1253 0 ▶ if ( $_ > 365 * 1.5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ > "547.5") 0 0 0
1254 0 $y = int($_ / 365); $_ %= 365};
1255 0 ▶ if ( $_ > 30 * 1.5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ > 45) 0 0 0
1256 0 $m = int($_ / 30); $_ %= 30};
1257 0 ▶ if ( $_ > 7 * 1.5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ > "10.5") 0 0 0
1258 0 $w = int($_ / 7); $_ %= 7};
1259 0 ▶ unshift (@elems, $_."d") if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 0 0 0
1260 0 ▶ unshift (@elems, $w."w") if $w;
Branch: 1 branch
BranchTrueFalseTotal
if $w 0 0 0
1261 0 ▶ unshift (@elems, $m."M") if $m;
Branch: 1 branch
BranchTrueFalseTotal
if $m 0 0 0
1262 0 ▶ unshift (@elems, $y."Y") if $y;
Branch: 1 branch
BranchTrueFalseTotal
if $y 0 0 0
1263 0 return vzfix($vz, @elems);
1264 }
1265  
1266 sub vzfix {
1267 0 ▶ my $vz = shift @_;
Subroutine vzfix: not called CC=1 SCAR=6.9
1268 0 substr($_[0], 0, 0) = $vz;
1269 0 return (@_, "", "", "");
1270 }
1271  
1272  
1273 =head1 AUTHOR
1274  
1275 Thomas Berger
1276 CPAN ID: THB
1277 gymel.com
1278 THB@cpan.org
1279  
1280 =head1 COPYRIGHT
1281  
1282 This program is free software; you can redistribute
1283 it and/or modify it under the same terms as Perl itself.
1284  
1285 The full text of the license can be found in the
1286 LICENSE file included with this module.
1287  
1288  
1289 =head1 SEE ALSO
1290  
1291 SeeAlso::Source::BeaconAggregator::Maintenance
1292 SeeAlso::Source::BeaconAggregator::Publisher
1293  
1294 =cut
1295  
1296 1;
1297  
1298 ### THE END ###
1299  
« blib/lib/SeeAlso/Source/BeaconAggregator/Maintenance.pm ↑ Summary blib/lib/SeeAlso/Source/BeaconAggregator.pm »