line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Console; |
2
|
1
|
|
|
1
|
|
56079
|
use Mojo::Base 'Mojolicious::Command'; |
|
1
|
|
|
|
|
160548
|
|
|
1
|
|
|
|
|
7
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
41740
|
use List::Util qw(any none); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
380
|
use Mojo::Console::Input; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
356
|
use Mojo::Console::Output; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'input' => sub { Mojo::Console::Input->new }; |
12
|
|
|
|
|
|
|
has 'max_attempts' => 10; |
13
|
|
|
|
|
|
|
has 'output' => sub { Mojo::Console::Output->new }; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub ask { |
16
|
0
|
|
|
0
|
0
|
|
my ($self, $message, $required) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $attempts = $self->max_attempts; |
19
|
0
|
|
|
|
|
|
my $answer = ''; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
0
|
|
|
|
while ((($required || $attempts == 10) && !$answer) && $attempts--) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
22
|
0
|
|
|
|
|
|
$self->line($message . ' '); |
23
|
0
|
|
|
|
|
|
$answer = $self->input->ask; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
if ($attempts < 0) { |
27
|
0
|
|
|
|
|
|
$self->error("Please answer the question.\n"); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return $answer; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub confirm { |
34
|
0
|
|
|
0
|
0
|
|
my ($self, $message, $default) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
0
|
0
|
|
|
my $default_yes = (any { lc($default || '') eq $_ } qw/y yes/); |
|
0
|
|
|
|
|
|
|
37
|
0
|
|
0
|
0
|
|
|
my $default_no = (any { lc($default || '') eq $_ } qw/n no/); |
|
0
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $attempts = $self->max_attempts; |
40
|
0
|
|
|
|
|
|
my $answer = ''; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
0
|
0
|
|
|
while ((none { lc($answer) eq $_ } qw/y yes n no/) && $attempts--) { |
|
0
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->line($message); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$self->success(' [yes/no] '); |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if ($default) { |
48
|
0
|
|
|
|
|
|
$self->warn(sprintf('[default=%s] ', $default)); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
0
|
|
|
|
$answer = $self->input->ask || $default; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if ($attempts < 0) { |
55
|
0
|
|
|
|
|
|
$self->error("Please answer with [yes/no]\n"); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
0
|
|
|
return (any { lc($answer) eq $_ } qw/y yes/) ? 1 : 0; |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub choice { |
62
|
0
|
|
|
0
|
0
|
|
my ($self, $message, $choices, $default) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $attempts = $self->max_attempts; |
65
|
0
|
|
|
|
|
|
my $answer = ''; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
0
|
0
|
|
|
while ((none { $answer eq $_ } @$choices) && $attempts--) { |
|
0
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$self->line($message); |
69
|
0
|
|
|
|
|
|
$self->success(sprintf(' [%s] ', join(', ', @$choices))); |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if ($default) { |
72
|
0
|
|
|
|
|
|
$self->warn(sprintf('[default=%s] ', $default)); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
0
|
|
|
|
$answer = $self->input->ask || $default; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if ($attempts < 0) { |
79
|
0
|
|
|
|
|
|
$self->error(sprintf("Please chose one of the following options: [%s] \n", join(', ', @$choices))); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return $answer; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub error { |
86
|
0
|
|
|
0
|
0
|
|
return shift->output->error(@_); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub info { |
90
|
0
|
|
|
0
|
0
|
|
return shift->output->info(@_); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub line { |
94
|
0
|
|
|
0
|
0
|
|
return shift->output->line(@_); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub newline { |
98
|
0
|
|
|
0
|
0
|
|
return shift->output->newline(@_); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub success { |
102
|
0
|
|
|
0
|
0
|
|
return shift->output->success(@_); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub warn { |
106
|
0
|
|
|
0
|
0
|
|
return shift->output->warn(@_); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |