File Coverage

blib/lib/DBIx/OracleLogin.pm
Criterion Covered Total %
statement 21 41 51.2
branch 7 22 31.8
condition 1 3 33.3
subroutine 4 4 100.0
pod 0 1 0.0
total 33 71 46.4


line stmt bran cond sub pod time code
1             package DBIx::OracleLogin;
2              
3 1     1   8780 use strict;
  1         4  
  1         46  
4 1     1   1241 use Term::ReadKey;
  1         11169  
  1         149  
5              
6 1     1   13 use vars qw($VERSION @ISA @EXPORT);
  1         7  
  1         594  
7             require Exporter;
8             @ISA = ('Exporter');
9             @EXPORT = qw( &parse );
10              
11             $VERSION = '0.02';
12              
13             sub parse {
14 1     1 0 64 my ($text) = @_;
15              
16 1         3 my $user;
17             my $pass;
18 0         0 my $sid;
19            
20             # Return if there are more special characters than expected
21 1 50 33     27 return undef if ( $text =~ /.*\/.*\// or $text =~ /.*\@.*\@/);
22              
23 1 50       12 if ( $text =~ /^([^\/]+)\/([^\@]+)\@(.+)$/ ) { # form UID/PW@SID
    50          
    0          
    0          
    0          
24 0         0 $user = $1;
25 0         0 $pass = $2;
26 0         0 $sid = $3;
27             }
28              
29             elsif ( $text =~ /^([^\@]+)\@([^\/]+)\/(.+)$/ ) { # form UID@SID/PW
30 1         5 $user = $1;
31 1         3 $sid = $2;
32 1         3 $pass = $3;
33             }
34              
35             elsif ( $text =~ /^([^\@]+)\@([^.]+)$/ ) { # form UID@SID
36 0         0 $user = $1;
37 0         0 $sid = $2;
38             }
39              
40             elsif ( $text =~ /^([^\@]+)\/([^.]+)$/ ) { # form UID/PW
41 0         0 $user = $1;
42 0         0 $pass = $2;
43             }
44              
45             elsif ( $text =~ /^([^\@\/]+)$/ ) { # form UID
46 0         0 $user = $1;
47             }
48              
49             else {
50 0         0 undef $user;
51 0         0 undef $sid;
52 0         0 undef $pass;
53             }
54              
55              
56             # return if there is no $user by now...
57 1 50       4 return undef if ( !$user);
58              
59             # Prompt for password if necessary
60 1 50       9 if ( !$pass ) {
61 0         0 print STDERR "password: ";
62 0         0 ReadMode('noecho');
63 0         0 $pass = ReadLine(0);
64 0         0 chomp $pass;
65 0         0 print "\n";
66             }
67              
68             # return if there is no $pass by now...
69 1 50       5 return undef if (! $pass);
70              
71             # retrieve default sid if none has been provided
72 1 0       3 if (!$sid) { if (!$ENV{ORACLE_SID}) {return undef;} else {$sid = $ENV{ORACLE_SID};}
  0 50       0  
  0         0  
  0         0  
73             }
74              
75 1         6 return ( $user, $pass, $sid );
76             }
77              
78              
79             1;
80             __END__