lib/Rex/Inventory/SMBios/Section.pm

filter: Statementstmt 52.1% 48 / 92 Branchbran 25.0% 3 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 57.8% 11 / 19 Podpod 0.0% 0 / 8 totaltotal 44.6% 62 / 139 CC 12 SCAR 23.5
CC
12
Cov
47%
_search_for
42.0
new
6.0
get_index
6.0
CRAP 10.5
« lib/Rex/Virtualization/Lxc/destroy.pm ↑ Summary lib/Rex/Virtualization/Lxc/info.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Inventory::SMBios::Section;
6  
7 39 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 39 our $VERSION = '1.16.1'; # VERSION
11  
12 39 require Exporter;
13 39 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 39 ▶use vars qw($SECTION @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 39 @EXPORT = qw(section);
17 39 $SECTION = {};
18  
19 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
20 0 my $that = shift;
21 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
22 0 my $self = {@_};
23  
24 0 bless( $self, $proto );
25  
26 0 return $self;
27 }
28  
29 234 ▶sub section {
Subroutine section: called CC=1 SCAR=0.0
Pod undocumented
30 234 my ( $class, $section ) = @_;
31 234 $SECTION->{$class} = $section;
32 }
33  
34 234 ▶sub has {
Subroutine has: called CC=4 SCAR=14.1
Pod undocumented
35 234 my ( $class, $item, $is_array ) = @_;
36  
37 234 ▶ unless ( ref($item) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $item eq "ARRAY") 0 234 234
38 0 my $_tmp = $item;
39 0 $item = [$_tmp];
40 }
41  
42 39 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 234 for my $_itm ( @{$item} ) {
45 1053 my ( $itm, $from );
46  
47 1053 ▶ if ( ref($_itm) eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_itm eq 'HASH') { } 390 663 1053
48 390 $itm = $_itm->{key};
49 390 $from = $_itm->{from};
50 }
51 else {
52 663 $itm = $_itm;
53 663 $from = $_itm;
54 }
55 1053 $itm =~ s/[^a-zA-Z0-9_]+/_/g;
56 1053 ▶ *{"${class}::get_\L$itm"} = sub {
Subroutine __ANON__: not called CC=1 SCAR=2.6
57 0 my $self = shift;
58 0 return $self->get( $from, $is_array );
59 1053 };
60  
61 1053 push( @{"${class}::items"}, "\L$itm" );
62 }
63  
64 39 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 }
66  
67 0 ▶sub dmi {
Subroutine dmi: not called CC=1 SCAR=6.9
Pod undocumented
68  
69 0 my ($self) = @_;
70 0 return $self->{"dmi"};
71  
72 }
73  
74 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod undocumented
75  
76 0 my ( $self, $key, $is_array ) = @_;
77 0 return $self->_search_for( $key, $is_array );
78  
79 }
80  
81 0 ▶sub get_all {
Subroutine get_all: not called CC=2 SCAR=9.2
Pod undocumented
82  
83 0 my ($self) = @_;
84  
85 39 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 0 my $r = ref($self);
87  
88 39 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
89 0 my @items = @{"${r}::items"};
90 39 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 0 my $ret = {};
93 0 for my $itm (@items) {
94 0 my $f = "get_$itm";
95 0 $ret->{$itm} = $self->$f();
96 }
97  
98 0 return $ret;
99  
100 }
101  
102 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=6.9
Pod undocumented
103  
104 0 my ($self) = @_;
105  
106 0 require Data::Dumper;
107 print Data::Dumper::Dumper(
108 0 $self->dmi->get_tree( $SECTION->{ ref($self) } ) );
109  
110 }
111  
112 0 ▶sub _search_for {
Subroutine _search_for: not called CC=6 SCAR=37.4
113 0 my ( $self, $key, $is_array ) = @_;
114  
115 0 ▶ unless ( $self->dmi->get_tree( $SECTION->{ ref($self) } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dmi->get_tree($$Rex::Inventory::SMBios::Section::SECTION{ref $self})) 0 0 0
116  
117 #die $SECTION->{ref($self)} . " not supported";
118 0 return;
119 }
120  
121 0 my $idx = 0;
122 0 for my $entry ( @{ $self->dmi->get_tree( $SECTION->{ ref($self) } ) } ) {
123 0 my ($_key) = keys %{$entry};
124 0 ▶ if ($is_array) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_array) 0 0 0
125 0 ▶ if ( $idx != $self->get_index() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx != $self->get_index) 0 0 0
126 0 ++$idx;
127 0 next;
128 }
129 }
130  
131 0 ▶ if ( exists $entry->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry->{$key}) { } 0 0 0
132 0 return $entry->{$key};
133 }
134 else {
135 0 return "";
136 }
137 0 ++$idx;
138 }
139  
140 0 return "";
141 }
142  
143 0 ▶sub get_index {
Subroutine get_index: not called CC=2 SCAR=17.9
Pod undocumented
144  
145 0 my ($self) = @_;
146 0 ▶ return $self->{"index"} || 0;
Condition0%0/2
$self->{'index'} || 0
l!l
00
MC/DC0%0/1
$self->{'index'} || 0
$self->{'index'}
Truth table0%0/2
A
A= $self->{'index'}
Aresult
11
00
147  
148 }
149  
150 39 1;
« lib/Rex/Virtualization/Lxc/destroy.pm ↑ Summary lib/Rex/Virtualization/Lxc/info.pm »