blib/lib/IO/Prompt/Tiny.pm

filter: Statementstmt 87.5% 35 / 40 Branchbran 50.0% 10 / 20 Conditioncond 27.7% 5 / 18 MC/DCmcdc 27.2% 3 / 11 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 62.8% 61 / 97 CC 17 SCAR 33.9
CC
17
Cov
64%
_is_interactive
65.9
prompt
9.1
BEGIN
1.0
CRAP 29.6
↑ Summary
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
BranchTrueFalseTotal
unless defined $mess 0 4 4
19 unless defined $mess;
20  
21 4 ▶ my $dispdef = defined $def ? "[$def] " : " ";
Branch: 1 branch
BranchTrueFalseTotal
defined $def ? : 4 0 4
22 4 ▶ $def = defined $def ? $def : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $def ? : 4 0 4
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
BranchTrueFalseTotal
if ($ENV{'PERL_MM_USE_DEFAULT'} or not _is_interactive()) { } 2 2 4
Condition100%3/3
$ENV{"PERL_MM_USE_DEFAULT"} or not _is_interactive()
l!l&&r!l&&!r
112
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()
ABresult
1X1
011
000
30 2 print "$def\n";
31 }
32 else {
33 2 $ans = <STDIN>;
34 2 ▶ if ( defined $ans ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ans) { } 1 1 2
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
BranchTrueFalseTotal
!defined($ans) || $ans eq '' ? : 3 1 4
Condition66%2/3
not defined $ans or $ans eq ""
l!l&&r!l&&!r
301
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 ""
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless -t $out_handle 1 0 1
50 0 ▶ if ( tied(*ARGV) or defined( fileno(ARGV) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (tied *ARGV or defined fileno ARGV) { } 0 0 0
Condition0%0/3
tied *ARGV or defined fileno ARGV
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
51 0 ▶ return -t *STDIN if defined $ARGV && $ARGV eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if defined $ARGV and $ARGV eq "-" 0 0 0
Condition0%0/3
defined $ARGV and $ARGV eq "-"
!ll&&!rl&&r
000
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 "-"
ABresult
0X0
100
111
52 0 ▶ return @ARGV > 0 && $ARGV[0] eq '-' && -t *STDIN if eof *ARGV;
Branch: 1 branch
BranchTrueFalseTotal
if eof ARGV 0 0 0
Condition0%0/6
@ARGV > 0 && $ARGV[0] eq '-' && -t *STDIN
!ll&&!rl&&r
000
@ARGV > 0 and $ARGV[0] eq "-"
!ll&&!rl&&r
000
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
ABCresult
0XX0
10X0
1100
1111
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__
↑ Summary