File Coverage

blib/lib/Unix/Uptime/Linux.pm
Criterion Covered Total %
statement 22 23 95.6
branch 4 8 50.0
condition n/a
subroutine 5 5 100.0
pod 0 3 0.0
total 31 39 79.4


line stmt bran cond sub pod time code
1             package Unix::Uptime::Linux;
2              
3 4     4   18 use warnings;
  4         4  
  4         123  
4 4     4   20 use strict;
  4         4  
  4         1522  
5              
6             our $VERSION='0.4000';
7             $VERSION = eval $VERSION;
8              
9             sub uptime {
10 2     2 0 28 my $class = shift;
11 2 50       153 open my $proc_uptime, '<', '/proc/uptime'
12             or die "Failed to open /proc/uptime: $!";
13              
14 2         63 my $line = <$proc_uptime>;
15 2         25 my ($uptime) = $line =~ /^(\d+)/;
16 2         56 return $uptime;
17             }
18              
19             sub uptime_hires {
20 2     2 0 18 my $class = shift;
21              
22 2 50       12 unless ($class->_want_hires()) {
23 0         0 die "uptime_hires: you need to import Unix::Uptime with ':hires'";
24             }
25              
26 2 50       137 open my $proc_uptime, '<', '/proc/uptime'
27             or die "Failed to open /proc/uptime: $!";
28              
29 2         77 my $line = <$proc_uptime>;
30 2         29 my ($uptime) = $line =~ /^(\d+(\.\d+)?)/;
31 2         50 return $uptime;
32             }
33              
34             sub load {
35 1     1 0 27 my $class = shift;
36              
37 1 50       70 open my $proc_loadavg, '<', '/proc/loadavg'
38             or die "Failed to open /proc/loadavg: $!";
39              
40 1         29 my $line = <$proc_loadavg>;
41 1         11 my ($load1, $load5, $load15) = $line =~ /^(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/;
42 1         24 return ($load1, $load5, $load15);
43             }
44              
45             1;
46              
47             __END__