line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
22
|
use 5.008008; |
|
1
|
|
|
|
|
5
|
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Ask::Question; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.013'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
8
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
11
|
1
|
|
|
1
|
|
401
|
use Scalar::Util 'blessed'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
87
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use overload ( |
14
|
2
|
|
|
2
|
|
2182
|
'&{}' => sub { shift->coderef }, |
15
|
1
|
|
|
|
|
16
|
fallback => 1, |
16
|
1
|
|
|
1
|
|
7
|
); |
|
1
|
|
|
|
|
2
|
|
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
1
|
0
|
sub ask { shift->coderef->() } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has backend => ( is => 'lazy' ); |
21
|
|
|
|
|
|
|
has type => ( is => 'rwp', predicate => 1 ); |
22
|
|
|
|
|
|
|
has spec => ( is => 'rwp', predicate => 1 ); |
23
|
|
|
|
|
|
|
has title => ( is => 'rwp', predicate => 1 ); |
24
|
|
|
|
|
|
|
has text => ( is => 'rwp', predicate => 1 ); |
25
|
|
|
|
|
|
|
has multiple => ( is => 'rwp' ); |
26
|
|
|
|
|
|
|
has choices => ( is => 'rwp' ); |
27
|
|
|
|
|
|
|
has coderef => ( is => 'lazy', init_arg => undef ); |
28
|
|
|
|
|
|
|
has default => ( is => 'rwp', predicate => 1 ); |
29
|
|
|
|
|
|
|
has method => ( is => 'rwp' ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _build_backend { |
32
|
0
|
|
|
0
|
|
0
|
require Ask; |
33
|
0
|
|
|
|
|
0
|
'Ask'->detect; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub BUILDARGS { |
37
|
1
|
|
|
1
|
0
|
1773
|
my ( $class, @args ) = ( shift, @_ ); |
38
|
1
|
50
|
33
|
|
|
5
|
@args == 1 and ref $args[0] and return $args[0]; |
39
|
1
|
50
|
|
|
|
5
|
unshift @args, 'text' if @args % 2; |
40
|
1
|
|
|
|
|
22
|
+{@args}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub isa { # trick Moose |
44
|
0
|
0
|
|
0
|
0
|
0
|
return 1 if $_[1] eq __PACKAGE__; |
45
|
0
|
0
|
|
|
|
0
|
return 1 if $_[1] eq 'Class::MOP::Method'; |
46
|
0
|
0
|
|
|
|
0
|
return 1 if $_[1] eq 'Moo::Object'; |
47
|
0
|
0
|
|
|
|
0
|
return 1 if $_[1] eq 'UNIVERSAL'; |
48
|
0
|
|
|
|
|
0
|
return 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _build_coderef { |
52
|
1
|
|
|
1
|
|
10
|
my ( $self ) = ( shift ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Avoid closing over $self |
55
|
1
|
|
|
|
|
18
|
my $ask = $self->backend; |
56
|
1
|
|
|
|
|
11
|
my $type = $self->type; |
57
|
1
|
|
|
|
|
3
|
my $choices = $self->choices; |
58
|
1
|
|
|
|
|
7
|
my $multiple = $self->multiple; |
59
|
1
|
|
50
|
|
|
17
|
my $spec = $self->spec || {}; |
60
|
1
|
50
|
|
|
|
12
|
my $default = $self->has_default ? $self->default : $spec->{default}; |
61
|
1
|
50
|
|
|
|
8
|
my $text = $self->has_text ? $self->text : $spec->{documentation}; |
62
|
1
|
|
|
|
|
4
|
my $method = $self->method; |
63
|
1
|
|
|
|
|
3
|
my $title = $self->title; |
64
|
|
|
|
|
|
|
|
65
|
1
|
50
|
33
|
|
|
9
|
undef $default if ( blessed $default and $default == $self ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return sub { |
68
|
1
|
|
|
1
|
|
4936
|
my @args = @_; |
69
|
1
|
|
|
|
|
3
|
my ( $instance ) = ( @args ); |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
2
|
my $local_text = $text; |
72
|
1
|
50
|
|
|
|
4
|
if ( ref $local_text ) { |
73
|
0
|
|
|
|
|
0
|
$local_text = $local_text->( @args ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
2
|
my $local_default = $default; |
77
|
1
|
50
|
|
|
|
4
|
if ( ref $local_default ) { |
78
|
0
|
|
|
|
|
0
|
$local_default = $local_default->( @args ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
3
|
my $local_type = $type; |
82
|
1
|
50
|
|
|
|
3
|
if ( not ref $local_type ) { |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
0
|
|
|
0
|
$local_type ||= $spec->{type}; |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
0
|
|
|
0
|
if ( defined $local_type and not ref $local_type ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
87
|
0
|
|
|
|
|
0
|
require Type::Utils; |
88
|
0
|
|
|
|
|
0
|
$local_type = Type::Utils::dwim_type( |
89
|
|
|
|
|
|
|
$local_type, |
90
|
|
|
|
|
|
|
for => ref( $instance ), |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
elsif ( defined $spec->{'isa'} and not ref $local_type ) { |
95
|
|
|
|
|
|
|
$local_type = |
96
|
|
|
|
|
|
|
ref( $spec->{'isa'} ) |
97
|
|
|
|
|
|
|
? $spec->{'isa'} |
98
|
0
|
0
|
|
|
|
0
|
: do { |
99
|
0
|
|
|
|
|
0
|
require Type::Utils; |
100
|
|
|
|
|
|
|
Type::Utils::dwim_type( |
101
|
0
|
|
|
|
|
0
|
$spec->{'isa'}, |
102
|
|
|
|
|
|
|
for => ref( $instance ), |
103
|
|
|
|
|
|
|
fallback => ['make_class_type'], |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
} #/ elsif ( defined $spec->{'isa'...}) |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
elsif ( defined $spec->{'does'} and not ref $local_type ) { |
109
|
|
|
|
|
|
|
$local_type = |
110
|
|
|
|
|
|
|
ref( $spec->{'does'} ) |
111
|
|
|
|
|
|
|
? $spec->{'does'} |
112
|
0
|
0
|
|
|
|
0
|
: do { |
113
|
0
|
|
|
|
|
0
|
require Type::Utils; |
114
|
|
|
|
|
|
|
Type::Utils::dwim_type( |
115
|
0
|
|
|
|
|
0
|
$spec->{'does'}, |
116
|
|
|
|
|
|
|
for => ref( $instance ), |
117
|
|
|
|
|
|
|
fallback => ['make_role_type'], |
118
|
|
|
|
|
|
|
); |
119
|
|
|
|
|
|
|
}; |
120
|
|
|
|
|
|
|
} #/ elsif ( defined $spec->{'does'...}) |
121
|
|
|
|
|
|
|
} #/ if ( not ref $local_type) |
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
4
|
my $local_multiple = $multiple; |
124
|
1
|
50
|
33
|
|
|
9
|
if ( blessed $local_type and not defined $local_multiple ) { |
125
|
1
|
|
|
|
|
8
|
require Types::Standard; |
126
|
1
|
|
|
|
|
7
|
$local_multiple = ( $local_type <= Types::Standard::ArrayRef() ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
511
|
my $local_choices = $choices; |
130
|
1
|
50
|
33
|
|
|
13
|
if ( defined $local_type |
|
|
|
33
|
|
|
|
|
131
|
|
|
|
|
|
|
and blessed $local_type |
132
|
|
|
|
|
|
|
and not defined $local_choices ) |
133
|
|
|
|
|
|
|
{ |
134
|
1
|
|
|
|
|
7
|
my $map = sub { [ map [ $_ x 2 ], @{ +shift } ] }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
135
|
1
|
|
|
|
|
7
|
require Types::Standard; |
136
|
1
|
50
|
33
|
|
|
3
|
if ( $local_type->isa( 'Type::Tiny::Enum' ) ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
137
|
0
|
|
|
|
|
0
|
$local_choices = $map->( $local_type->unique_values ); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
elsif ( $local_type->isa( 'Moose::Meta::TypeConstraint::Enum' ) ) { |
140
|
0
|
|
|
|
|
0
|
$local_choices = $map->( $local_type->values ); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
elsif ( $local_type <= Types::Standard::ArrayRef() |
143
|
|
|
|
|
|
|
and $local_type->is_parameterized ) |
144
|
|
|
|
|
|
|
{ |
145
|
1
|
|
|
|
|
365
|
my $tp = $local_type->type_parameter; |
146
|
1
|
50
|
|
|
|
10
|
if ( $tp->isa( 'Type::Tiny::Enum' ) ) { |
|
|
50
|
|
|
|
|
|
147
|
0
|
|
|
|
|
0
|
$local_choices = $map->( $tp->unique_values ); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
elsif ( $tp->isa( 'Moose::Meta::TypeConstraint::Enum' ) ) { |
150
|
0
|
|
|
|
|
0
|
$local_choices = $map->( $tp->values ); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} #/ elsif ( $local_type <= Types::Standard::ArrayRef...) |
153
|
|
|
|
|
|
|
} #/ if ( defined $local_type...) |
154
|
|
|
|
|
|
|
|
155
|
1
|
|
|
|
|
24
|
my $is_bool; |
156
|
1
|
50
|
33
|
|
|
7
|
if ( defined $local_type and blessed $local_type ) { |
157
|
1
|
|
|
|
|
6
|
require Types::Standard; |
158
|
1
|
|
|
|
|
5
|
$is_bool = !!( $local_type <= Types::Standard::Bool() ); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
1
|
|
|
|
|
936
|
my ( $is_path, $is_dir, $is_abs ); |
162
|
1
|
50
|
33
|
|
|
8
|
if ( defined $local_type and blessed $local_type ) { |
163
|
|
|
|
|
|
|
|
164
|
1
|
50
|
|
|
|
2
|
if ( eval { require Types::Path::Tiny } ) { |
|
1
|
|
|
|
|
216
|
|
165
|
0
|
|
|
|
|
0
|
$is_path = !!( $local_type <= Types::Path::Tiny::Path() ); |
166
|
0
|
0
|
|
|
|
0
|
my $path_type = $is_path ? $local_type : undef; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
0
|
require Types::Standard; |
169
|
0
|
0
|
0
|
|
|
0
|
if ( !$is_path |
|
|
|
0
|
|
|
|
|
170
|
|
|
|
|
|
|
and $local_type <= Types::Standard::ArrayRef() |
171
|
|
|
|
|
|
|
and $local_type->is_parameterized ) |
172
|
|
|
|
|
|
|
{ |
173
|
0
|
|
|
|
|
0
|
my $tp = $local_type->type_parameter; |
174
|
0
|
0
|
|
|
|
0
|
if ( $tp <= Types::Path::Tiny::Path() ) { |
175
|
0
|
|
|
|
|
0
|
$is_path = 1; |
176
|
0
|
|
|
|
|
0
|
$local_multiple = 1; |
177
|
0
|
|
|
|
|
0
|
$path_type = $tp; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
} #/ if ( !$is_path and $local_type...) |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
0
|
if ( $is_path ) { |
182
|
0
|
|
0
|
|
|
0
|
$is_dir = ( $path_type <= Types::Path::Tiny::Dir() ) |
183
|
|
|
|
|
|
|
|| ( $path_type <= Types::Path::Tiny::AbsDir() ); |
184
|
0
|
|
0
|
|
|
0
|
$is_abs = |
185
|
|
|
|
|
|
|
( $path_type <= Types::Path::Tiny::AbsPath() ) |
186
|
|
|
|
|
|
|
|| ( $path_type <= Types::Path::Tiny::AbsFile() ) |
187
|
|
|
|
|
|
|
|| ( $path_type <= Types::Path::Tiny::AbsDir() ); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
} #/ if ( eval { require Types::Path::Tiny...}) |
190
|
|
|
|
|
|
|
} #/ if ( defined $local_type...) |
191
|
|
|
|
|
|
|
|
192
|
1
|
50
|
|
|
|
9
|
my @common = ( |
|
|
50
|
|
|
|
|
|
193
|
|
|
|
|
|
|
text => $local_text, |
194
|
|
|
|
|
|
|
defined( $title ) ? ( title => $title ) : (), |
195
|
|
|
|
|
|
|
defined( $local_default ) ? ( default => $local_default ) : (), |
196
|
|
|
|
|
|
|
); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
my $get_answer = sub { |
199
|
|
|
|
|
|
|
|
200
|
2
|
50
|
33
|
|
|
30
|
if ( $method ) { |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
201
|
0
|
|
|
|
|
0
|
my $str = $ask->$method( |
202
|
|
|
|
|
|
|
choices => $choices, |
203
|
|
|
|
|
|
|
multiple => $multiple, |
204
|
|
|
|
|
|
|
@common, |
205
|
|
|
|
|
|
|
); |
206
|
0
|
|
|
|
|
0
|
chomp $str; |
207
|
0
|
|
|
|
|
0
|
return $str; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
elsif ( $local_multiple and $local_choices ) { |
211
|
0
|
|
|
|
|
0
|
my @values = $ask->multiple_choice( @common, choices => $local_choices ); |
212
|
0
|
|
|
|
|
0
|
return \@values; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
elsif ( $local_choices ) { |
216
|
0
|
|
|
|
|
0
|
return $ask->single_choice( @common, choices => $local_choices ); |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
elsif ( $local_multiple and $is_path ) { |
220
|
0
|
|
|
|
|
0
|
require Path::Tiny; |
221
|
0
|
|
|
|
|
0
|
my @paths = map( 'Path::Tiny'->new( $_ ), |
222
|
|
|
|
|
|
|
$ask->file_selection( @common, directory => $is_dir, multiple => 1 ), |
223
|
|
|
|
|
|
|
); |
224
|
0
|
0
|
|
|
|
0
|
if ( $is_abs ) { |
225
|
0
|
|
|
|
|
0
|
@paths = map $_->absolute, @paths; |
226
|
|
|
|
|
|
|
} |
227
|
0
|
|
|
|
|
0
|
return \@paths; |
228
|
|
|
|
|
|
|
} #/ elsif ( $local_multiple and...) |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
elsif ( $is_path ) { |
231
|
0
|
|
|
|
|
0
|
require Path::Tiny; |
232
|
0
|
|
|
|
|
0
|
my $path = 'Path::Tiny'->new( |
233
|
|
|
|
|
|
|
$ask->file_selection( @common, directory => $is_dir, multiple => 0 ), |
234
|
|
|
|
|
|
|
); |
235
|
0
|
0
|
|
|
|
0
|
return $is_abs ? $path->absolute : $path; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
elsif ( $is_bool ) { |
239
|
0
|
|
|
|
|
0
|
return $ask->question( @common, ok_label => 'TRUE', cancel_label => 'FALSE' ); |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
elsif ( $local_multiple ) { |
243
|
2
|
|
|
|
|
5
|
my @strings; |
244
|
2
|
|
|
|
|
4
|
STRING: while ( 1 ) { |
245
|
6
|
|
|
|
|
18
|
chomp( my $str = $ask->entry( @common ) ); |
246
|
6
|
100
|
|
|
|
45
|
if ( length $str ) { |
247
|
4
|
|
|
|
|
9
|
push @strings, $str; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
else { |
250
|
2
|
|
|
|
|
6
|
last STRING; |
251
|
|
|
|
|
|
|
} |
252
|
4
|
50
|
|
|
|
37
|
return if @strings >= 100; |
253
|
|
|
|
|
|
|
} #/ STRING: while ( 1 ) |
254
|
2
|
|
|
|
|
24
|
return \@strings; |
255
|
|
|
|
|
|
|
} #/ elsif ( $local_multiple ) |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
else { |
258
|
0
|
|
|
|
|
0
|
chomp( my $str = $ask->entry( @common ) ); |
259
|
0
|
|
|
|
|
0
|
return $str; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
1
|
|
|
|
|
16
|
}; # sub $get_answer |
263
|
|
|
|
|
|
|
|
264
|
1
|
|
|
|
|
3
|
my $answer; |
265
|
1
|
|
|
|
|
3
|
my $tries = 0; |
266
|
1
|
|
|
|
|
3
|
TRY: while ( !defined $answer ) { |
267
|
|
|
|
|
|
|
|
268
|
2
|
|
|
|
|
7
|
$answer = $get_answer->(); |
269
|
2
|
|
|
|
|
5
|
++$tries; |
270
|
|
|
|
|
|
|
|
271
|
2
|
50
|
|
|
|
11
|
if ( blessed $local_type ) { |
|
|
0
|
|
|
|
|
|
272
|
2
|
|
|
|
|
9
|
my $okay = $local_type->check( $answer ); |
273
|
|
|
|
|
|
|
|
274
|
2
|
50
|
33
|
|
|
59
|
if ( !$okay |
|
|
|
33
|
|
|
|
|
275
|
|
|
|
|
|
|
and $local_type->can( 'has_coercion' ) |
276
|
|
|
|
|
|
|
and $local_type->has_coercion ) |
277
|
|
|
|
|
|
|
{ |
278
|
2
|
|
|
|
|
84
|
$answer = $local_type->coerce( $answer ); |
279
|
2
|
|
|
|
|
1376
|
$okay = $local_type->check( $answer ); |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
|
282
|
2
|
100
|
|
|
|
41
|
if ( not $okay ) { |
283
|
1
|
|
|
|
|
5
|
$ask->error( text => $local_type->get_message( $answer ) ); |
284
|
1
|
|
|
|
|
9
|
$answer = undef; |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
} #/ if ( blessed $local_type) |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
elsif ( ref $local_type ) { |
289
|
0
|
|
|
|
|
0
|
local $@; |
290
|
0
|
|
|
|
|
0
|
my $okay = eval { $local_type->( $answer ); 1 }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
291
|
0
|
0
|
|
|
|
0
|
if ( not $okay ) { |
292
|
0
|
|
|
|
|
0
|
$ask->error( text => $@ ); |
293
|
0
|
|
|
|
|
0
|
$answer = undef; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
2
|
50
|
33
|
|
|
11
|
if ( $tries >= 3 and not defined $answer ) { |
298
|
0
|
|
|
|
|
0
|
$ask->error( text => 'Too many retries!' ); |
299
|
0
|
|
|
|
|
0
|
last TRY; |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
} #/ TRY: while ( !defined $answer ) |
302
|
|
|
|
|
|
|
|
303
|
1
|
50
|
|
|
|
45
|
return $answer if defined $answer; |
304
|
0
|
|
|
|
|
|
return $local_default; |
305
|
1
|
|
|
|
|
10
|
}; # built sub |
306
|
|
|
|
|
|
|
} #/ sub _build_coderef |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
1; |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
__END__ |