DBBrowser/Credentials.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 49 CC 5 SCAR 27.7
CC
5
Cov
0%
get_login
30.0
new
2.0
BEGIN
2.0
CRAP 16.0
1 package # hide from PAUSE
2 App::DBBrowser::Credentials;
3  
4 use warnings;
5 use strict;
6 use 5.016;
7  
8 use Term::Form::ReadLine qw();
9  
10  
11 sub new {
12 my ( $class, $info, $options ) = @_;
13 my $sf = {
14 i => $info,
15 o => $options,
16 };
17 bless $sf, $class;
18 }
19  
20  
21 sub get_login {
22 my ( $sf, $key, $show_sofar ) = @_;
23 if ( ! $sf->{o}{connect_data}{"${key}_required"} ) {
24 return;
25 }
26 my $env_var = 'DBI_' . uc $key;
27 if ( length $sf->{o}{connect_data}{$key} ) {
28 return $sf->{o}{connect_data}{$key};
29 }
30 elsif ( $sf->{o}{connect_data}{"use_dbi_$key"} && exists $ENV{$env_var} ) {
31 return $ENV{$env_var}; #
32 }
33 else {
34 my $no_echo = $key =~ /^(?:host|port|user)\z/ ? 0 : 1;
35 my $prompt = ucfirst( $key ) . ': ';
36 my $tr = Term::Form::ReadLine->new( $sf->{i}{tr_default} );
37 # Readline
38 my $new = $tr->readline(
39 $prompt,
40 { info => $show_sofar, no_echo => $no_echo, history => [] }
41 );
42 return $new;
43 }
44 }
45  
46  
47  
48  
49 1;
50  
51  
52 __END__