lib/Mogura/Scanner/Spool.pm

filter: Statementstmt 100% 47 / 47 Branchbran 58.3% 14 / 24 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 6 totaltotal 77.5% 76 / 98 CC 15 SCAR 15.9
CC
15
Cov
83%
write_record
10.4
artifact
4.1
log
3.1
CRAP 4.9
« lib/Mogura/Server/Results.pm ↑ Summary lib/Mogura/Server/I18N.pm »
1 package Mogura::Scanner::Spool;
2 3 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use Mojo::File qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Mojo::JSON qw(decode_json encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Mogura::Protocol qw(valid_id now artifact_name);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 has 'config';
8  
9 509 ▶sub directory {
Subroutine directory: called CC=2 SCAR=7.1
Pod undocumented
10 509 my ($self, $id) = @_;
11 509 ▶ die 'Invalid scan ID' unless valid_id($id);
Branch: 1 branch
BranchTrueFalseTotal
unless valid_id($id) 0 509 509
12 509 return path($self->config->state, 'spool', $id);
13 }
14  
15 215 ▶sub write_record {
Subroutine write_record: called CC=8 SCAR=23.4
Pod undocumented
16 215 my ($self, $path, $value) = @_;
17 215 my $tmp = "$path.tmp";
18 215 ▶ open my $fh, '>:raw', $tmp or die "Open $tmp: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:raw", $tmp or die "Open ${tmp}: $!" 215 0 215
19 215 ▶ print {$fh} encode_json($value) or die "Write $tmp: $!";
Branch: 1 branch
BranchTrueFalseTotal
print {$fh;} encode_json($value) or die "Write ${tmp}: $!" 215 0 215
20 215 ▶ $fh->flush && $fh->sync or die "Sync $tmp: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->flush and $fh->sync or die "Sync ${tmp}: $!" 215 0 215
Condition33%1/3
$fh->flush and $fh->sync
!ll&&!rl&&r
00215
MC/DC0%0/2
$fh->flush and $fh->sync
$fh->flush $fh->sync
Truth table33%1/3
A and B
A= $fh->flushB= $fh->sync
ABresult
0X0
100
111
21 215 ▶ close $fh or die "Close $tmp: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Close ${tmp}: $!" 215 0 215
22 215 ▶ rename $tmp, $path or die "Publish $path: $!";
Branch: 1 branch
BranchTrueFalseTotal
rename $tmp, $path or die "Publish ${path}: $!" 215 0 215
23 215 ▶ path($path)->dirname->open('<')->sync or die "Sync record directory: $!";
Branch: 1 branch
BranchTrueFalseTotal
path($path)->dirname->open("<")->sync or die "Sync record directory: $!" 215 0 215
24 }
25  
26 206 ▶sub save {
Subroutine save: called CC=1 SCAR=0.0
Pod undocumented
27 206 my ($self, $scan) = @_;
28 206 my $dir = $self->directory($scan->{id})->make_path({mode => 0700});
29 206 $scan->{sequence}++;
30 206 $self->write_record($dir->child('scan.json'), $scan);
31 206 return $scan;
32 }
33  
34 72 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod undocumented
35 72 my ($self, $id) = @_;
36 72 my $file = $self->directory($id)->child('scan.json');
37 72 ▶ return unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 25 47 72
38 47 return decode_json($file->slurp);
39 }
40  
41 58 ▶sub artifact {
Subroutine artifact: called CC=4 SCAR=14.1
Pod undocumented
42 58 my ($self, $id, $kind) = @_;
43 58 ▶ my $name = artifact_name($kind) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $name = artifact_name($kind) or return 58 0 58
44 58 my $file = $self->directory($id)->child($name);
45 58 ▶ return -f $file && !-l $file ? $file : undef;
Branch: 1 branch
BranchTrueFalseTotal
-f $file && !(-l $file) ? : 43 15 58
Condition66%2/3
-f $file and not -l $file
!ll&&!rl&&r
15043
MC/DC50%1/2
-f $file and not -l $file
-f $file not -l $file
Truth table66%2/3
A and not(B)
A= -f $fileB= not -l $file
ABresult
0X0
100
111
46 }
47  
48 116 ▶sub log {
Subroutine log: called CC=3 SCAR=11.3
Pod undocumented
49 116 my ($self, $id, $message) = @_;
50 116 ▶ open my $fh, '>>:encoding(UTF-8)', $self->directory($id)->child('scan.log') or die "Log: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>:encoding(UTF-8)", $self->directory($id)->child("scan.log") or die "Log: $!" 116 0 116
51 116 print {$fh} now() . " $message\n";
52 116 ▶ close $fh or die "Log: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Log: $!" 116 0 116
53 }
54 3 1;
« lib/Mogura/Server/Results.pm ↑ Summary lib/Mogura/Server/I18N.pm »