| 1 | # | ||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Rex::Inventory::DMIDecode::Section; | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 40 | ▶ | use v5.14.4; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 40 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 40 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 40 | require Exporter; | |||||||||||||||||||
| 13 | 40 | ▶ | use Symbol; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 40 | ▶ | use base qw(Exporter); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 40 | ▶ | use vars qw($SECTION @EXPORT); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 40 | @EXPORT = qw(section); | |||||||||||||||||||
| 18 | 40 | $SECTION = {}; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 69 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||
| 21 | 69 | my $that = shift; | |||||||||||||||||||
| 22 | 69 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||
|
Condition33%1/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table33%1/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 23 | 69 | my $self = {@_}; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 69 | bless( $self, $proto ); | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 69 | return $self; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 240 | ▶ | sub section { | ||||||||||||||||||
|
Subroutine
section: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 31 | 240 | my ( $class, $section ) = @_; | |||||||||||||||||||
| 32 | 240 | $SECTION->{$class} = $section; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 240 | ▶ | sub has { | ||||||||||||||||||
|
Subroutine
has: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||
| 36 | 240 | my ( $class, $item, $is_array ) = @_; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 240 | ▶ | unless ( ref($item) eq "ARRAY" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 0 | my $_tmp = $item; | |||||||||||||||||||
| 40 | 0 | $item = [$_tmp]; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 240 | for my $itm ( @{$item} ) { | |||||||||||||||||||
| 44 | 1400 | my $o_itm = $itm; | |||||||||||||||||||
| 45 | 1400 | $itm =~ s/[^a-zA-Z0-9_]+/_/g; | |||||||||||||||||||
| 46 | 1400 | my $ref_to_item_getter = qualify_to_ref( "get_\L$itm", $class ); | |||||||||||||||||||
| 47 | 1400 | ▶ | *{$ref_to_item_getter} = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 48 | 82 | my $self = shift; | |||||||||||||||||||
| 49 | 82 | return $self->get( $o_itm, $is_array ); | |||||||||||||||||||
| 50 | 1400 | }; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 1400 | my $ref_to_items = qualify_to_ref( 'items', $class ); | |||||||||||||||||||
| 53 | 1400 | push( @{ *{$ref_to_items} }, "\L$itm" ); | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 113 | ▶ | sub dmi { | ||||||||||||||||||
|
Subroutine
dmi: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 113 | my ($self) = @_; | |||||||||||||||||||
| 60 | 113 | return $self->{"dmi"}; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 82 | ▶ | sub get { | ||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 82 | my ( $self, $key, $is_array ) = @_; | |||||||||||||||||||
| 67 | 82 | return $self->_search_for( $key, $is_array ); | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 1 | ▶ | sub get_all { | ||||||||||||||||||
|
Subroutine
get_all: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | my ($self) = @_; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 40 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 76 | 1 | my $r = ref($self); | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 1 | my $ref_to_items = qualify_to_ref( 'items', $r ); | |||||||||||||||||||
| 79 | 1 | my @items = @{ *{$ref_to_items} }; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 1 | my $ret = {}; | |||||||||||||||||||
| 82 | 1 | for my $itm (@items) { | |||||||||||||||||||
| 83 | 4 | my $f = "get_$itm"; | |||||||||||||||||||
| 84 | 4 | $ret->{$itm} = $self->$f(); | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 1 | return $ret; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | ▶ | sub dump { | ||||||||||||||||||
|
Subroutine
dump: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | my ($self) = @_; | |||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | require Data::Dumper; | |||||||||||||||||||
| 96 | print Data::Dumper::Dumper( | ||||||||||||||||||||
| 97 | 0 | $self->dmi->get_tree( $SECTION->{ ref($self) } ) ); | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 82 | ▶ | sub _search_for { | ||||||||||||||||||
|
Subroutine
_search_for: called CC=6 SCAR=19.2
| |||||||||||||||||||||
| 102 | 82 | my ( $self, $key, $is_array ) = @_; | |||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 82 | ▶ | unless ( $self->dmi->get_tree( $SECTION->{ ref($self) } ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | #die $SECTION->{ref($self)} . " not supported"; | ||||||||||||||||||||
| 107 | 51 | return; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 31 | my $idx = 0; | |||||||||||||||||||
| 111 | 31 | for my $entry ( @{ $self->dmi->get_tree( $SECTION->{ ref($self) } ) } ) { | |||||||||||||||||||
| 112 | 31 | my ($_key) = keys %{$entry}; | |||||||||||||||||||
| 113 | 31 | ▶ | if ($is_array) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 9 | ▶ | if ( $idx != $self->get_index() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | 0 | ++$idx; | |||||||||||||||||||
| 116 | 0 | next; | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 31 | ▶ | if ( exists $entry->{$key} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | 31 | return $entry->{$key}; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | else { | ||||||||||||||||||||
| 124 | 0 | return ""; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | 0 | ++$idx; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 0 | return ""; | |||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 9 | ▶ | sub get_index { | ||||||||||||||||||
|
Subroutine
get_index: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 9 | my ($self) = @_; | |||||||||||||||||||
| 135 | 9 | return $self->{"index"}; | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 40 | 1; | |||||||||||||||||||