| 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
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 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'
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')
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | ▶ | if ( exists $ENV{REX_CACHE_PATH} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 0 | $path = $ENV{REX_CACHE_PATH}; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | ▶ | if ( !-d $path ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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'
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')
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | if ( exists $ENV{REX_CACHE_PATH} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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; | |||||||||||||||||||