lib/Chj/Util/AskYN.pm

filter: Statementstmt 48.2% 14 / 29 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 41.8% 18 / 43 CC 5 SCAR 28.4
CC
5
Cov
38%
maybe_askyn
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 17.1
« lib/Chj/xhome.pm ↑ Summary lib/Chj/IO/Dir.pm »
1 #
2 # Copyright (c) 2003-2015 Christian Jaeger, copying@christianjaeger.ch
3 #
4 # This is free software, offered under either the same terms as perl 5
5 # or the terms of the Artistic License version 2 or the terms of the
6 # MIT License (Expat version). See the file COPYING.md that came
7 # bundled with this file.
8 #
9  
10 =head1 NAME
11  
12 Chj::Util::AskYN
13  
14 =head1 SYNOPSIS
15  
16 use Chj::Util::AskYN;
17  
18 LP: {
19 if (maybe_askyn "Do you want to retry?") {
20 redo LP;
21 }
22 }
23  
24 =head1 DESCRIPTION
25  
26 Simply ask for a boolean question on stdout/stdin. Accept y/n, yes/no
27 in english, german and french and return those as boolean
28 true/false. If the user closes the input (using ctl-d), undef is
29 returned.
30  
31 =head1 TODO
32  
33 Delete this and use something else?
34  
35 =head1 NOTE
36  
37 This is alpha software! Read the status section in the package README
38 or on the L<website|http://functional-perl.org/>.
39  
40 =cut
41  
42 package Chj::Util::AskYN;
43 1 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 our @EXPORT = qw(maybe_askyn);
45  
46 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 0 ▶sub maybe_askyn {
Subroutine maybe_askyn: not called CC=5 SCAR=34.0
Pod undocumented
51 0 my ($maybe_prompt) = @_;
52 0 local $| = 1;
53 ASK: {
54 0 ▶ if (defined $maybe_prompt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maybe_prompt) 0 0 0
55 0 print $maybe_prompt;
56 }
57 0 print " ";
58 0 my $ans = <STDIN>;
59 0 ▶ if (defined $ans) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ans) { } 0 0 0
60 0 ▶ if ($ans =~ /^n(?:o|ein|ada|on)?$/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ans =~ /^n(?:o|ein|ada|on)?$/i) { } 0 0 0
elsif ($ans =~ /^(?:ja|yes|j|y|oui)$/i) { } 0 0 0
61 0 ''
62 } elsif ($ans =~ /^(?:ja|yes|j|y|oui)$/i) {
63 0 1
64 } else {
65 0 print "Please answer with yes or no or their initials, "
66 . "or the same in french or german.\n";
67 0 redo ASK;
68 }
69 } else {
70  
71 # EOF, i.e. ctl-d
72 0 print "\n";
73 undef
74 0 }
75 }
76 }
77  
78 1 1
« lib/Chj/xhome.pm ↑ Summary lib/Chj/IO/Dir.pm »