1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
package DBIShell::Fixup;
# dbishell: A generic database shell based on the Perl DBI layer
# Copyright (C) 2000 Vivek Dasmohapatra (vivek@etla.org)
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
use strict;
use Exporter ();
use Getopt::Long;
use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS @ISA);
$VERSION = 0.01_02;
@EXPORT = qw();
@EXPORT_OK = qw();
%EXPORT_TAGS = qw();
@ISA = qw(Exporter);
use constant FIXLIST =>
{
'Term::ReadLine::Perl' => *term_readline_perl ,
'Getopt::Long' => *getopt_long ,
};
# user-visible function:
sub patch ($)
{
my $patch;
my $target = $_[0];
if( $patch = (FIXLIST)->{$target} ) { $patch->() }
}
# FIXUP: Getopt::Long
# fixup for old versions (cf solaris 2.5/2.6 or so, iirc):
use constant GETOPT_WARNING =>
"Old version of Getopt::Long [%d] detected: trying to kludge it...\n";
sub getopt_long ()
{
if($::{'Getopt::'} && $::{'Getopt::'}{'Long::'})
{
my $sym_tab = $::{'Getopt::'}{'Long::'};
if(!exists($sym_tab->{Configure}))
{
warn(sprintf(GETOPT_WARNING, $Getopt::Long::VERSION));
if(exists($sym_tab->{config}))
{
$sym_tab->{Configure} = *{ $sym_tab->{config} };
}
}
}
}
# FIXUP: Term::ReadLine::Perl
# fix package so it meets the TIEHASH criteria: this is so we can access
# its attributes in a Term::ReadLine::Gnu compatible way:
package Term::ReadLine::Perl::Tie;
use vars qw(*DBISHELL_GLOB);
package DBIShell::Fixup;
TRL_PERL_PRIVATE:
{
my @rlh_keys = ();
sub _trl_perl_tie_firstkey
{
package Term::ReadLine::Perl::Tie;
my $symt;
if( $symt = $::{'readline::'} )
{
my $key0;
(@rlh_keys) = map { s/^rl_//; $_} grep { /^rl_/ } keys( %{$symt} );
if( @rlh_keys && ($key0 = $rlh_keys[0]) )
{
local(*DBISHELL_GLOB) = $symt->{ join('_', 'rl_', $key0) };
return wantarray ? ($key0, $DBISHELL_GLOB) : $key0;
}
}
return ();
}
sub _trl_perl_tie_nextkey
{
package Term::ReadLine::Perl::Tie;
my $symt;
my $self = shift(@_);
my $last = shift(@_);
if( $symt = $::{'readline::'} )
{
my $seen = 0;
foreach (@rlh_keys)
{
if( !$seen ){ $seen = ($_ eq $last); next }
local(*DBISHELL_GLOB) = $symt->{ join('_', 'rl_', $_) };
return wantarray ? ($_, $DBISHELL_GLOB) : $_;
}
}
return ();
}
1;
};
sub _trl_perl_minline ($;$)
{
my $rv = $readline::minlength;
if(@_ == 2) { $readline::minlength = $_[1] }
return $rv;
}
sub term_readline_perl ()
{
my $st;
if( $st =
$::{'Term::'} &&
$::{'Term::'}{'ReadLine::'} &&
$::{'Term::'}{'ReadLine::'}{'Perl::'} )
{
$st->{MinLine} = *_trl_perl_minline;
}
if( $st = $st && $st->{'Tie::'} )
{
$st->{FIRSTKEY} ||= *_trl_perl_tie_firstkey;
$st->{NEXTKEY} ||= *_trl_perl_tie_nextkey;
}
}
__END__
|