CLI/Config.pm

filter: Statementstmt 100% 23 / 23 Branchbran 100% 6 / 6 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 84.0% 37 / 44 CC 6 SCAR 9.0
CC
6
Cov
91%
__ANON__
4.1
load
3.0
save
2.0
CRAP 2.4
« CLI/Client.pm ↑ Summary CLI/Progress.pm »
1 # SPDX-FileCopyrightText: SUSE LLC
2 # SPDX-License-Identifier: GPL-2.0-or-later
3  
4 package Cavil::CLI::Config;
5 7 ▶use Mojo::Base -base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use Mojo::File qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Mojo::JSON qw(from_json to_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Persistent per-user settings (the Cavil URL and API token) so they need not be passed on every run. Under
11 # XDG_CONFIG_HOME, and written 0600 because it holds a credential.
12  
13 7 ▶has dir => sub { path($ENV{XDG_CONFIG_HOME} || (($ENV{HOME} // '.') . '/.config'))->child('cavil-cli') };
Subroutine __ANON__: called CC=3 SCAR=14.2
Condition25%1/4
$ENV{'XDG_CONFIG_HOME'} || ($ENV{'HOME'} // '.') . '/.config'
l!l
70
$ENV{"HOME"} // "."
l!l
00
MC/DC0%0/1
$ENV{'XDG_CONFIG_HOME'} || ($ENV{'HOME'} // '.') . '/.config'
$ENV{'XDG_CONFIG_HOME'}
Truth table50%1/2
A
A= $ENV{'XDG_CONFIG_HOME'}
Aresult
11
00
14  
15 14 ▶sub file ($self) { return $self->dir->child('config.json') }
Subroutine file: called CC=1 SCAR=0.0
Pod undocumented
16  
17 6 ▶sub load ($self) {
Subroutine load: called CC=3 SCAR=11.0
Pod undocumented
18 6 my $file = $self->file;
19 6 ▶ return {} unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 2 4 6
20 4 my $data = eval { from_json($file->slurp) };
21 4 ▶ return ref $data eq 'HASH' ? $data : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $data eq 'HASH' ? : 3 1 4
22 }
23  
24 3 ▶sub save ($self, $data) {
Subroutine save: called CC=2 SCAR=6.9
Pod undocumented
25 3 ▶ $self->dir->make_path unless -d $self->dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->dir 2 1 3
26 3 my $file = $self->file;
27 3 $file->spew(to_json($data));
28 3 chmod 0600, $file->to_string;
29 3 return $self;
30 }
31  
32 7 1;
« CLI/Client.pm ↑ Summary CLI/Progress.pm »