line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
1
|
|
1008
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
10
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
11
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
70
|
|
12
|
1
|
|
|
1
|
|
6
|
use Data::Dumper qw/Dumper/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
13
|
1
|
|
|
1
|
|
15
|
use English qw/ -no_match_vars /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
14
|
1
|
|
|
1
|
|
364
|
use Term::ANSIColor; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
46
|
|
15
|
1
|
|
|
1
|
|
7
|
use Path::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
321
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = 0.08; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub uptime { |
20
|
0
|
|
|
0
|
1
|
|
my ($self, $options) = @_; |
21
|
0
|
|
|
|
|
|
my ($uptime) = eval { split /\s+/, path('/proc/uptime')->slurp }; |
|
0
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
return if !$uptime; |
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; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__END__ |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
App::PS1::Plugin::Uptime - Adds system uptime to prompt |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 VERSION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This documentation refers to App::PS1::Plugin::Uptime version 0.08. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use App::PS1::Plugin::Uptime; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Brief but working code example(s) here showing the most common usage(s) |
53
|
|
|
|
|
|
|
# This section will be as far as many users bother reading, so make it as |
54
|
|
|
|
|
|
|
# educational and exemplary as possible. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head3 C<uptime ()> |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Current system uptime. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
There are no known bugs in this module. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Patches are welcome. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Copyright (c) 2011 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW, Australia 2077) |
88
|
|
|
|
|
|
|
All rights reserved. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
91
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
92
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
93
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
94
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |