lib/Rex/Interface/Cache/YAML.pm

filter: Statementstmt 37.2% 16 / 43 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 3 totaltotal 26.6% 20 / 75 CC 9 SCAR 27.4
CC
9
Cov
27%
save
30.0
load
20.0
new
6.0
CRAP 15.5
« lib/Rex/Cron.pm ↑ Summary lib/Rex/Box/Docker.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Interface::Cache::YAML;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Rex::Interface::Cache::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use base qw(Rex::Interface::Cache::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = '1.16.1'; # VERSION
13  
14 1 require Rex::Commands;
15 1 require Rex::Commands::Fs;
16 1 require YAML;
17  
18 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
19 0 my $that = shift;
20 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
21 0 my $self = $proto->SUPER::new(@_);
22  
23 0 bless( $self, $proto );
24  
25 0 return $self;
26 }
27  
28 0 ▶sub save {
Subroutine save: not called CC=5 SCAR=34.0
Pod undocumented
29 0 my ($self) = @_;
30  
31 0 ▶ my $path = Rex::Commands::get("cache_path") || ".cache";
Condition0%0/2
Rex::Commands::get('cache_path') || '.cache'
l!l
00
MC/DC0%0/1
Rex::Commands::get('cache_path') || '.cache'
Rex::Commands::get('cache_path')
Truth table0%0/2
A
A= Rex::Commands::get('cache_path')
Aresult
11
00
32  
33 0 ▶ if ( exists $ENV{REX_CACHE_PATH} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"REX_CACHE_PATH"}) 0 0 0
34 0 $path = $ENV{REX_CACHE_PATH};
35 }
36  
37 0 ▶ if ( !-d $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $path) 0 0 0
38 0 ▶ Rex::Commands::LOCAL( sub { mkdir $path } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 }
40  
41 0 ▶ open( my $fh, ">", "$path/" . Rex::Commands::connection->server . ".yml" )
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "$path/" . Rex::Commands::connection()->server . '.yml' or die $! 0 0 0
42 or die($!);
43 0 print $fh YAML::Dump( $self->{__data__} );
44 0 close($fh);
45 }
46  
47 0 ▶sub load {
Subroutine load: not called CC=4 SCAR=30.0
Pod undocumented
48 0 my ($self) = @_;
49  
50 0 ▶ my $path = Rex::Commands::get("cache_path") || ".cache";
Condition0%0/2
Rex::Commands::get('cache_path') || '.cache'
l!l
00
MC/DC0%0/1
Rex::Commands::get('cache_path') || '.cache'
Rex::Commands::get('cache_path')
Truth table0%0/2
A
A= Rex::Commands::get('cache_path')
Aresult
11
00
51  
52 0 ▶ if ( exists $ENV{REX_CACHE_PATH} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"REX_CACHE_PATH"}) 0 0 0
53 0 $path = $ENV{REX_CACHE_PATH};
54 }
55  
56 0 my $file_name = "$path/" . Rex::Commands::connection->server . ".yml";
57  
58 0 ▶ if ( !-f $file_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file_name) 0 0 0
59  
60 # no cache found
61 0 return;
62 }
63  
64 0 my $yaml = eval { local ( @ARGV, $/ ) = ($file_name); <>; };
65  
66 0 $yaml .= "\n";
67  
68 0 $self->{__data__} = YAML::Load($yaml);
69 }
70  
71 1 1;
« lib/Rex/Cron.pm ↑ Summary lib/Rex/Box/Docker.pm »