line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
29029
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package PortageXS::UI::Spinner; |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
34
|
$PortageXS::UI::Spinner::AUTHORITY = 'cpan:KENTNL'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
{ |
9
|
|
|
|
|
|
|
$PortageXS::UI::Spinner::VERSION = '0.3.1'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Dancing Console progress spinner bling. |
13
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# PortageXS::UI::Spinner |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# author : Christian Hartmann |
18
|
|
|
|
|
|
|
# license : GPL-2 |
19
|
|
|
|
|
|
|
# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS/UI/Spinner.pm,v 1.1.1.1 2006/11/13 00:28:34 ian Exp $ |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify it under |
24
|
|
|
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software |
25
|
|
|
|
|
|
|
# Foundation; either version 2 of the License, or (at your option) any later |
26
|
|
|
|
|
|
|
# version. |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
959
|
use Moo; |
|
1
|
|
|
|
|
18221
|
|
|
1
|
|
|
|
|
6
|
|
31
|
1
|
|
|
1
|
|
3132
|
use IO::Handle; |
|
1
|
|
|
|
|
8064
|
|
|
1
|
|
|
|
|
427
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has spinstate => ( is => rwp =>, default => sub { 0 } ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has output_handle => ( |
40
|
|
|
|
|
|
|
is => ro =>, |
41
|
|
|
|
|
|
|
default => sub { |
42
|
|
|
|
|
|
|
my $handle = \*STDOUT; |
43
|
|
|
|
|
|
|
$handle->autoflush(1); |
44
|
|
|
|
|
|
|
return $handle; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has spinstates => ( |
50
|
|
|
|
|
|
|
is => ro =>, |
51
|
|
|
|
|
|
|
default => sub { |
52
|
|
|
|
|
|
|
[ '/', '-', '\\', '|' ]; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
|
|
sub _last_spinstate { return $#{ $_[0]->spinstates } } |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _increment_spinstate { |
61
|
0
|
|
|
0
|
|
|
my $self = shift; |
62
|
0
|
|
|
|
|
|
my $rval = $self->spinstate; |
63
|
0
|
|
|
|
|
|
my $nextstate = $rval + 1; |
64
|
0
|
0
|
|
|
|
|
if ( $nextstate > $self->_last_spinstate ) { |
65
|
0
|
|
|
|
|
|
$nextstate = 0; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
$self->_set_spinstate($nextstate); |
68
|
0
|
|
|
|
|
|
return $rval; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _get_next_spinstate { |
73
|
0
|
|
|
0
|
|
|
my (@states) = @{ $_[0]->spinstates }; |
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $states[ $_[0]->_increment_spinstate ]; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _print_to_output { |
79
|
0
|
|
|
0
|
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
$self->output_handle->print(@_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub spin { |
85
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
86
|
0
|
|
|
|
|
|
$self->_print_to_output( "\b" . $self->_get_next_spinstate ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub reset { |
91
|
0
|
|
|
0
|
1
|
|
$_[0]->_print_to_output("\b \b"); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |