line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
1792
|
use 5.008008; |
|
3
|
|
|
|
|
13
|
|
2
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
76
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
168
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Ask::Clui; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.015'; |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
17
|
use Moo; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
21
|
|
11
|
3
|
|
|
3
|
|
3290
|
use Term::Clui 1.65 (); |
|
3
|
|
|
|
|
38178
|
|
|
3
|
|
|
|
|
104
|
|
12
|
3
|
|
|
3
|
|
24
|
use Path::Tiny 'path'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
170
|
|
13
|
3
|
|
|
3
|
|
20
|
use namespace::autoclean; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
30
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
with 'Ask::API'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub BUILD { |
18
|
0
|
|
|
0
|
0
|
0
|
STDOUT->autoflush( 1 ); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub is_usable { |
22
|
0
|
|
|
0
|
0
|
0
|
my ( $self ) = @_; |
23
|
0
|
0
|
|
|
|
0
|
-t STDIN and -t STDOUT; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub quality { |
27
|
15
|
|
|
15
|
0
|
60
|
my ( $self ) = ( shift ); |
28
|
15
|
50
|
33
|
|
|
143
|
( -t STDIN and -t STDOUT ) ? 91 : 30; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub info { |
32
|
0
|
|
|
0
|
0
|
|
my ( $self, %opts ) = ( shift, @_ ); |
33
|
0
|
|
|
|
|
|
chomp( my $text = $opts{text} ); |
34
|
0
|
|
|
|
|
|
Term::Clui::inform( $opts{text} ); |
35
|
0
|
|
|
|
|
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub warning { |
39
|
0
|
|
|
0
|
0
|
|
my ( $self, %opts ) = ( shift, @_ ); |
40
|
0
|
|
|
|
|
|
chomp( my $text = $opts{text} ); |
41
|
0
|
|
|
|
|
|
Term::Clui::inform( 'WARNING: ' . $opts{text} ); |
42
|
0
|
|
|
|
|
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub error { |
46
|
0
|
|
|
0
|
0
|
|
my ( $self, %opts ) = ( shift, @_ ); |
47
|
0
|
|
|
|
|
|
chomp( my $text = $opts{text} ); |
48
|
0
|
|
|
|
|
|
Term::Clui::inform( 'ERROR: ' . $opts{text} ); |
49
|
0
|
|
|
|
|
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub entry { |
53
|
0
|
|
|
0
|
0
|
|
my ( $self, %opts ) = ( shift, @_ ); |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if ( $opts{hide_text} ) { |
56
|
0
|
|
|
|
|
|
return Term::Clui::ask_password( $opts{text} ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
0
|
|
|
|
return Term::Clui::ask( $opts{text}, $opts{default} || '' ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub question { |
63
|
0
|
|
|
0
|
0
|
|
my ( $self, %opts ) = ( shift, @_ ); |
64
|
0
|
|
|
|
|
|
chomp( my $text = $opts{text} ); |
65
|
0
|
|
|
|
|
|
return Term::Clui::confirm( $opts{text} ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $_choices = sub { |
69
|
|
|
|
|
|
|
my $ref = shift; |
70
|
|
|
|
|
|
|
map $_->[0], @$ref; |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub single_choice { |
74
|
0
|
|
|
0
|
0
|
|
my ( $self, %opts ) = ( shift, @_ ); |
75
|
0
|
|
|
|
|
|
local $ENV{CLUI_DIR} = 'OFF'; |
76
|
0
|
|
|
|
|
|
scalar Term::Clui::choose( $opts{text}, $_choices->( $opts{choices} ) ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub multiple_choice { |
80
|
0
|
|
|
0
|
0
|
|
my ( $self, %opts ) = ( shift, @_ ); |
81
|
0
|
|
|
|
|
|
local $ENV{CLUI_DIR} = 'OFF'; |
82
|
0
|
|
|
|
|
|
Term::Clui::choose( $opts{text}, $_choices->( $opts{choices} ) ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub file_selection { |
86
|
0
|
|
|
0
|
0
|
|
my ( $self, %opts ) = ( shift, @_ ); |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my @chosen; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
FILE: { |
91
|
0
|
|
|
|
|
|
my $got = Term::Clui::ask_filename( $opts{text} ); |
|
0
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
if ( not length $got ) { |
94
|
0
|
0
|
|
|
|
|
last FILE if $opts{multiple}; |
95
|
0
|
|
|
|
|
|
redo FILE; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$got = path $got; |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
0
|
|
|
|
if ( $opts{existing} and not $got->exists ) { |
101
|
0
|
|
|
|
|
|
$self->error( text => 'Does not exist.' ); |
102
|
0
|
|
|
|
|
|
redo FILE; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
0
|
|
|
|
if ( $opts{directory} and not $got->is_dir ) { |
106
|
0
|
|
|
|
|
|
$self->error( text => 'Is not a directory.' ); |
107
|
0
|
|
|
|
|
|
redo FILE; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
push @chosen, $got; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if ( $opts{multiple} ) { |
113
|
0
|
|
|
|
|
|
$self->info( text => 'Enter another file, or leave blank to finish.' ); |
114
|
0
|
|
|
|
|
|
redo FILE; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} #/ FILE: |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
$opts{multiple} ? @chosen : $chosen[0]; |
119
|
|
|
|
|
|
|
} #/ sub file_selection |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |