lib/Rex/CMDB/Base.pm

filter: Statementstmt 88.6% 39 / 44 Branchbran 100% 8 / 8 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 1 totaltotal 77.9% 60 / 77 CC 8 SCAR 8.9
CC
8
Cov
83%
new
6.0
__get_hostname_for
3.0
__warm_up_cache_for
3.0
CRAP 2.4
« lib/Rex/Service/OpenBSD.pm ↑ Summary lib/Rex/Test/Base/has_output.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::CMDB::Base;
6  
7 6 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 our $VERSION = '1.16.1'; # VERSION
11  
12 6 ▶use Rex::Helper::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Rex::Hardware;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Rex::Hardware::Host;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my $that = shift;
18 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
19 0 my $self = {@_};
20  
21 0 bless( $self, $proto );
22  
23 0 return $self;
24 }
25  
26 156 ▶sub _parse_path {
Subroutine _parse_path: called CC=1 SCAR=0.0
27 156 my ( $self, $path, $mapping ) = @_;
28  
29 156 return parse_path( $path, $mapping );
30 }
31  
32 107 ▶sub __get_hostname_for {
Subroutine __get_hostname_for: called CC=3 SCAR=11.0
33 107 my ( $self, $server ) = @_;
34  
35 107 ▶ my $hostname = $server // Rex::get_current_connection()->{conn}->server->to_s;
Condition66%2/3
$server // Rex::get_current_connection()->{"conn"}->server->to_s
l!l&&r!l&&!r
78290
MC/DC0%0/2
$server // Rex::get_current_connection()->{"conn"}->server->to_s
$server Rex::get_current_connection()->{"conn"}->server->to_s
Truth table66%2/3
A // B
A= $serverB= Rex::get_current_connection()->{"conn"}->server->to_s
ABresult
1X1
011
000
36  
37 107 ▶ if ( $hostname eq '<local>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hostname eq "<local>") 29 78 107
38 29 my %hw_info = Rex::Hardware->get('Host');
39 29 $hostname = $hw_info{Host}{hostname};
40 }
41  
42 107 return $hostname;
43 }
44  
45 25 ▶sub __warm_up_cache_for {
Subroutine __warm_up_cache_for: called CC=3 SCAR=11.0
46 25 my ( $self, $server ) = @_;
47  
48 25 $server = $self->__get_hostname_for($server);
49 25 my $cache_key = $self->__cache_key("cmdb/$self/$server");
50  
51 25 ▶ if ( !$self->__cache->valid($cache_key) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->__cache->valid($cache_key)) 18 7 25
52 18 ▶ my $cmdb = $self->get( undef, $server ) || undef;
Condition50%1/2
$self->get(undef, $server) || undef
l!l
180
MC/DC0%0/1
$self->get(undef, $server) || undef
$self->get(undef, $server)
Truth table50%1/2
A
A= $self->get(undef, $server)
Aresult
11
00
53 18 $self->__cache->set( $cache_key, $cmdb );
54 }
55  
56 25 return $self->__cache;
57 }
58  
59 78 ▶sub __cache_key {
Subroutine __cache_key: called CC=2 SCAR=6.9
60 78 my ( $self, $key ) = @_;
61  
62 78 ▶ if ( defined $key ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 25 53 78
63 25 $self->{__cache_key} = $key;
64 }
65  
66 78 return $self->{__cache_key};
67 }
68  
69 121 ▶sub __cache {
Subroutine __cache: called CC=2 SCAR=6.9
70 121 my ($self) = @_;
71  
72 121 ▶ if ( !defined $self->{__cache} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"__cache"}) 6 115 121
73 6 $self->{__cache} = Rex::get_cache();
74 }
75  
76 121 return $self->{__cache};
77 }
78  
79 6 1;
« lib/Rex/Service/OpenBSD.pm ↑ Summary lib/Rex/Test/Base/has_output.pm »