line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
34529
|
use 5.006; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
20
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package IO::Prompt::Tiny; |
6
|
|
|
|
|
|
|
# ABSTRACT: Prompt for user input with a default option |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
3
|
use Exporter (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
11
|
1
|
|
|
1
|
|
3
|
use Carp (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
241
|
|
12
|
|
|
|
|
|
|
our @ISA = qw/Exporter/; |
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw/prompt/; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Copied from ExtUtils::MakeMaker (by many authors) |
16
|
|
|
|
|
|
|
sub prompt { |
17
|
4
|
|
|
4
|
1
|
7677
|
my ( $mess, $def ) = @_; |
18
|
4
|
50
|
|
|
|
11
|
Carp::croak("prompt function called without an argument") |
19
|
|
|
|
|
|
|
unless defined $mess; |
20
|
|
|
|
|
|
|
|
21
|
4
|
50
|
|
|
|
11
|
my $dispdef = defined $def ? "[$def] " : " "; |
22
|
4
|
50
|
|
|
|
7
|
$def = defined $def ? $def : ""; |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
10
|
local $| = 1; |
25
|
4
|
|
|
|
|
9
|
local $\; |
26
|
4
|
|
|
|
|
89
|
print "$mess $dispdef"; |
27
|
|
|
|
|
|
|
|
28
|
4
|
|
|
|
|
5
|
my $ans; |
29
|
4
|
100
|
100
|
|
|
19
|
if ( $ENV{PERL_MM_USE_DEFAULT} || !_is_interactive() ) { |
30
|
2
|
|
|
|
|
13
|
print "$def\n"; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
2
|
|
|
|
|
21
|
$ans = ; |
34
|
2
|
100
|
|
|
|
5
|
if ( defined $ans ) { |
35
|
1
|
|
|
|
|
3
|
chomp $ans; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { # user hit ctrl-D |
38
|
1
|
|
|
|
|
6
|
print "\n"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
4
|
100
|
66
|
|
|
35
|
return ( !defined $ans || $ans eq '' ) ? $def : $ans; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Copied (without comments) from IO::Interactive::Tiny by Daniel Muey, |
46
|
|
|
|
|
|
|
# based on IO::Interactive by Damian Conway and brian d foy |
47
|
|
|
|
|
|
|
sub _is_interactive { |
48
|
1
|
|
|
1
|
|
4
|
my ($out_handle) = ( @_, select ); |
49
|
1
|
50
|
|
|
|
8
|
return 0 if not -t $out_handle; |
50
|
0
|
0
|
0
|
|
|
|
if ( tied(*ARGV) or defined( fileno(ARGV) ) ) { |
51
|
0
|
0
|
0
|
|
|
|
return -t *STDIN if defined $ARGV && $ARGV eq '-'; |
52
|
0
|
0
|
0
|
|
|
|
return @ARGV > 0 && $ARGV[0] eq '-' && -t *STDIN if eof *ARGV; |
53
|
0
|
|
|
|
|
|
return -t *ARGV; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
0
|
|
|
|
|
|
return -t *STDIN; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# vim: ts=2 sts=2 sw=2 et: |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |