| 1 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package IO::Prompt::Tiny; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Prompt for user input with a default option | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Exporter (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our @ISA = qw/Exporter/; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | our @EXPORT_OK = qw/prompt/; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # Copied from ExtUtils::MakeMaker (by many authors) | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | sub prompt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prompt: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | my ( $mess, $def ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | Carp::croak("prompt function called without an argument") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | unless defined $mess; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | my $dispdef = defined $def ? "[$def] " : " "; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | $def = defined $def ? $def : ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | local $| = 1; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | local $\; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | print "$mess $dispdef"; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | my $ans; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | if ( $ENV{PERL_MM_USE_DEFAULT} || !_is_interactive() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ENV{"PERL_MM_USE_DEFAULT"} or not _is_interactive()
MC/DC100%2/2
$ENV{"PERL_MM_USE_DEFAULT"} or not _is_interactive()
$ENV{"PERL_MM_USE_DEFAULT"}
not _is_interactive()
Truth table100%3/3
A or not(B)
A= $ENV{"PERL_MM_USE_DEFAULT"}B= not _is_interactive()
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | print "$def\n"; | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | $ans = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | if ( defined $ans ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | chomp $ans; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | else { # user hit ctrl-D | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | ▶ | return ( !defined $ans || $ans eq '' ) ? $def : $ans; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $ans or $ans eq ""
MC/DC50%1/2
not defined $ans or $ans eq ""
not defined $ans
$ans eq ""
Truth table66%2/3
not(A) or B
A= not defined $ansB= $ans eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub _is_interactive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_interactive: called CC=9 SCAR=41.9
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | my ($out_handle) = ( @_, select ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | return 0 if not -t $out_handle; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( tied(*ARGV) or defined( fileno(ARGV) ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
tied *ARGV or defined fileno ARGV
MC/DC0%0/2
tied *ARGV or defined fileno ARGV
tied *ARGV
defined fileno ARGV
Truth table0%0/3
A or B
A= tied *ARGVB= defined fileno ARGV
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return -t *STDIN if defined $ARGV && $ARGV eq '-'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ARGV and $ARGV eq "-"
MC/DC0%0/2
defined $ARGV and $ARGV eq "-"
defined $ARGV
$ARGV eq "-"
Truth table0%0/3
A and B
A= defined $ARGVB= $ARGV eq "-"
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return @ARGV > 0 && $ARGV[0] eq '-' && -t *STDIN if eof *ARGV; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@ARGV > 0 && $ARGV[0] eq '-' && -t *STDIN
@ARGV > 0 and $ARGV[0] eq "-"
MC/DC0%0/3
@ARGV > 0 && $ARGV[0] eq '-' && -t *STDIN
@ARGV > 0
$ARGV[0] eq "-"
-t *STDIN
Truth table0%0/4
A and B && C
A= @ARGV > 0B= $ARGV[0] eq "-"C= -t *STDIN
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return -t *ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return -t *STDIN; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # vim: ts=2 sts=2 sw=2 et: | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||||||||||||||||