| 1 | package Langertha::Skeid::UsageStore; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 115 | our $VERSION = '0.004'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Usage event sink - config normalization and backend factory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 115 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 115 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 115 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 155 | ▶ | sub normalize_config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_config: called CC=50 SCAR=44.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 155 | my ($class, $cfg, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 155 | ▶ | $cfg ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cfg ||= {}
MC/DC0%0/1
$cfg ||= {}
$cfg
Truth table50%1/2
A
A= $cfg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 155 | ▶ | croak 'usage_store must be a hashref' unless ref($cfg) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 155 | ▶ | my $backend = lc($cfg->{backend} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cfg->{"backend"} // ""
MC/DC100%1/1
$cfg->{"backend"} // ""
$cfg->{"backend"}
Truth table100%2/2
A
A= $cfg->{"backend"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 155 | ▶ | $backend = 'sqlite' if !$backend && (defined($cfg->{sqlite_path}) || defined($cfg->{path}) || defined($cfg->{db_path})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not $backend and defined $cfg->{"sqlite_path"} || defined $cfg->{"path"} || defined $cfg->{"db_path"}
defined $cfg->{"sqlite_path"} or defined $cfg->{"path"} or defined $cfg->{"db_path"}
defined $cfg->{"sqlite_path"} or defined $cfg->{"path"}
MC/DC50%2/4
not $backend and defined $cfg->{"sqlite_path"} || defined $cfg->{"path"} || defined $cfg->{"db_path"}
not $backend
defined $cfg->{"sqlite_path"}
defined $cfg->{"path"}
defined $cfg->{"db_path"}
Truth table60%3/5
not(A) and B or C or D
A= not $backendB= defined $cfg->{"sqlite_path"}C= defined $cfg->{"path"}D= defined $cfg->{"db_path"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 155 | ▶ | $backend = 'postgresql' if !$backend && defined($cfg->{dsn}) && $cfg->{dsn} =~ /^dbi:Pg:/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $backend and defined $cfg->{"dsn"} and $cfg->{"dsn"} =~ /^dbi:Pg:/i
not $backend and defined $cfg->{"dsn"}
MC/DC33%1/3
not $backend and defined $cfg->{"dsn"} and $cfg->{"dsn"} =~ /^dbi:Pg:/i
not $backend
defined $cfg->{"dsn"}
$cfg->{"dsn"} =~ /^dbi:Pg:/i
Truth table50%2/4
not(A) and B and C
A= not $backendB= defined $cfg->{"dsn"}C= $cfg->{"dsn"} =~ /^dbi:Pg:/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 155 | ▶ | $backend = 'jsonlog' if !$backend && defined($cfg->{log_path}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $backend and defined $cfg->{"log_path"}
MC/DC0%0/2
not $backend and defined $cfg->{"log_path"}
not $backend
defined $cfg->{"log_path"}
Truth table33%1/3
not(A) and B
A= not $backendB= defined $cfg->{"log_path"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 155 | ▶ | $backend = 'sqlite' unless length $backend; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 155 | ▶ | $backend = 'postgresql' if $backend =~ /^postgres/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 155 | ▶ | $backend = 'jsonlog' if $backend =~ /^json/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 155 | ▶ | if ($backend eq 'sqlite') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 39 | ▶ | my $path = $cfg->{sqlite_path} // $cfg->{path} // $cfg->{db_path} // $opts{default_sqlite_path}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition44%4/9
(($cfg->{"sqlite_path"} // $cfg->{"path"}) // $cfg->{"db_path"}) // $opts{"default_sqlite_path"}
($cfg->{"sqlite_path"} // $cfg->{"path"}) // $cfg->{"db_path"}
$cfg->{"sqlite_path"} // $cfg->{"path"}
MC/DC0%0/4
(($cfg->{"sqlite_path"} // $cfg->{"path"}) // $cfg->{"db_path"}) // $opts{"default_sqlite_path"}
$cfg->{"sqlite_path"}
$cfg->{"path"}
$cfg->{"db_path"}
$opts{"default_sqlite_path"}
Truth table40%2/5
A // B // C // D
A= $cfg->{"sqlite_path"}B= $cfg->{"path"}C= $cfg->{"db_path"}D= $opts{"default_sqlite_path"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 39 | ▶ | if (!defined($path) || !length($path)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $path and length $path
MC/DC0%0/2
defined $path and length $path
defined $path
length $path
Truth table33%1/3
A and B
A= defined $pathB= length $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | croak 'usage_store.sqlite_path (or path/db_path) is required for sqlite backend'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | backend => 'sqlite', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | dsn => "dbi:SQLite:dbname=$path", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | user => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | password => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | schema_file => ($cfg->{schema_file} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 39 | ▶ | auto_migrate => exists($cfg->{auto_migrate}) ? ($cfg->{auto_migrate} ? 1 : 0) : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
$cfg->{"schema_file"} // ""
MC/DC100%1/1
$cfg->{"schema_file"} // ""
$cfg->{"schema_file"}
Truth table100%2/2
A
A= $cfg->{"schema_file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | flush_interval_ms => $class->_flush_interval_ms($cfg), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | spool_dir => $class->_spool_dir($cfg), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 116 | ▶ | if ($backend eq 'postgresql') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 75 | my $dsn = $cfg->{dsn}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 75 | ▶ | if (!defined($dsn) || !length($dsn)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $dsn and length $dsn
MC/DC50%1/2
defined $dsn and length $dsn
defined $dsn
length $dsn
Truth table66%2/3
A and B
A= defined $dsnB= length $dsn
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | ▶ | my $host = $cfg->{host} // '127.0.0.1'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cfg->{"host"} // "127.0.0.1"
MC/DC0%0/1
$cfg->{"host"} // "127.0.0.1"
$cfg->{"host"}
Truth table50%1/2
A
A= $cfg->{"host"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | ▶ | my $port = $cfg->{port} // 5432; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cfg->{"port"} // 5432
MC/DC100%1/1
$cfg->{"port"} // 5432
$cfg->{"port"}
Truth table100%2/2
A
A= $cfg->{"port"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | my $name = $cfg->{dbname} // $cfg->{database} // 'skeid'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
($cfg->{"dbname"} // $cfg->{"database"}) // "skeid"
$cfg->{"dbname"} // $cfg->{"database"}
MC/DC0%0/2
($cfg->{"dbname"} // $cfg->{"database"}) // "skeid"
$cfg->{"dbname"}
$cfg->{"database"}
Truth table33%1/3
A // B
A= $cfg->{"dbname"}B= $cfg->{"database"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | $dsn = "dbi:Pg:dbname=$name;host=$host;port=$port"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 75 | ▶ | my $password = defined($cfg->{password}) ? $cfg->{password} : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 75 | ▶ | if (!length($password) && defined($cfg->{password_env}) && length($cfg->{password_env})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not length $password and defined $cfg->{"password_env"} and length $cfg->{"password_env"}
not length $password and defined $cfg->{"password_env"}
MC/DC66%2/3
not length $password and defined $cfg->{"password_env"} and length $cfg->{"password_env"}
not length $password
defined $cfg->{"password_env"}
length $cfg->{"password_env"}
Truth table75%3/4
not(A) and B and C
A= not length $passwordB= defined $cfg->{"password_env"}C= length $cfg->{"password_env"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | ▶ | $password = $ENV{$cfg->{password_env}} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{$cfg->{"password_env"}} // ""
MC/DC100%1/1
$ENV{$cfg->{"password_env"}} // ""
$ENV{$cfg->{"password_env"}}
Truth table100%2/2
A
A= $ENV{$cfg->{"password_env"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | backend => 'postgresql', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | path => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | dsn => $dsn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | user => ($cfg->{user} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | password => $password, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | schema_file => ($cfg->{schema_file} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 75 | ▶ | auto_migrate => exists($cfg->{auto_migrate}) ? ($cfg->{auto_migrate} ? 1 : 0) : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition75%3/4
$cfg->{"user"} // ""
$cfg->{"schema_file"} // ""
MC/DC100%1/1
$cfg->{"user"} // ""
$cfg->{"user"}
MC/DC0%0/1
$cfg->{"schema_file"} // ""
$cfg->{"schema_file"}
Truth table100%2/2
A
A= $cfg->{"user"}
Truth table50%1/2
A
A= $cfg->{"schema_file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | flush_interval_ms => $class->_flush_interval_ms($cfg), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | spool_dir => $class->_spool_dir($cfg), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 41 | ▶ | if ($backend eq 'jsonlog') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 41 | ▶ | my $path = $cfg->{log_path} // $cfg->{path} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
($cfg->{"log_path"} // $cfg->{"path"}) // ""
$cfg->{"log_path"} // $cfg->{"path"}
MC/DC0%0/2
($cfg->{"log_path"} // $cfg->{"path"}) // ""
$cfg->{"log_path"}
$cfg->{"path"}
Truth table66%2/3
A // B
A= $cfg->{"log_path"}B= $cfg->{"path"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 41 | ▶ | croak 'usage_store.log_path (or path) is required for jsonlog backend' unless length $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 41 | ▶ | my $mode = $cfg->{mode} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cfg->{"mode"} // ""
MC/DC100%1/1
$cfg->{"mode"} // ""
$cfg->{"mode"}
Truth table100%2/2
A
A= $cfg->{"mode"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 41 | ▶ | if (!length($mode)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 21 | ▶ | $mode = (-d $path || $path =~ m{/$}) ? 'dir' : 'file'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-d $path or $path =~ m[/$]
MC/DC100%2/2
-d $path or $path =~ m[/$]
-d $path
$path =~ m[/$]
Truth table100%3/3
A or B
A= -d $pathB= $path =~ m[/$]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | backend => 'jsonlog', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | mode => $mode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 41 | ▶ | fsync => ($cfg->{fsync} ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | croak "unsupported usage_store backend '$backend'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # Write-behind for the DBI backends (skeid k78). 0 -- the default -- is the synchronous write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # every deployment had before; anything else widens the loss window, so it has to be asked for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # with a number that means what it says. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 114 | ▶ | sub _flush_interval_ms { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flush_interval_ms: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 114 | my ($class, $cfg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 114 | ▶ | my $ms = $cfg->{flush_interval_ms} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cfg->{"flush_interval_ms"} // 0
MC/DC100%1/1
$cfg->{"flush_interval_ms"} // 0
$cfg->{"flush_interval_ms"}
Truth table100%2/2
A
A= $cfg->{"flush_interval_ms"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 114 | ▶ | croak 'usage_store.flush_interval_ms must be a whole number of milliseconds (0 = write each event at once)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | unless $ms =~ /\A\d+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 111 | return 0 + $ms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # The usage spool of the DBI backends (skeid k110, ADR 0027). Empty -- the default -- keeps the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # behavior from before: what the database cannot take is reported lost. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 111 | ▶ | sub _spool_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_spool_dir: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 111 | my ($class, $cfg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 111 | ▶ | my $dir = $cfg->{spool_dir} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cfg->{"spool_dir"} // ""
MC/DC100%1/1
$cfg->{"spool_dir"} // ""
$cfg->{"spool_dir"}
Truth table100%2/2
A
A= $cfg->{"spool_dir"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 111 | ▶ | croak 'usage_store.spool_dir must be a directory path' if ref $dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 110 | return "$dir"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 71 | ▶ | sub for_config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
for_config: called CC=17 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 71 | my ($class, $cfg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 71 | ▶ | return unless ref($cfg) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 71 | ▶ | my $backend = $cfg->{backend} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cfg->{"backend"} // ""
MC/DC0%0/1
$cfg->{"backend"} // ""
$cfg->{"backend"}
Truth table50%1/2
A
A= $cfg->{"backend"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 71 | ▶ | return unless length $backend; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 71 | ▶ | if ($backend eq 'jsonlog') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 38 | require Langertha::Skeid::UsageStore::JsonLog; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | return Langertha::Skeid::UsageStore::JsonLog->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | path => ($cfg->{path} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | mode => ($cfg->{mode} // 'dir'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 38 | ▶ | fsync => ($cfg->{fsync} ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$cfg->{"path"} // ""
$cfg->{"mode"} // "dir"
MC/DC0%0/1
$cfg->{"path"} // ""
$cfg->{"path"}
MC/DC0%0/1
$cfg->{"mode"} // "dir"
$cfg->{"mode"}
Truth table50%1/2
A
A= $cfg->{"path"}
Truth table50%1/2
A
A= $cfg->{"mode"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 33 | require Langertha::Skeid::UsageStore::DBI; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | return Langertha::Skeid::UsageStore::DBI->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | backend => $backend, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | dsn => ($cfg->{dsn} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | user => ($cfg->{user} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | password => ($cfg->{password} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | path => ($cfg->{path} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | schema_file => ($cfg->{schema_file} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | auto_migrate => (exists($cfg->{auto_migrate}) ? ($cfg->{auto_migrate} ? 1 : 0) : 1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | flush_interval_ms => ($cfg->{flush_interval_ms} // 0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 33 | ▶ | spool_dir => ($cfg->{spool_dir} // q{}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%7/14
$cfg->{"dsn"} // ""
$cfg->{"user"} // ""
$cfg->{"password"} // ""
$cfg->{"path"} // ""
$cfg->{"schema_file"} // ""
$cfg->{"flush_interval_ms"} // 0
$cfg->{"spool_dir"} // ""
MC/DC0%0/1
$cfg->{"dsn"} // ""
$cfg->{"dsn"}
MC/DC0%0/1
$cfg->{"user"} // ""
$cfg->{"user"}
MC/DC0%0/1
$cfg->{"password"} // ""
$cfg->{"password"}
MC/DC0%0/1
$cfg->{"path"} // ""
$cfg->{"path"}
MC/DC0%0/1
$cfg->{"schema_file"} // ""
$cfg->{"schema_file"}
MC/DC0%0/1
$cfg->{"flush_interval_ms"} // 0
$cfg->{"flush_interval_ms"}
MC/DC0%0/1
$cfg->{"spool_dir"} // ""
$cfg->{"spool_dir"}
Truth table50%1/2
A
A= $cfg->{"dsn"}
Truth table50%1/2
A
A= $cfg->{"user"}
Truth table50%1/2
A
A= $cfg->{"password"}
Truth table50%1/2
A
A= $cfg->{"path"}
Truth table50%1/2
A
A= $cfg->{"schema_file"}
Truth table50%1/2
A
A= $cfg->{"flush_interval_ms"}
Truth table50%1/2
A
A= $cfg->{"spool_dir"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 3644 | ▶ | sub num { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 3644 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 3644 | ▶ | return 0 unless defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 2923 | return 0 + $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 134 | ▶ | sub read_text_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_text_file: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 134 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 134 | ▶ | open my $fh, '<', $path or die "Cannot open $path: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 134 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 134 | my $text = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 134 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 134 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 115 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||