File Coverage

blib/lib/System/Info.pm
Criterion Covered Total %
statement 64 66 96.9
branch 13 24 54.1
condition 1 3 33.3
subroutine 18 19 94.7
pod 4 4 100.0
total 100 116 86.2


line stmt bran cond sub pod time code
1             package System::Info;
2              
3 2     2   211524 use strict;
  2         11  
  2         59  
4 2     2   11 use warnings;
  2         4  
  2         76  
5              
6             our $VERSION = "0.064";
7              
8 2     2   12 use base "Exporter";
  2         5  
  2         302  
9             our @EXPORT_OK = qw( &sysinfo &sysinfo_hash &si_uname );
10              
11 2     2   869 use System::Info::AIX;
  2         5  
  2         64  
12 2     2   841 use System::Info::BSD;
  2         4  
  2         56  
13 2     2   787 use System::Info::Cygwin;
  2         6  
  2         63  
14 2     2   850 use System::Info::Darwin;
  2         4  
  2         65  
15 2     2   739 use System::Info::Generic;
  2         6  
  2         52  
16 2     2   777 use System::Info::Haiku;
  2         4  
  2         54  
17 2     2   808 use System::Info::HPUX;
  2         5  
  2         57  
18 2     2   786 use System::Info::Irix;
  2         5  
  2         52  
19 2     2   13 use System::Info::Linux;
  2         2  
  2         47  
20 2     2   840 use System::Info::Solaris;
  2         5  
  2         55  
21 2     2   810 use System::Info::VMS;
  2         6  
  2         53  
22 2     2   807 use System::Info::Windows;
  2         6  
  2         1185  
23              
24             =head1 NAME
25              
26             System::Info - Factory for system specific information objects
27              
28             =head1 SYNOPSIS
29              
30             use System::Info;
31              
32             my $si = System::Info->new;
33              
34             printf "Hostname: %s\n", $si->host;
35             printf "Number of CPU's: %s\n", $si->ncpu;
36             printf "Processor type: %s\n", $si->cpu_type; # short
37             printf "Processor description: %s\n", $si->cpu; # long
38             printf "OS and version: %s\n", $si->os;
39              
40             or
41              
42             use System::Info qw( sysinfo );
43             printf "[%s]\n", sysinfo ();
44              
45             or
46              
47             $ perl -MSystem::Info=si_uname -le print+si_uname
48              
49             =head1 DESCRIPTION
50              
51             System::Info tries to present system-related information, like number of CPU's,
52             architecture, OS and release related information in a system-independent way.
53             This releases the user of this module of the need to know if the information
54             comes from Windows, Linux, HP-UX, AIX, Solaris, Irix, or VMS, and if the
55             architecture is i386, x64, pa-risc2, or arm.
56              
57             =head1 METHODS
58              
59             =head2 System::Info->new
60              
61             Factory method, with fallback to the information in C<< POSIX::uname () >>.
62              
63             =cut
64              
65             sub new {
66 108     108 1 5710 my $factory = shift;
67              
68 108 50       537 $^O =~ m/aix/i and return System::Info::AIX->new;
69 108 50       512 $^O =~ m/bsd|dragonfly/i and return System::Info::BSD->new;
70 108 50       252 $^O =~ m/cygwin/i and return System::Info::Cygwin->new;
71 108 50       220 $^O =~ m/darwin/i and return System::Info::Darwin->new;
72 108 50       285 $^O =~ m/haiku/ and return System::Info::Haiku->new;
73 108 50       287 $^O =~ m/hp-?ux/i and return System::Info::HPUX->new;
74 108 50       264 $^O =~ m/irix/i and return System::Info::Irix->new;
75 108 100       852 $^O =~ m/linux/i and return System::Info::Linux->new;
76 1 50       5 $^O =~ m/solaris|sunos|osf/i and return System::Info::Solaris->new;
77 1 50       5 $^O =~ m/VMS/ and return System::Info::VMS->new;
78 1 50       4 $^O =~ m/mswin32|windows/i and return System::Info::Windows->new;
79              
80 1         14 return System::Info::Generic->new;
81             }
82              
83             =head2 sysinfo
84              
85             C returns a string with C, C and C.
86              
87             =cut
88              
89             sub sysinfo {
90 1     1 1 334 my $si = System::Info->new;
91 1 50       34 my @fields = $_[0]
92             ? qw( host os cpu ncpu cpu_type )
93             : qw( host os cpu_type );
94 1         9 return join " ", @{ $si }{ map "_$_" => @fields };
  1         67  
95             } # sysinfo
96              
97             =head2 sysinfo_hash
98              
99             C returns a hash reference with basic system information, like:
100              
101             { cpu => 'Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz (GenuineIntel 2700MHz)',
102             cpu_count => '1 [8 cores]',
103             cpu_cores => 8,
104             cpu_type => 'x86_64',
105             distro => 'openSUSE Tumbleweed 20171030',
106             hostname => 'foobar',
107             os => 'linux - 4.13.10-1-default [openSUSE Tumbleweed 20171030]',
108             osname => 'Linux',
109             osvers => '4.13.10-1-default'
110             }
111              
112             =cut
113              
114             sub sysinfo_hash {
115 1     1 1 12 my $si = System::Info->new;
116             return {
117             hostname => $si->{_host},
118             cpu => $si->{_cpu},
119             cpu_type => $si->{_cpu_type},
120             cpu_count => $si->{_ncpu},
121             cpu_cores => $si->{_ncore},
122             os => $si->{_os},
123             osname => $si->{__osname},
124             osvers => $si->{__osvers},
125             distro => $si->{__distro}
126             || join " " => $si->{__osname}, $si->{__osvers},
127 1   33     89 };
128             } # sysinfo
129              
130             =head2 si_uname (@args)
131              
132             This class gathers most of the C info, make a comparable
133             version. Takes almost the same arguments:
134              
135             a for all (can be omitted)
136             n for nodename
137             s for os name and version
138             m for cpu name
139             c for cpu count
140             p for cpu_type
141              
142             =cut
143              
144             sub si_uname {
145 0     0 1   my $si = System::Info->new;
146 0           return $si->si_uname (@_);
147             }
148              
149             1;
150              
151             __END__