/usr/share/perl5/System/Info/Base.pm is in libsystem-info-perl 0.057-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | package System::Info::Base;
use strict;
use warnings;
use POSIX ();
our $VERSION = "0.050";
=head1 NAME
System::Info::Base - Baseclass for system information.
=head1 ATTRIBUTES
=head2 cpu
=head2 cpu_type
=head2 ncpu
=head2 os
=head2 host
=head1 DESCRIPTION
=head2 System::Info::Base->new()
Return a new instance for $^O
=cut
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->prepare_sysinfo;
$self->{_host} = $self->get_hostname;
$self->{_os} = $self->get_os;
$self->{_cpu_type} = $self->get_cpu_type;
$self->{_cpu} = $self->get_cpu;
$self->{_ncpu} = $self->get_cpu_count;
$self->{_ncore} = $self->{_ncpu}
? (sort { $b <=> $a } ($self->{_ncpu} =~ m/(\d+)/g))[0]
: $self->{_ncpu};
return $self;
} # new
=head2 $si->prepare_sysinfo
This method should be overridden by platform specific subclasses.
The generic information is taken from C<< POSIX::uname() >>.
=over
=item $self->_hostname => (POSIX::uname)[1]
=item $self->_os => join " - " => (POSIX::uname)[0,2]
=item $self->_osname => (POSIX::uname)[0]
=item $self->_osvers => (POSIX::uname)[2]
=item $self->_cpu_type => (POSIX::uname)[4]
=item $self->_cpu => (POSIX::uname)[4]
=item $self->_cpu_count => ""
=back
=cut
sub prepare_sysinfo {
my $self = shift;
my @uname = POSIX::uname();
$self->{__hostname} = $uname[1];
$self->{__osname} = $uname[0];
$self->{__osvers} = $uname[2];
my $os = join " - " => @uname[0,2];
$os =~ s/(\S+)/\L$1/;
$self->{__os} = $os;
$self->{__cpu_type} = $uname[4];
$self->{__cpu} = $uname[4];
$self->{__cpu_count} = "";
return $self;
} # prepare_sysinfo
=head2 $si->get_os
Returns $self->_os
=cut
sub get_os {
my $self = shift;
return $self->_os;
} # get_os
=head2 $si->get_hostname
Returns $self->_hostname
=cut
sub get_hostname {
my $self = shift;
return $self->_hostname;
} # get_hostname
=head2 $si->get_cpu_type
Returns $self->_cpu_type
=cut
sub get_cpu_type {
my $self = shift;
return $self->_cpu_type;
} # get_cpu_type
=head2 $si->get_cpu
Returns $self->_cpu
=cut
sub get_cpu {
my $self = shift;
return $self->_cpu;
} # get_cpu
=head2 $si->get_cpu_count
Returns $self->_cpu_count
=cut
sub get_cpu_count {
my $self = shift;
return $self->_cpu_count;
} # get_cpu_count
=head2 $si->get_core_count
Returns $self->get_cpu_count as a number
If C<get_cpu_count> returns C<2 [8 cores]>, C<get_core_count> returns C<8>
=cut
sub get_core_count {
my $self = shift;
return $self->{_ncore};
} # get_core_count
=head2 si_uname (@args)
This class gathers most of the C<uname(1)> info, make a comparable
version. Takes almost the same arguments:
a for all (can be omitted)
n for nodename
s for os name and version
m for cpu name
c for cpu count
p for cpu_type
=cut
sub si_uname {
my $self = shift;
my @args = map split () => @_;
my @sw = qw( n s m c p );
my %sw = (
n => "host",
s => "os",
m => "cpu",
c => "ncpu",
p => "cpu_type",
);
@args = grep exists $sw{$_} => @args;
@args or @args = ("a");
grep m/a/ => @args and @args = @sw;
# filter supported args but keep order of @sw!
my %show = map +( $_ => undef ) => grep exists $sw{$_} => @args;
@args = grep exists $show{$_} => @sw;
return join " ", map { my $m = $sw{$_}; $self->$m } @args;
} # si_uname
=head2 $si->old_dump
Just a backward compatible way to dump the object (for test suite).
=cut
sub old_dump {
my $self = shift;
return {
_cpu => $self->cpu,
_cpu_type => $self->cpu_type,
_ncpu => $self->ncpu,
_os => $self->os,
_host => $self->host,
};
}
sub DESTROY { }
sub AUTOLOAD {
my $self = shift;
(my $attrib = our $AUTOLOAD) =~ s/.*:://;
if (exists $self->{"_$attrib"}) {
ref $self->{"_$attrib"} eq "ARRAY" and
return @{ $self->{"_$attrib"} };
return $self->{"_$attrib"};
}
}
1;
__END__
=head1 COPYRIGHT AND LICENSE
(c) 2016-2018, Abe Timmerman & H.Merijn Brand, All rights reserved.
With contributions from Jarkko Hietaniemi, Campo Weijerman, Alan Burlison,
Allen Smith, Alain Barbet, Dominic Dunlop, Rich Rauenzahn, David Cantrell.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
See:
=over 4
=item * L<http://www.perl.com/perl/misc/Artistic.html>
=item * L<http://www.gnu.org/copyleft/gpl.html>
=back
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
=cut
|