File Coverage

blib/lib/System/Info/BSD.pm
Criterion Covered Total %
statement 9 26 34.6
branch 0 12 0.0
condition n/a
subroutine 3 5 60.0
pod 1 1 100.0
total 13 44 29.5


line stmt bran cond sub pod time code
1             package System::Info::BSD;
2              
3 3     3   22 use strict;
  3         5  
  3         87  
4 3     3   15 use warnings;
  3         6  
  3         75  
5              
6 3     3   14 use base "System::Info::Base";
  3         7  
  3         1377  
7              
8             our $VERSION = "0.051";
9              
10             =head1 NAME
11              
12             System::Info::BSD - Object for specific BSD info.
13              
14             =head1 DESCRIPTION
15              
16             =head2 $si->prepare_sysinfo()
17              
18             Use os-specific tools to find out more about the system.
19              
20             =cut
21              
22             sub prepare_sysinfo {
23 0     0 1   my $self = shift;
24 0           $self->SUPER::prepare_sysinfo;
25              
26 0           my $sysctl = __get_sysctl ();
27 0           $self->{__sysctl} = $sysctl;
28              
29 0           my $cpu = $sysctl->{model};
30              
31 0 0         if (exists $sysctl->{cpuspeed}) {
    0          
32 0           $cpu .= sprintf " (%.0f MHz)", $sysctl->{cpuspeed};
33             }
34             elsif (exists $sysctl->{cpufrequency}) {
35 0           $cpu .= sprintf " (%.0f MHz)", $sysctl->{cpufrequency}/1_000_000;
36             }
37              
38 0 0         $self->{__cpu_type} = $sysctl->{machine} if $sysctl->{machine};
39 0 0         $self->{__cpu} = $cpu if $cpu;
40 0           $self->{__cpu_count} = $sysctl->{ncpu};
41              
42 0           return $self;
43             } # prepare_sysinfo
44              
45             sub __get_sysctl {
46 0 0   0     my $sysctl_cmd = -x "/sbin/sysctl" ? "/sbin/sysctl" : "sysctl";
47              
48 0           chomp (my @sysctl = `$sysctl_cmd -a hw`);
49 0           my %sysctl = map m/^hw\.([\w.]+)\s*[:=]\s*(.*)$/ => @sysctl;
50 0 0         $sysctl{machine} and $sysctl{machine} =~ s/Power Macintosh/macppc/;
51              
52 0           return \%sysctl;
53             } # __get_sysctl
54              
55             1;
56              
57             __END__