PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: What am I doing wrong???
Date: Nov 7 1997 10:30PM

Michael Peppler wrote:
> 
> Jim Anderson wrote:
> >
> > 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!
> 
> I've never played with the AutoLoader like that, but the problem
> could be that sql() itself is autoloaded (at least up to 2.07).

I think that may be the problem - I was curious so I tried the 
following with 2.08_51 and it worked:

package Auto;

use strict;
use Carp;
use Sybase::DBlib;
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->{dbh} ||= new Sybase::DBlib 'sa';

    # this line opens sybase connection, getting the dbproc
    $self->{$tag} = $self->{dbh};
  }

  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 :-(   !!!NOT!!! :-)
  goto &$name;
}

1;


# auto.pl:
require 5.004;

use strict;
use lib qw ( . );
use Auto;

my $obj = new Auto ( tag => 'csers.mlcs');
$obj->sql("sp_help", sub { print join(', ', @_), "\n"});
$obj->dbclose;



Michael
-- 
Michael Peppler       -||-  Data Migrations Inc.
mpeppler@datamig.com  -||-  http://www.mbay.net/~mpeppler