File Coverage

blib/lib/App/RemoteCommand/Util.pm
Criterion Covered Total %
statement 17 42 40.4
branch 1 6 16.6
condition n/a
subroutine 6 9 66.6
pod 0 2 0.0
total 24 59 40.6


line stmt bran cond sub pod time code
1             package App::RemoteCommand::Util;
2 1     1   10 use v5.24;
  1         2  
3 1     1   3 use warnings;
  1         2  
  1         101  
4 1     1   4 use experimental qw(lexical_subs signatures);
  1         1  
  1         4  
5              
6 1     1   110 use Exporter 'import';
  1         6  
  1         56  
7             our @EXPORT_OK = qw(prompt DEBUG logger);
8              
9 1 50   1   4 use constant DEBUG => $ENV{PERL_RCOMMAND_DEBUG} ? 1 : 0;
  1         1  
  1         85  
10              
11 1     1   566 use Term::ReadKey 'ReadMode';
  1         1845  
  1         313  
12              
13 0     0 0   sub logger (@args) {
  0            
  0            
14 0 0         my $msg = @args == 1 ? $args[0] : sprintf shift(@args), @args;
15 0           warn " | $msg\n";
16             }
17              
18 0     0 0   sub prompt ($msg) {
  0            
  0            
19 0           local $| = 1;
20 0           print $msg;
21 0           ReadMode 'noecho', \*STDIN;
22 0           my $SIGNAL = "Catch SIGINT\n";
23 0           my $answer;
24 0           eval {
25 0     0     local $SIG{INT} = sub (@) { die $SIGNAL };
  0            
  0            
  0            
26 0           $answer = ;
27             };
28 0           my $error = $@;
29 0           ReadMode 'restore', \*STDIN;
30 0           print "\n";
31 0 0         die $error if $error;
32 0           chomp $answer;
33 0           $answer;
34             }
35              
36             1;