Info/Base.pm

filter: Statementstmt 100% 70 / 70 Branchbran 83.3% 10 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 93.7% 15 / 16 Podpod 100% 11 / 11 totaltotal 93.2% 111 / 119 CC 9 SCAR 8.5
CC
9
Cov
95%
new
5.1
AUTOLOAD
3.0
si_uname
3.0
CRAP 2.3
« Info/VMS.pm ↑ Summary Info/Irix.pm »
1 package System::Info::Base;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = "0.050";
9  
10 =head1 NAME
11  
12 System::Info::Base - Baseclass for system information.
13  
14 =head1 ATTRIBUTES
15  
16 =over 2
17  
18 =item cpu
19  
20 =item cpu_type
21  
22 =item ncpu
23  
24 =item os
25  
26 =item host
27  
28 =back
29  
30 =head1 DESCRIPTION
31  
32 =head2 System::Info::Base->new()
33  
34 Return a new instance for $^O
35  
36 =cut
37  
38 143 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod documented
39 143 my $class = shift;
40  
41 143 my $self = bless {}, $class;
42 143 $self->prepare_sysinfo;
43  
44 143 $self->{_host} = $self->get_hostname;
45 143 $self->{_os} = $self->get_os;
46 143 $self->{_cpu_type} = $self->get_cpu_type;
47 143 $self->{_cpu} = $self->get_cpu;
48 143 $self->{_ncpu} = $self->get_cpu_count;
49  
50 143 (my $bc = $class) =~ s/.*://;
51 143 ▶ $self->{_distro} = $self->get_dist_name || ($bc eq "Base" ? "" : $bc);
Branch: 1 branch
BranchTrueFalseTotal
$bc eq 'Base' ? : 0 6 6
Condition66%2/3
$self->get_dist_name || ($bc eq 'Base' ? '' : $bc)
l!l&&r!l&&!r
13760
MC/DC0%0/2
$self->get_dist_name || ($bc eq 'Base' ? '' : $bc)
$self->get_dist_name ($bc eq 'Base' ? '' : $bc)
Truth table66%2/3
A || B
A= $self->get_dist_nameB= ($bc eq 'Base' ? '' : $bc)
ABresult
1X1
011
000
52  
53 $self->{_ncore} ||= $self->{_ncpu}
54 11 ? (sort { $b <=> $a } ($self->{_ncpu} =~ m/(\d+)/g))[0]
55 143 ▶ : $self->{_ncpu};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_ncpu'} ? : 141 2 143
Condition66%2/3
$self->{"_ncore"} ||= $self->{"_ncpu"} ? (sort {$b <=> $a;} $self->{"_ncpu"} =~ /(\d+)/g)[0] : $self->{"_ncpu"}
l!l&&r!l&&!r
01412
MC/DC50%1/2
$self->{"_ncore"} ||= $self->{"_ncpu"} ? (sort {$b <=> $a;} $self->{"_ncpu"} =~ /(\d+)/g)[0] : $self->{"_ncpu"}
$self->{"_ncore"} $self->{"_ncpu"} ? (sort {$b <=> $a;} $self->{"_ncpu"} =~ /(\d+)/g)[0] : $self->{"_ncpu"}
Truth table66%2/3
A ||= B
A= $self->{"_ncore"}B= $self->{"_ncpu"} ? (sort {$b <=> $a;} $self->{"_ncpu"} =~ /(\d+)/g)[0] : $self->{"_ncpu"}
ABresult
1X1
011
000
56  
57 143 return $self;
58 } # new
59  
60 =head2 $si->prepare_sysinfo
61  
62 This method should be overridden by platform specific subclasses.
63  
64 The generic information is taken from C<< POSIX::uname() >>.
65  
66 =over
67  
68 =item $self->_hostname => (POSIX::uname)[1]
69  
70 =item $self->_os => join " - " => (POSIX::uname)[0,2]
71  
72 =item $self->_osname => (POSIX::uname)[0]
73  
74 =item $self->_osvers => (POSIX::uname)[2]
75  
76 =item $self->_cpu_type => (POSIX::uname)[4]
77  
78 =item $self->_cpu => (POSIX::uname)[4]
79  
80 =item $self->_cpu_count => ""
81  
82 =back
83  
84 =cut
85  
86 143 ▶sub prepare_sysinfo {
Subroutine prepare_sysinfo: called CC=1 SCAR=0.0
Pod documented
87 143 my $self = shift;
88 143 my @uname = POSIX::uname();
89  
90 143 $self->{__hostname} = $uname[1];
91  
92 143 $self->{__osname} = $uname[0];
93 143 $self->{__osvers} = $uname[2];
94 143 my $os = join " - " => @uname[0,2];
95 143 $os =~ s/(\S+)/\L$1/;
96 143 $self->{__os} = $os;
97  
98 143 $self->{__cpu_type} = $uname[4];
99 143 $self->{__cpu} = $uname[4];
100 143 $self->{__cpu_count} = "";
101  
102 143 return $self;
103 } # prepare_sysinfo
104  
105 =head2 $si->get_os
106  
107 Returns $self->_os
108  
109 =cut
110  
111 143 ▶sub get_os {
Subroutine get_os: called CC=1 SCAR=0.0
Pod documented
112 143 my $self = shift;
113 143 return $self->_os;
114 } # get_os
115  
116 =head2 $si->get_hostname
117  
118 Returns $self->_hostname
119  
120 =cut
121  
122 143 ▶sub get_hostname {
Subroutine get_hostname: called CC=1 SCAR=0.0
Pod documented
123 143 my $self = shift;
124 143 return $self->_hostname;
125 } # get_hostname
126  
127 =head2 $si->get_cpu_type
128  
129 Returns $self->_cpu_type
130  
131 =cut
132  
133 258 ▶sub get_cpu_type {
Subroutine get_cpu_type: called CC=1 SCAR=0.0
Pod documented
134 258 my $self = shift;
135 258 return $self->_cpu_type;
136 } # get_cpu_type
137  
138 =head2 $si->get_cpu
139  
140 Returns $self->_cpu
141  
142 =cut
143  
144 143 ▶sub get_cpu {
Subroutine get_cpu: called CC=1 SCAR=0.0
Pod documented
145 143 my $self = shift;
146 143 return $self->_cpu;
147 } # get_cpu
148  
149 =head2 $si->get_cpu_count
150  
151 Returns $self->_cpu_count
152  
153 =cut
154  
155 143 ▶sub get_cpu_count {
Subroutine get_cpu_count: called CC=1 SCAR=0.0
Pod documented
156 143 my $self = shift;
157 143 return $self->_cpu_count;
158 } # get_cpu_count
159  
160 =head2 $si->get_core_count
161  
162 Returns $self->get_cpu_count as a number
163  
164 If C<get_cpu_count> returns C<2 [8 cores]>, C<get_core_count> returns C<8>
165  
166 =cut
167  
168 1 ▶sub get_core_count {
Subroutine get_core_count: called CC=1 SCAR=0.0
Pod documented
169 1 my $self = shift;
170 1 return $self->{_ncore};
171 } # get_core_count
172  
173 =head2 $si->get_dist_name
174  
175 Returns the name of the distribution.
176  
177 =cut
178  
179 143 ▶sub get_dist_name {
Subroutine get_dist_name: called CC=1 SCAR=0.0
Pod documented
180 143 my $self = shift;
181 143 return $self->{__distro};
182 } # get_dist_name
183  
184 =head2 si_uname (@args)
185  
186 This class gathers most of the C<uname(1)> info, make a comparable
187 version. Takes almost the same arguments:
188  
189 a for all (can be omitted)
190 n for nodename
191 s for os name and version
192 m for cpu name
193 c for cpu count
194 p for cpu_type
195  
196 =cut
197  
198 64 ▶sub si_uname {
Subroutine si_uname: called CC=3 SCAR=11.0
Pod documented
199 64 my $self = shift;
200 64 my @args = map split () => @_;
201  
202 64 my @sw = qw( n s m c p );
203 64 my %sw = (
204 n => "host",
205 s => "os",
206 m => "cpu",
207 c => "ncpu",
208 p => "cpu_type",
209 );
210  
211 64 @args = grep exists $sw{$_} => @args;
212 64 ▶ @args or @args = ("a");
Branch: 1 branch
BranchTrueFalseTotal
@args or @args = "a" 59 5 64
213 64 ▶ grep m/a/ => @args and @args = @sw;
Branch: 1 branch
BranchTrueFalseTotal
grep /a/, @args and @args = @sw 5 59 64
214  
215 # filter supported args but keep order of @sw!
216 64 my %show = map +( $_ => undef ) => grep exists $sw{$_} => @args;
217 64 @args = grep exists $show{$_} => @sw;
218  
219 64 return join " ", map { my $m = $sw{$_}; $self->$m } @args;
220 } # si_uname
221  
222 =head2 $si->old_dump
223  
224 Just a backward compatible way to dump the object (for test suite).
225  
226 =cut
227  
228 11 ▶sub old_dump {
Subroutine old_dump: called CC=1 SCAR=0.0
Pod documented
229 11 my $self = shift;
230 return {
231 11 _cpu => $self->cpu,
232 _cpu_type => $self->cpu_type,
233 _ncpu => $self->ncpu,
234 _os => $self->os,
235 _host => $self->host,
236 };
237 }
238  
239 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
240  
241 2141 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
242 2141 my $self = shift;
243  
244 2141 (my $attrib = our $AUTOLOAD) =~ s/.*:://;
245 2141 ▶ if (exists $self->{"_$attrib"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$self{"_$attrib"}) 2141 0 2141
246 ref $self->{"_$attrib"} eq "ARRAY" and
247 2141 ▶ return @{ $self->{"_$attrib"} };
Branch: 1 branch
BranchTrueFalseTotal
ref $$self{"_$attrib"} eq "ARRAY" and return @{$$self{"_$attrib"};} 808 1333 2141
248 1333 return $self->{"_$attrib"};
249 }
250 }
251  
252 4 1;
253  
254 __END__
« Info/VMS.pm ↑ Summary Info/Irix.pm »