home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / OracleLogin.pm < prev    next >
Encoding:
Perl POD Document  |  2002-07-30  |  3.5 KB  |  128 lines

  1. package DBIx::OracleLogin;
  2.  
  3. use strict;
  4. use Term::ReadKey;
  5.  
  6. use vars qw($VERSION @ISA @EXPORT);
  7. require Exporter;
  8. @ISA    = ('Exporter');
  9. @EXPORT = qw( &parse );
  10.  
  11. $VERSION = '0.02';
  12.  
  13. sub parse {
  14.     my ($text) = @_;
  15.  
  16.     my $user;
  17.     my $pass;
  18.     my $sid;
  19.  
  20.     # Return if there are more special characters than expected
  21.     return undef if ( $text =~ /.*\/.*\// or $text =~ /.*\@.*\@/);
  22.  
  23.     if ( $text =~ /^([^\/]+)\/([^\@]+)\@(.+)$/ ) {    # form UID/PW@SID
  24.         $user = $1;
  25.         $pass = $2;
  26.         $sid  = $3;
  27.     }
  28.  
  29.     elsif ( $text =~ /^([^\@]+)\@([^\/]+)\/(.+)$/ ) {    # form UID@SID/PW
  30.         $user = $1;
  31.         $sid  = $2;
  32.         $pass = $3;
  33.     }
  34.  
  35.     elsif ( $text =~ /^([^\@]+)\@([^.]+)$/ ) {           # form UID@SID
  36.         $user = $1;
  37.         $sid  = $2;
  38.     }
  39.  
  40.     elsif ( $text =~ /^([^\@]+)\/([^.]+)$/ ) {           # form UID/PW
  41.         $user = $1;
  42.         $pass  = $2;
  43.     }
  44.  
  45.     elsif ( $text =~ /^([^\@\/]+)$/ ) {           # form UID
  46.         $user = $1;
  47.     }
  48.  
  49.     else {
  50.         undef $user;
  51.         undef $sid;
  52.         undef $pass;
  53.     }
  54.  
  55.  
  56.     # return if there is no $user by now...
  57.     return undef if ( !$user);
  58.  
  59.     # Prompt for password if necessary
  60.      if ( !$pass ) {
  61.             print STDERR "password: ";
  62.             ReadMode('noecho');
  63.             $pass = ReadLine(0);
  64.             chomp $pass;
  65.             print "\n";
  66.      }
  67.  
  68.     # return if there is no $pass by now...
  69.     return undef if (! $pass);
  70.  
  71.     # retrieve default sid if none has been provided
  72.     if (!$sid) { if (!$ENV{ORACLE_SID}) {return undef;} else {$sid = $ENV{ORACLE_SID};}
  73.     }
  74.  
  75.     return ( $user, $pass, $sid );
  76. }
  77.  
  78.  
  79. 1;
  80. __END__
  81.  
  82.  
  83. =head1 NAME
  84.  
  85. DBIx::OracleLogin - takes a string and splits out individual login information (user id, Oracle sid, and password) to be used in a DBI->connect() statement when connecting to an Oracle database. 
  86.  
  87. =head1 SYNOPSIS
  88.  
  89.   use DBIx::OracleLogin;
  90.   my ( $user, $pass, $sid ) = DBIx::OracleLogin::parse($text);
  91.  
  92. $text should be of the standard form used by Oracle applications such as sqlplus: userid@oracle_sid/password or userid/password@oracle_sid or userid@oracle_sid or userid/password or user.
  93.  
  94. A password does not need to be provided in the $text argument. If no password is provided then the program prompts for a password.
  95.  
  96. A oracle_sid does not need to be provided in the $text argument. If no oracle_sid is provided then the program attempts to retrieve a default from $ENV{ORACLE_SID} environment variable.
  97.  
  98. If the $text format is invalid the program will return null values for $user, $sid and $pass.
  99.  
  100. =head1 DESCRIPTION
  101.  
  102. This module is useful to avoid hard-coding of Oracle database login information in a Perl program. 
  103.  
  104. The $text argument provided to the method parse() should be of one of 
  105. these forms: userid@oracle_sid/password or userid/password@oracle_sid or
  106. userid@oracle_sid or userid/password or userid. 
  107.  
  108. A password does not need to be provided in the $text argument. If no password is provided then the program prompts for a password without echoing to stdout.
  109.  
  110. A oracle_sid does not need to be provided in the $text argument. If no oracle_sid is provided then the program attempts to retrieve a default from $ENV{ORACLE_SID} environment variable.
  111.  
  112. If the $text format is invalid the program will return null values for $user, $sid and $pass.
  113.  
  114. =head1 REQUIRES
  115.  
  116. Term::ReadKey
  117.  
  118. =head1 AUTHOR
  119.  
  120. Diane Benz E<lt>diane@ccgb.umn.eduE<gt>
  121.  
  122. =head1 SEE ALSO
  123.  
  124. DBD, DBD::Oracle
  125.  
  126. =cut
  127.  
  128.