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   30 use v5.12.5;
  2         7  
8 2     2   10 use warnings;
  2         6  
  2         89  
9              
10             our $VERSION = '1.14.2.3'; # TRIAL VERSION
11              
12 2     2   677 use Data::Dumper;
  2         7095  
  2         120  
13 2     2   567 use Rex::Commands::File;
  2         7  
  2         17  
14 2     2   18 use Rex::Commands::Fs;
  2         8  
  2         12  
15              
16             sub new {
17 2     2 0 6 my $that = shift;
18 2   33     11 my $proto = ref($that) || $that;
19 2         4 my $self = {@_};
20              
21 2         5 bless( $self, $proto );
22              
23 2         6 return $self;
24             }
25              
26             sub get {
27 2     2 0 5 my ($self) = @_;
28              
29 2         4 my @ret;
30              
31 2 50       7 if ( is_readable('/proc/cpuinfo') ) {
32              
33 2         12 my @cpuinfo = split /\n/, cat "/proc/cpuinfo";
34 2         34 chomp @cpuinfo;
35              
36 2         6 my $proc = 0;
37 2         6 for my $line (@cpuinfo) {
38 862 100       3218 next if $line =~ qr{^$};
39 832         2951 my ( $key, $val ) = split /\s*:\s*/, $line, 2;
40 832 100       1668 if ( $key eq "processor" ) {
41 32         42 $proc = $val;
42 32         78 $ret[$proc] = {};
43 32         57 next;
44             }
45              
46 800         1716 $ret[$proc]->{$key} = $val;
47             }
48             }
49             else {
50 0         0 Rex::Logger::info( 'Cannot read /proc/cpuinfo', 'warn' );
51             }
52              
53 2         24 return \@ret;
54             }
55              
56             1;