lib/Rex/Inventory/Hal/Object.pm

filter: Statementstmt 48.3% 30 / 62 Branchbran 16.6% 2 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 5 totaltotal 40.6% 39 / 96 CC 11 SCAR 22.3
CC
11
Cov
42%
__ANON__
25.8
get
12.0
new
6.0
CRAP 9.3
« lib/Rex/Virtualization/LibVirt/iflist.pm ↑ Summary lib/Rex/Helper/Rexfile/ParamLookup.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Inventory::Hal::Object;
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  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
13 0 my $that = shift;
14 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
15 0 my $self = {@_};
16  
17 0 bless( $self, $proto );
18  
19 0 return $self;
20 }
21  
22 3 ▶sub has {
Subroutine has: called CC=3 SCAR=14.4
Pod undocumented
23  
24 3 my ( $class, $keys ) = @_;
25 0 for my $k ( @{$keys} ) {
26 13 my $key = $k->{key};
27 13 my $accessor = $k->{accessor};
28 13 my $overwrite = $k->{overwrite};
29  
30 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 13 ▶ if ( !$overwrite ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($overwrite) 12 1 13
32 12 ▶ *{"${class}::get_$accessor"} = sub {
Subroutine __ANON__: not called CC=5 SCAR=32.5
33 0 my ($self) = @_;
34 0 ▶ if ( $k->{"parent"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k->{'parent'}) { } 0 0 0
35 0 return $self->parent()->get($key);
36 }
37 else {
38 0 ▶ if ( ref($key) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $key eq 'ARRAY') { } 0 0 0
39 0 for my $_k ( @{$key} ) {
40 0 ▶ if ( my $ret = $self->get($_k) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ret = $self->get($_k)) 0 0 0
41 0 return $ret;
42 }
43  
44 0 return "";
45 }
46 }
47 else {
48 0 return $self->get($key);
49 }
50 }
51 12 };
52  
53 }
54 13 push( @{"${class}::items"}, $k );
55  
56 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 }
58  
59 }
60  
61 # returns the parent of the current object
62 0 ▶sub parent {
Subroutine parent: not called CC=1 SCAR=6.9
Pod undocumented
63  
64 0 my ($self) = @_;
65 0 return $self->{"hal"}->get_object_by_udi( $self->{'info.parent'} );
66  
67 }
68  
69 0 ▶sub get {
Subroutine get: not called CC=3 SCAR=24.8
Pod undocumented
70  
71 0 my ( $self, $key ) = @_;
72  
73 0 ▶ if ( ref( $self->{$key} ) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$key} eq "ARRAY") 0 0 0
74 0 return @{ $self->{$key} };
75 }
76  
77 return exists $self->{$key}
78 0 ▶ ? $self->{$key}
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$key} ? : 0 0 0
79 : "";
80  
81 }
82  
83 0 ▶sub get_all {
Subroutine get_all: not called CC=2 SCAR=10.5
Pod undocumented
84  
85 0 my ($self) = @_;
86  
87 0 my $r = ref($self);
88  
89 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 0 my @items = @{"${r}::items"};
91 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93 0 my $ret;
94 0 for my $itm (@items) {
95 0 my $f = "get_" . $itm->{"accessor"};
96 0 $ret->{ $itm->{"accessor"} } = $self->$f();
97 }
98  
99 0 return $ret;
100 }
101  
102 1 1;
« lib/Rex/Virtualization/LibVirt/iflist.pm ↑ Summary lib/Rex/Helper/Rexfile/ParamLookup.pm »