|
|
sybperl-l Archive
Up Prev Next
From: Jim Anderson <jander at ml dot com>
Subject: Re: What am I doing wrong???
Date: Nov 8 1997 6:24PM
OK, so I'll try installing 2.08_51. But I looked on CPAN and only
spotted 2.08. Is that 2.08_51? If not, could you let me know where I
can grab it?
Thanks very much!
jim
Michael Peppler sagely stated:
> 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
>
--
Jim Anderson jander@ml.com
Consultant-at-large jander@jander.com
(212) 449-1598
|