File Coverage

lib/Rex/Inventory/Proc/Cpuinfo.pm
Criterion Covered Total %
statement 34 35 97.1
branch 5 6 83.3
condition 1 3 33.3
subroutine 7 7 100.0
pod 0 2 0.0
total 47 53 88.6


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Inventory::Proc::Cpuinfo;
6              
7 2     2   27 use v5.12.5;
  2         8  
8 2     2   10 use warnings;
  2         4  
  2         93  
9              
10             our $VERSION = '1.14.2.2'; # TRIAL VERSION
11              
12 2     2   628 use Data::Dumper;
  2         6927  
  2         105  
13 2     2   533 use Rex::Commands::File;
  2         7  
  2         16  
14 2     2   17 use Rex::Commands::Fs;
  2         15  
  2         15  
15              
16             sub new {
17 2     2 0 5 my $that = shift;
18 2   33     10 my $proto = ref($that) || $that;
19 2         5 my $self = {@_};
20              
21 2         5 bless( $self, $proto );
22              
23 2         5 return $self;
24             }
25              
26             sub get {
27 2     2 0 5 my ($self) = @_;
28              
29 2         4 my @ret;
30              
31 2 50       8 if ( is_readable('/proc/cpuinfo') ) {
32              
33 2         9 my @cpuinfo = split /\n/, cat "/proc/cpuinfo";
34 2         35 chomp @cpuinfo;
35              
36 2         7 my $proc = 0;
37 2         6 for my $line (@cpuinfo) {
38 862 100       3158 next if $line =~ qr{^$};
39 832         3072 my ( $key, $val ) = split /\s*:\s*/, $line, 2;
40 832 100       1631 if ( $key eq "processor" ) {
41 32         44 $proc = $val;
42 32         72 $ret[$proc] = {};
43 32         58 next;
44             }
45              
46 800         1711 $ret[$proc]->{$key} = $val;
47             }
48             }
49             else {
50 0         0 Rex::Logger::info( 'Cannot read /proc/cpuinfo', 'warn' );
51             }
52              
53 2         27 return \@ret;
54             }
55              
56             1;