|
|
sybperl-l Archive
Up Prev Next
From: Jim Anderson <jander at ml dot com>
Subject: What am I doing wrong???
Date: Nov 7 1997 8:46PM
I've created a class that although it doesn't inherit from
Sybase::DBlib, it does a 'new Sybase::DBlib' during its
initialization.
Then, it has an AUTOLOAD sub that invokes (I wish :) a dblib
method. Unfortunately, this isn't working, and I get the msg:
Goto undefined subroutine &Sybase::DBlib::sql at ../lib/Map/Db.pm line 40.
Any help greatly appreciated!
Here's the code.
====================================================================
package Map::Db;
#-------------------------------------------------------------------------------------------
$VERSION = __PACKAGE__ . ": " . (split(/[<>]/,'Time-stamp: <97/11/07 15:02:13 jander>'))[1];
#-------------------------------------------------------------------------------------------
use strict;
use Carp;
use Sybase::DBlib;
use IO::File;
use Dblogin;
use vars qw ( $VERSION $AUTOLOAD );
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
%$self = @_;
my $tag = $self->{tag};
die "'tag' param required" unless $tag;
unless ($self->{$tag}) {
# this reads a file of server/login/password info
$self->{dblogins} ||= new Dblogin;
# this line opens sybase connection, getting the dbproc
$self->{$tag} = $self->{dblogins}->login($tag);
}
bless $self, $class;
}
sub AUTOLOAD {
my $self = shift;
ref($self) || croak "$self is not an object";
my $tag = $self->{tag};
unshift @_, $self->{$tag}; # dbproc
my $name = $AUTOLOAD;
$name =~ s/^.*:/Sybase::DBlib::/; # qualify to point to DBlib
# this fails :-(
goto &$name;
}
1;
====================================================================
and the invocation:
====================================================================
#!/home/jander/bin/perl -w
#-------------------------------------------------------------------------
my $VERSION = (split(/[<>]/,'Time-stamp: <97/11/07 15:11:47 jander>'))[1];
#-------------------------------------------------------------------------
#
# test2.pl
#
# test misc map table classes
require 5.004;
use strict;
use lib qw ( ../lib );
use Map::Db;
my $obj = new Map::Db ( tag => 'csers.mlcs');
$obj->sql("sp_help", sub { print join(', ', @_), "\n"});
$obj->dbclose;
====================================================================
--
Jim Anderson jander@ml.com
Consultant-at-large jander@jander.com
(212) 449-1598
|