| 1 | package Object::Remote::Prompt; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strictures 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 11 | our @EXPORT = qw(prompt prompt_pw); | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 11 | our ($prompt, $prompt_pw); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub _local_prompt { | ||||||||||||||||||||||||||
|
Subroutine
_local_prompt: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 12 | 0 | _local_prompt_core(0, @_); | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub _local_prompt_pw { | ||||||||||||||||||||||||||
|
Subroutine
_local_prompt_pw: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 16 | 0 | _local_prompt_core(1, @_); | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 11 | our %Prompt_Cache; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub _local_prompt_core { | ||||||||||||||||||||||||||
|
Subroutine
_local_prompt_core: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 22 | 0 | my ($pw, $message, $default, $opts) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if ($opts->{cache} and my $hit = $Prompt_Cache{$message}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts->{"cache"} and my $hit = $Object::Remote::Prompt::Prompt_Cache{$message}
MC/DC0%0/2
$opts->{"cache"} and my $hit = $Object::Remote::Prompt::Prompt_Cache{$message}
$opts->{"cache"}
my $hit = $Object::Remote::Prompt::Prompt_Cache{$message}
Truth table0%0/3
A and B
A= $opts->{"cache"}B= my $hit = $Object::Remote::Prompt::Prompt_Cache{$message}
| |||||||||||||||||||||||||||||
| 25 | 0 | return $hit; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | STDOUT->autoflush(1); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | system('stty -echo') if $pw; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | print STDOUT "${message}: "; | |||||||||||||||||||||||||||
| 33 | 0 | chomp(my $res = <STDIN>); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | print STDOUT "\n" if $pw; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | system('stty echo') if $pw; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $Prompt_Cache{$message} = $res if $opts->{cache}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | return $res; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub prompt { | ||||||||||||||||||||||||||
|
Subroutine
prompt: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | die "User input wanted - $_[0] - but no prompt available" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | unless $prompt; | ||||||||||||||||||||||||||||
| 46 | 0 | goto &$prompt; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub prompt_pw { | ||||||||||||||||||||||||||
|
Subroutine
prompt_pw: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | die "User input wanted - $_[0] - but no password prompt available" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | unless $prompt_pw; | ||||||||||||||||||||||||||||
| 52 | 0 | goto &$prompt_pw; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 11 | ▶ | if (-t STDIN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | $prompt = \&_local_prompt; | |||||||||||||||||||||||||||
| 57 | 0 | $prompt_pw = \&_local_prompt_pw; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub set_local_prompt_command { | ||||||||||||||||||||||||||
|
Subroutine
set_local_prompt_command: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | ($prompt, $prompt_pw) = @_; | |||||||||||||||||||||||||||
| 62 | 0 | return; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 19 | ▶ | sub maybe_set_prompt_command_on { | ||||||||||||||||||||||||||
|
Subroutine
maybe_set_prompt_command_on: called CC=2 SCAR=10.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 19 | ▶ | return unless $prompt; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | my ($conn) = @_; | |||||||||||||||||||||||||||
| 68 | 0 | $conn->remote_sub('Object::Remote::Prompt::set_local_prompt_command') | |||||||||||||||||||||||||||
| 69 | ->($prompt, $prompt_pw); | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 11 | 1; | |||||||||||||||||||||||||||