| 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
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 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
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
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 107 | ▶ | if ( $hostname eq '<local>' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 52 | 18 | ▶ | my $cmdb = $self->get( undef, $server ) || undef; | ||||||||||||||||||
|
Condition50%1/2
$self->get(undef, $server) || undef
MC/DC0%0/1
$self->get(undef, $server) || undef
$self->get(undef, $server)
Truth table50%1/2
A
A= $self->get(undef, $server)
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 73 | 6 | $self->{__cache} = Rex::get_cache(); | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 121 | return $self->{__cache}; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 6 | 1; | |||||||||||||||||||