| 1 | package App::PS1::Plugin::Uptime; | ||||||||||
| 2 | |||||||||||
| 3 | # Created on: 2011-06-21 09:49:08 | ||||||||||
| 4 | # Create by: Ivan Wills | ||||||||||
| 5 | # $Id$ | ||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Data::Dumper qw/Dumper/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use English qw/ -no_match_vars /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use Term::ANSIColor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | our $VERSION = 0.08; | |||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | sub uptime { | ||||||||
|
Subroutine
uptime: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 20 | 0 | my ($self, $options) = @_; | |||||||||
| 21 | 0 | my ($uptime) = eval { split /\s+/, path('/proc/uptime')->slurp }; | |||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | return if !$uptime; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | |||||||||||
| 25 | 0 | my $days = int $uptime / 60 / 60 / 24; | |||||||||
| 26 | 0 | my $hours = int ( ( $uptime - $days * 60 * 60 * 24 ) / 60 / 60 ); | |||||||||
| 27 | 0 | my $minutes = int ( ( $uptime - $days * 60 * 60 * 24 - $hours * 60 * 60 ) / 60 ); | |||||||||
| 28 | |||||||||||
| 29 | 0 | my $up = sprintf "%dd%dh%dm", $days, $hours, $minutes; | |||||||||
| 30 | 0 | my $length = length $up; | |||||||||
| 31 | 0 | $up = $self->colour('up_time') . $up; | |||||||||
| 32 | |||||||||||
| 33 | 0 | return $self->surround( 4 + $length, $self->colour('up_label') . "up: $up" ); | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 1 | 1; | |||||||||
| 37 | |||||||||||
| 38 | __END__ | ||||||||||