blib/lib/App/Sys/Info.pm

filter: Statementstmt 79.5% 202 / 254 Branchbran 38.6% 34 / 88 Conditioncond 32.4% 12 / 37 MC/DCmcdc 4.7% 1 / 21 Subroutinesub 94.7% 36 / 38 Podpod 100% 3 / 3 totaltotal 65.3% 288 / 441 CC 63 SCAR 21.8
CC
63
Cov
65%
_current_user
35.4
_probe
16.5
_registered
12.2
CRAP 8.8
↑ Summary
1 package App::Sys::Info;
2 2 $App::Sys::Info::VERSION = '0.26';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use constant CP_UTF8 => 65_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use constant LAST_ELEMENT => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Format::Human::Bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use POSIX qw( locale_h );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Text::Table qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Time::Duration qw( duration_exact );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Sys::Info qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Sys::Info::Constants qw( NEW_PERL OSID );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 my($NEED_CHCP, $OLDCP);
18  
19 2 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
20 2 ▶ no strict qw( refs );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 foreach my $id ( qw( info os cpu fhb meta NA ) ) {
22 12 ▶ *{ $id } = sub () { return shift->{$id} };
Subroutine __ANON__: called CC=1 SCAR=0.0
23 }
24 }
25  
26 1 ▶END {
Subroutine END: called CC=3 SCAR=14.2
27 1 ▶ _chcp( $OLDCP ) if $NEED_CHCP && $OLDCP;
Branch: 1 branch
BranchTrueFalseTotal
if $NEED_CHCP and $OLDCP 0 1 1
Condition33%1/3
$NEED_CHCP and $OLDCP
!ll&&!rl&&r
100
MC/DC0%0/2
$NEED_CHCP and $OLDCP
$NEED_CHCP $OLDCP
Truth table33%1/3
A and B
A= $NEED_CHCPB= $OLDCP
ABresult
0X0
100
111
28 }
29  
30 0 ▶sub _chcp {
Subroutine _chcp: not called CC=2 SCAR=17.9
31 0 ▶ my $enc = shift || croak 'No encoding specified';
Condition0%0/2
shift() || croak('No encoding specified')
l!l
00
MC/DC0%0/1
shift() || croak('No encoding specified')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
32 0 system chcp => $enc, '2>nul', '1>nul';
33 0 return;
34 }
35  
36 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.9
Pod documented
37 1 my $class = shift;
38 1 my $i = Sys::Info->new;
39 1 my $loc = do {
40 1 my $rv;
41 eval {
42 1 $rv = setlocale( LC_CTYPE );
43 1 1;
44 1 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $rv = setlocale(0); 1 } } or do { my $error = $@ || "Unknown error"; warn "Unable to collect the locale information: $error"; $rv = "" } 1 0 1
45 0 ▶ my $error = $@ || 'Unknown error';
Condition0%0/2
$@ || 'Unknown error'
l!l
00
MC/DC0%0/1
$@ || 'Unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
46 0 warn "Unable to collect the locale information: $error";
47 0 $rv = '';
48 };
49 1 $rv;
50 };
51 1 my $self = {
52 LOCALE => $loc,
53 NA => 'N/A',
54 info => $i,
55 os => $i->os,
56 cpu => $i->device('CPU'),
57 fhb => Format::Human::Bytes->new,
58 };
59 1 $self->{meta} = { $self->{os}->meta };
60 1 bless $self, $class;
61 1 return $self;
62 }
63  
64 1 ▶sub run {
Subroutine run: called CC=3 SCAR=11.3
Pod documented
65 1 my $self = __PACKAGE__->new;
66 1 ▶ $NEED_CHCP = $self->os->is_winnt && $ENV{PROMPT};
Condition33%1/3
$self->os->is_winnt && $ENV{'PROMPT'}
!ll&&!rl&&r
100
MC/DC0%0/2
$self->os->is_winnt && $ENV{'PROMPT'}
$self->os->is_winnt $ENV{'PROMPT'}
Truth table33%1/3
A && B
A= $self->os->is_winntB= $ENV{'PROMPT'}
ABresult
0X0
100
111
67 1 my @probe = $self->probe;
68  
69 1 $self->_init_encoding;
70  
71 1 my $tb = Text::Table->new( q{}, q{} );
72 1 $tb->load( @probe );
73  
74 1 ▶ print "\n", $tb or croak "Unable to orint to STDOUT: $!";
Branch: 1 branch
BranchTrueFalseTotal
print "\n", $tb or croak("Unable to orint to STDOUT: $!") 1 0 1
75 1 return;
76 }
77  
78 1 ▶sub probe {
Subroutine probe: called CC=2 SCAR=7.0
Pod documented
79 1 my $self = shift;
80 1 my @rv = eval { $self->_probe(); };
81 1 ▶ croak "Error fetching information: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
82 1 return @rv;
83 }
84  
85 1 ▶sub _init_encoding {
Subroutine _init_encoding: called CC=3 SCAR=16.7
86 1 my $self = shift;
87 1 ▶ if ( $NEED_CHCP ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($NEED_CHCP) 0 1 1
88 ## no critic (InputOutput::ProhibitBacktickOperators)
89 0 chomp($OLDCP = (split /:\s?/xms, qx(chcp))[LAST_ELEMENT]);
90 # try to change the command line encoding to unicode
91 0 ▶ _chcp( CP_UTF8 ) if $OLDCP;
Branch: 1 branch
BranchTrueFalseTotal
if $OLDCP 0 0 0
92 0 if ( NEW_PERL ) {
93 0 my $eok = eval q{ binmode STDOUT, ':utf8'; 1; };
94 }
95 }
96 1 return;
97 }
98  
99 1 ▶sub _probe {
Subroutine _probe: called CC=15 SCAR=28.0
100 1 my $self = shift;
101 1 my $meta = $self->meta;
102 1 my $NA = $self->NA;
103 1 my $i = $self->info;
104 1 my $os = $self->os;
105 1 my $pt = $os->product_type;
106 1 my $proc = $self->_processors;
107 1 my $tz = $os->tz;
108 1 my $driver = 'Sys::Info::Driver::' . OSID;
109 1 my @rv;
110  
111 1 push @rv,
112 [ 'Sys::Info Version' =>
113 sprintf(
114 '%s (%s: %s - Base: %s)',
115 Sys::Info->VERSION,
116 OSID,
117 $driver->VERSION,
118 Sys::Info::Base->VERSION,
119 )
120 ],
121 [ 'Perl Version' => $i->perl_long ],
122 [ 'Host Name' => $os->host_name ],
123 [ 'OS Name' => $self->_os_name ],
124 [ 'OS Version' => $self->_os_version ],
125 ;
126  
127 1 my $manu = $meta->{manufacturer};
128 1 my $bt = $meta->{build_type};
129  
130 1 ▶ push @rv, [ 'OS Manufacturer' => $manu ] if $manu;
Branch: 1 branch
BranchTrueFalseTotal
if $manu 1 0 1
131 1 ▶ push @rv, [ 'OS Configuration' => $pt ] if $pt;
Branch: 1 branch
BranchTrueFalseTotal
if $pt 0 1 1
132 1 ▶ push @rv, [ 'OS Build Type' => $bt ] if $bt;
Branch: 1 branch
BranchTrueFalseTotal
if $bt 0 1 1
133  
134 1 $self->_bitness( \@rv );
135 1 $self->_current_user( \@rv );
136 1 $self->_registered( \@rv, $meta );
137  
138 1 my $pid = $meta->{product_id};
139 1 my $tick = $os->tick_count;
140 1 my $st = $meta->{system_type};
141  
142 1 ▶ push @rv, [ 'Product ID' => $pid ] if $pid;
Branch: 1 branch
BranchTrueFalseTotal
if $pid 0 1 1
143  
144 1 $self->_install_date( \@rv );
145  
146 1 ▶ push @rv, [ 'System Up Time' => duration_exact($tick) ] if $tick;
Branch: 1 branch
BranchTrueFalseTotal
if $tick 1 0 1
147  
148 1 $self->_manufacturer( \@rv, $meta );
149  
150 1 ▶ push @rv, [ 'System Type' => $st ] if $st;
Branch: 1 branch
BranchTrueFalseTotal
if $st 1 0 1
151 1 ▶ push @rv, [ 'Processor(s)' => $proc ] if $proc;
Branch: 1 branch
BranchTrueFalseTotal
if $proc 1 0 1
152  
153 1 $self->_proc_meta( \@rv );
154 1 $self->_bios_version( \@rv );
155 1 $self->_directories( \@rv, $meta );
156  
157 1 my $loc = $self->{LOCALE};
158  
159 1 ▶ push @rv, [ 'System Locale' => $loc ] if $loc;
Branch: 1 branch
BranchTrueFalseTotal
if $loc 1 0 1
160 1 ▶ push @rv, [ 'Input Locale' => $loc ] if $loc;
Branch: 1 branch
BranchTrueFalseTotal
if $loc 1 0 1
161 1 ▶ push @rv, [ 'Time Zone' => $tz ] if $tz;
Branch: 1 branch
BranchTrueFalseTotal
if $tz 0 1 1
162  
163 1 $self->_memory( \@rv, $meta );
164 1 $self->_vm( \@rv );
165  
166 1 my $domain = $os->domain_name;
167 1 my $logon = $os->logon_server;
168 1 my $ip = $os->ip;
169 1 my $page = $meta->{page_file_path};
170  
171 1 ▶ push @rv, [ 'Page File Location(s)' => $page ] if $page;
Branch: 1 branch
BranchTrueFalseTotal
if $page 0 1 1
172 1 ▶ push @rv, [ 'Domain' => $domain ] if $domain;
Branch: 1 branch
BranchTrueFalseTotal
if $domain 0 1 1
173 1 ▶ push @rv, [ 'Logon Server' => $logon ] if $logon;
Branch: 1 branch
BranchTrueFalseTotal
if $logon 0 1 1
174 1 ▶ push @rv, [ 'IP Address' => $ip ] if $ip;
Branch: 1 branch
BranchTrueFalseTotal
if $ip 0 1 1
175  
176 1 $self->_cdkey( \@rv );
177  
178 1 return @rv;
179 }
180  
181 1 ▶sub _registered {
Subroutine _registered: called CC=4 SCAR=25.0
182 1 my($self, $rv, $meta) = @_;
183 1 ▶ return if ! $self->os->is_windows;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->os->is_windows 1 0 1
184 0 my $owner = $meta->{owner};
185 0 my $org = $meta->{organization};
186 0 ▶ push @{ $rv }, [ 'Registered Owner' => $owner ] if $owner;
Branch: 1 branch
BranchTrueFalseTotal
if $owner 0 0 0
187 0 ▶ push @{ $rv }, [ 'Registered Organization' => $org ] if $org;
Branch: 1 branch
BranchTrueFalseTotal
if $org 0 0 0
188 0 return;
189 }
190  
191 1 ▶sub _directories {
Subroutine _directories: called CC=4 SCAR=15.5
192 1 my($self, $rv, $meta) = @_;
193 1 my $win = $meta->{windows_dir};
194 1 my $sys = $meta->{system_dir};
195 1 my $boot = $meta->{boot_device};
196 0 ▶ push @{ $rv }, [ 'Windows Directory' => $win ] if $win;
Branch: 1 branch
BranchTrueFalseTotal
if $win 0 1 1
197 0 ▶ push @{ $rv }, [ 'System Directory' => $sys ] if $sys;
Branch: 1 branch
BranchTrueFalseTotal
if $sys 0 1 1
198 0 ▶ push @{ $rv }, [ 'Boot Device' => $boot ] if $boot;
Branch: 1 branch
BranchTrueFalseTotal
if $boot 0 1 1
199 1 return;
200 }
201  
202 1 ▶sub _manufacturer {
Subroutine _manufacturer: called CC=4 SCAR=25.0
203 1 my($self, $rv, $meta) = @_;
204 1 ▶ return if ! $self->os->is_windows;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->os->is_windows 1 0 1
205 0 my $manu = $meta->{system_manufacturer};
206 0 my $model = $meta->{system_model};
207 0 ▶ push @{ $rv }, [ 'System Manufacturer' => $manu ] if $manu;
Branch: 1 branch
BranchTrueFalseTotal
if $manu 0 0 0
208 0 ▶ push @{ $rv }, [ 'System Model' => $model ] if $model;
Branch: 1 branch
BranchTrueFalseTotal
if $model 0 0 0
209 0 return;
210 }
211  
212 1 ▶sub _cdkey {
Subroutine _cdkey: called CC=4 SCAR=23.7
213 1 my($self, $rv) = @_;
214 1 my $os = $self->os;
215 1 ▶ return if ! $os->is_windows;
Branch: 1 branch
BranchTrueFalseTotal
unless $os->is_windows 1 0 1
216  
217 0 my $cdkey = $os->cdkey;
218 0 my $okey = $self->_office_cdkey;
219 0 ▶ push @{ $rv }, [ 'Windows CD Key' => $cdkey ] if $cdkey;
Branch: 1 branch
BranchTrueFalseTotal
if $cdkey 0 0 0
220 0 ▶ push @{ $rv }, [ 'Microsoft Office CD Key' => $okey ] if $okey;
Branch: 1 branch
BranchTrueFalseTotal
if $okey 0 0 0
221 0 return;
222 }
223  
224 1 ▶sub _current_user {
Subroutine _current_user: called CC=7 SCAR=35.7
225 1 my($self, $rv_ref) = @_;
226 1 my $os = $self->os;
227 1 ▶ my $user = $os->login_name || return;
Condition50%1/2
$os->login_name || (return)
l!l
01
MC/DC0%0/1
$os->login_name || (return)
$os->login_name
Truth table50%1/2
A
A= $os->login_name
Aresult
11
00
228 0 my $real = $os->login_name( real => 1 );
229  
230 0 ▶ return if ! $user || ! $real;
Branch: 1 branch
BranchTrueFalseTotal
unless $user and $real 0 0 0
Condition0%0/3
$user and $real
!ll&&!rl&&r
000
MC/DC0%0/2
$user and $real
$user $real
Truth table0%0/3
A and B
A= $userB= $real
ABresult
0X0
100
111
231  
232 0 ▶ my $display = $real && ($real ne $user) ? qq{$real ($user)} : $user;
Branch: 1 branch
BranchTrueFalseTotal
$real && $real ne $user ? : 0 0 0
Condition0%0/3
$real and $real ne $user
!ll&&!rl&&r
000
MC/DC0%0/2
$real and $real ne $user
$real $real ne $user
Truth table0%0/3
A and B
A= $realB= $real ne $user
ABresult
0X0
100
111
233 0 ▶ $display .= $os->is_root ? q{ is an administrator} : q{};
Branch: 1 branch
BranchTrueFalseTotal
$os->is_root ? : 0 0 0
234 0 push @{ $rv_ref }, [ 'Current User', $display ];
235  
236 0 return;
237 }
238  
239 1 ▶sub _proc_meta {
Subroutine _proc_meta: called CC=8 SCAR=21.3
240 1 my $self = shift;
241 1 my $data = shift;
242 1 my @cpu = $self->cpu->identify;
243 1 ▶ my $prop = $cpu[0] || {};
Condition50%1/2
$cpu[0] || {}
l!l
10
MC/DC0%0/1
$cpu[0] || {}
$cpu[0]
Truth table50%1/2
A
A= $cpu[0]
Aresult
11
00
244 1 my $load = $self->cpu->load;
245 1 my $L1 = $prop->{L1_cache}{max_cache_size};
246 1 my $L2 = $prop->{L2_cache}{max_cache_size};
247 1 my $sock = $prop->{socket_designation};
248 1 my $id = $prop->{processor_id};
249 1 my @rv;
250  
251 2 ▶ my $check_lc = sub {
Subroutine __ANON__: called CC=4 SCAR=14.3
252 2 ▶ my $ref = shift || return;
Condition50%1/2
shift() || (return)
l!l
20
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
253 2 ▶ return if ! ${ $ref };
Branch: 1 branch
BranchTrueFalseTotal
unless ${$ref;} 1 1 2
254 0 ▶ ${ $ref } .= q{ KB} if ${ $ref } !~ m{\sKB\z}xms;
Branch: 1 branch
BranchTrueFalseTotal
unless ${$ref;} =~ /\sKB\z/msx 0 1 1
255 1 return;
256 1 };
257  
258 1 $check_lc->( \$L1 );
259 1 $check_lc->( \$L2 );
260  
261 1 ▶ push @rv, qq{Load : $load} if $load;
Branch: 1 branch
BranchTrueFalseTotal
if $load 1 0 1
262 1 ▶ push @rv, qq{L1 Cache: $L1} if $L1;
Branch: 1 branch
BranchTrueFalseTotal
if $L1 0 1 1
263 1 ▶ push @rv, qq{L2 Cache: $L2} if $L2;
Branch: 1 branch
BranchTrueFalseTotal
if $L2 1 0 1
264 1 ▶ push @rv, qq{Package : $sock} if $sock;
Branch: 1 branch
BranchTrueFalseTotal
if $sock 0 1 1
265 1 ▶ push @rv, qq{ID : $id} if $id;
Branch: 1 branch
BranchTrueFalseTotal
if $id 0 1 1
266  
267 1 my $buf = q{ } x 2**2;
268 1 push @{$data}, [ q{ }, $buf . $_ ] for @rv;
269 1 return;
270 }
271  
272 1 ▶sub _processors {
Subroutine _processors: called CC=1 SCAR=0.0
273 1 my $self = shift;
274 1 my $cpu = $self->cpu;
275 1 my $name = scalar $cpu->identify;
276 1 my $rv = sprintf '%s ~%sMHz', $name, $cpu->speed;
277 1 $rv =~ s{\s+}{ }xmsg;
278 1 return $rv;
279 }
280  
281 1 ▶sub _memory {
Subroutine _memory: called CC=1 SCAR=0.0
282 1 my($self, $rv, $meta) = @_;
283 1 push @{ $rv },
284 map {
285 4 [ $_->[0], $self->_mb( $_->[1] ) ]
286 }
287 [ 'Total Physical Memory' => $meta->{physical_memory_total} ],
288 [ 'Available Physical Memory' => $meta->{physical_memory_available} ],
289 [ 'Virtual Memory: Max Size' => $meta->{page_file_total} ],
290 1 [ 'Virtual Memory: Available' => $meta->{page_file_available} ],
291 ;
292 1 return;
293 }
294  
295 1 ▶sub _vm {
Subroutine _vm: called CC=3 SCAR=18.1
296 1 my($self, $rv_ref) = @_;
297 1 ▶ my $tot = $self->meta->{page_file_total} || return;
Condition50%1/2
$self->meta->{'page_file_total'} || (return)
l!l
01
MC/DC0%0/1
$self->meta->{'page_file_total'} || (return)
$self->meta->{'page_file_total'}
Truth table50%1/2
A
A= $self->meta->{'page_file_total'}
Aresult
11
00
298 0 ▶ my $av = $self->meta->{page_file_available} || return;
Condition0%0/2
$self->meta->{'page_file_available'} || (return)
l!l
00
MC/DC0%0/1
$self->meta->{'page_file_available'} || (return)
$self->meta->{'page_file_available'}
Truth table0%0/2
A
A= $self->meta->{'page_file_available'}
Aresult
11
00
299 0 push @{ $rv_ref },
300 [ 'Virtual Memory: In Use' => $self->_mb( $tot - $av ) ]
301 ;
302 0 return;
303 }
304  
305 4 ▶sub _mb {
Subroutine _mb: called CC=2 SCAR=6.9
306 4 my $self = shift;
307 4 ▶ my $kb = shift || return $self->NA;
Condition100%2/2
shift() || (return $self->NA)
l!l
22
MC/DC100%1/1
shift() || (return $self->NA)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
308 2 return $self->fhb->base2( $kb, 2 );
309 }
310  
311 1 ▶sub _os_name {
Subroutine _os_name: called CC=1 SCAR=0.0
312 1 my $self = shift;
313 1 return $self->os->name( long => 1, edition => 1 );
314 }
315  
316 1 ▶sub _os_version {
Subroutine _os_version: called CC=1 SCAR=0.0
317 1 my $self = shift;
318 1 my $os = $self->os;
319 1 return $os->version . q{.} . $os->build;
320 }
321  
322 0 ▶sub _office_cdkey {
Subroutine _office_cdkey: not called CC=2 SCAR=17.9
323 0 my $self = shift;
324 0 my @office = $self->os->cdkey( office => 1 );
325 0 ▶ return @office ? $office[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@office ? : 0 0 0
326 }
327  
328 1 ▶sub _bitness {
Subroutine _bitness: called CC=3 SCAR=11.2
329 1 my($self, $rv_ref) = @_;
330 1 ▶ my $cpu = $self->cpu->bitness || q{??};
Condition50%1/2
$self->cpu->bitness || '??'
l!l
10
MC/DC0%0/1
$self->cpu->bitness || '??'
$self->cpu->bitness
Truth table50%1/2
A
A= $self->cpu->bitness
Aresult
11
00
331 1 ▶ my $os = $self->os->bitness || q{??};
Condition50%1/2
$self->os->bitness || '??'
l!l
10
MC/DC0%0/1
$self->os->bitness || '??'
$self->os->bitness
Truth table50%1/2
A
A= $self->os->bitness
Aresult
11
00
332 1 push @{ $rv_ref }, [ 'Running on' => qq{${cpu}bit CPU & ${os}bit OS} ];
333 1 return;
334 }
335  
336 1 ▶sub _install_date {
Subroutine _install_date: called CC=2 SCAR=7.0
337 1 my($self, $rv_ref) = @_;
338 1 ▶ my $date = $self->meta->{install_date} || return;
Condition50%1/2
$self->meta->{'install_date'} || (return)
l!l
10
MC/DC0%0/1
$self->meta->{'install_date'} || (return)
$self->meta->{'install_date'}
Truth table50%1/2
A
A= $self->meta->{'install_date'}
Aresult
11
00
339 1 push @{ $rv_ref }, [ 'Original Install Date' => scalar localtime $date ];
340 1 return;
341 }
342  
343 1 ▶sub _bios_version {
Subroutine _bios_version: called CC=3 SCAR=13.6
344 1 my($self, $rv_ref) = @_;
345 1 local $@;
346 1 my $bv = eval { $self->info->device('bios')->version; };
347 1 ▶ return if $@ || ! $bv;
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not $bv 1 0 1
Condition33%1/3
$@ or not $bv
l!l&&r!l&&!r
100
MC/DC0%0/2
$@ or not $bv
$@ not $bv
Truth table33%1/3
A or not(B)
A= $@B= not $bv
ABresult
1X1
011
000
348 0 push @{ $rv_ref }, [ 'BIOS Version' => $bv ];
349 0 return;
350 }
351  
352 2 1;
353  
354 __END__
↑ Summary