From list at mindling.com Mon May 6 18:48:13 2002 From: list at mindling.com (Seb) Date: Thu Aug 5 00:21:17 2004 Subject: Subclassing Curiosity Message-ID: <20020506164802.147D.LIST@mindling.com> I have a curiosity with regard to subclassing DBI. I'm just not sure I get the principles involved. I've got a module that is a DBI subclass. In order to subclass DBI as "package Mine", one must also provide packages Mine::db and Mine::st, because the database and statement handles used in DBI are their own classes. My confusion comes in when I put a constructor in my main package, and try to use DBI methods on its returned object. (DBI has no constructor method with which to reference a DBI object, per se) So I have something like this: #!/usr/bin/perl package MyDBI; use DBI; @ISA = qw(DBI); sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; } package MyDBI::db; @ISA = qw(DBI::db); package MyDBI::st; @ISA = qw(DBI::st); # now our main program package main; my $obj = new MyDBI; # $obj is a MyDBI object, with DBI base methods print '$obj is a: '.(scalar ref $obj)."\n"; my $dbh = $obj->connect('DBI:Pg:dbname=somedb', undef, undef); # This generates a warning # $dbh is a DBI::db object, NOT a MyDBI::db object print '$dbh is a: '.(scalar ref $dbh)."\n"; # On the other hand, if I use the module name, not my object... my $dbh2 = MyDBI->connect('DBI:Pg:dbname=somedb', undef, undef); # No error, and $dbh2 is a proper MyDBI::db object print '$dbh2 is a: '.(scalar ref $dbh2)."\n"; __END__ The output of the above code looks like this: $obj is a: MyDBI DBI subclass 'MyDBI=HASH(0x813c1a0)::db' isn't setup, ignored at MyDBI.pl line 26 $dbh is a: DBI::db $dbh2 is a: MyDBI::db Why does the first case ($obj->connect) not do what I expect it to, while the second case (MyDBI->connect) works fine? Is this just some basic scoping or inheritance thing that I'm not understanding? TIA Sebastian From kevin at oreilly.com Tue May 7 17:13:48 2002 From: kevin at oreilly.com (Kevin Bingham) Date: Thu Aug 5 00:21:17 2004 Subject: Subclassing Curiosity In-Reply-To: <20020506164802.147D.LIST@mindling.com> Message-ID: <5.1.0.14.0.20020507151019.00a8c0c8@pop3.west.ora.com> Hey Sebastian! Sorry, I don't know the answer to this particular one, though somebody kicking around might. Though considering our meager mailing list, who knows when you'll get a response. I suggest posting your question to Perl Monks, http://www.perlmonks.org/, which is highly touted by our very own Tom Anderson (http://tomacorp.com/, We're not a corporation). On Perl Monks you should get an answer right quick. Kudos! -Kevin At 04:48 PM 5/6/2002 -0700, Seb wrote: >I have a curiosity with regard to subclassing DBI. I'm just not sure I >get the principles involved. I've got a module that is a DBI subclass. >In order to subclass DBI as "package Mine", one must also provide >packages Mine::db and Mine::st, because the database and statement >handles used in DBI are their own classes. > >My confusion comes in when I put a constructor in my main package, and >try to use DBI methods on its returned object. (DBI has no constructor >method with which to reference a DBI object, per se) > >So I have something like this: > >#!/usr/bin/perl >package MyDBI; >use DBI; >@ISA = qw(DBI); > >sub new { > my $class = shift; > my $self = {}; > bless $self, $class; > return $self; >} > >package MyDBI::db; >@ISA = qw(DBI::db); > >package MyDBI::st; >@ISA = qw(DBI::st); > ># now our main program > >package main; > >my $obj = new MyDBI; > ># $obj is a MyDBI object, with DBI base methods >print '$obj is a: '.(scalar ref $obj)."\n"; > >my $dbh = $obj->connect('DBI:Pg:dbname=somedb', undef, undef); > ># This generates a warning ># $dbh is a DBI::db object, NOT a MyDBI::db object >print '$dbh is a: '.(scalar ref $dbh)."\n"; > ># On the other hand, if I use the module name, not my object... > >my $dbh2 = MyDBI->connect('DBI:Pg:dbname=somedb', undef, undef); > ># No error, and $dbh2 is a proper MyDBI::db object >print '$dbh2 is a: '.(scalar ref $dbh2)."\n"; > >__END__ > >The output of the above code looks like this: >$obj is a: MyDBI >DBI subclass 'MyDBI=HASH(0x813c1a0)::db' isn't setup, ignored at MyDBI.pl >line 26 >$dbh is a: DBI::db >$dbh2 is a: MyDBI::db > > >Why does the first case ($obj->connect) not do what I expect it to, >while the second case (MyDBI->connect) works fine? > >Is this just some basic scoping or inheritance thing that I'm not >understanding? > >TIA >Sebastian From schuyler at tridity.org Tue May 7 17:40:50 2002 From: schuyler at tridity.org (Schuyler D. Erle) Date: Thu Aug 5 00:21:17 2004 Subject: Subclassing Curiosity In-Reply-To: <5.1.0.14.0.20020507151019.00a8c0c8@pop3.west.ora.com> References: <20020506164802.147D.LIST@mindling.com> <5.1.0.14.0.20020507151019.00a8c0c8@pop3.west.ora.com> Message-ID: <20020507154050.134e1136.schuyler@tridity.org> I hate to say this, but, speaking from experience, subclassing DBI is *very* difficult to get right. I managed to get the inheritance straightened out, but then for reasons not clear to me, the driver I hacked up dumped core when I tried writing to the database. I'd have debugged it but I don't have the time ATM. The short answer is, and I'm sure you're not going to like this, avoid subclassing DBI if there's another practical solution to your problem. The DBI is really complicated, and IMHO it's not worth the headache. If you're trying to solve a problem that you really feel can't be solved without subclassing DBI, I recommend describing it in greater detail to the list to see what we come up with... SDE On Tue, 07 May 2002 15:13:48 -0700, "Kevin Bingham" wrote: > Hey Sebastian! > > Sorry, I don't know the answer to this particular one, though somebody > kicking around might. Though considering our meager mailing list, who knows > when you'll get a response. I suggest posting your question to Perl Monks, > http://www.perlmonks.org/, which is highly touted by our very own Tom > Anderson (http://tomacorp.com/, We're not a corporation). On Perl Monks you > should get an answer right quick. > > Kudos! > -Kevin > > At 04:48 PM 5/6/2002 -0700, Seb wrote: > >I have a curiosity with regard to subclassing DBI. I'm just not sure I > >get the principles involved. I've got a module that is a DBI subclass. > >In order to subclass DBI as "package Mine", one must also provide > >packages Mine::db and Mine::st, because the database and statement > >handles used in DBI are their own classes. > > > >My confusion comes in when I put a constructor in my main package, and > >try to use DBI methods on its returned object. (DBI has no constructor > >method with which to reference a DBI object, per se) > > > >So I have something like this: > > > >#!/usr/bin/perl > >package MyDBI; > >use DBI; > >@ISA = qw(DBI); > > > >sub new { > > my $class = shift; > > my $self = {}; > > bless $self, $class; > > return $self; > >} > > > >package MyDBI::db; > >@ISA = qw(DBI::db); > > > >package MyDBI::st; > >@ISA = qw(DBI::st); > > > ># now our main program > > > >package main; > > > >my $obj = new MyDBI; > > > ># $obj is a MyDBI object, with DBI base methods > >print '$obj is a: '.(scalar ref $obj)."\n"; > > > >my $dbh = $obj->connect('DBI:Pg:dbname=somedb', undef, undef); > > > ># This generates a warning > ># $dbh is a DBI::db object, NOT a MyDBI::db object > >print '$dbh is a: '.(scalar ref $dbh)."\n"; > > > ># On the other hand, if I use the module name, not my object... > > > >my $dbh2 = MyDBI->connect('DBI:Pg:dbname=somedb', undef, undef); > > > ># No error, and $dbh2 is a proper MyDBI::db object > >print '$dbh2 is a: '.(scalar ref $dbh2)."\n"; > > > >__END__ > > > >The output of the above code looks like this: > >$obj is a: MyDBI > >DBI subclass 'MyDBI=HASH(0x813c1a0)::db' isn't setup, ignored at MyDBI.pl > >line 26 > >$dbh is a: DBI::db > >$dbh2 is a: MyDBI::db > > > > > >Why does the first case ($obj->connect) not do what I expect it to, > >while the second case (MyDBI->connect) works fine? > > > >Is this just some basic scoping or inheritance thing that I'm not > >understanding? > > > >TIA > >Sebastian From kevin at oreilly.com Wed May 29 13:03:50 2002 From: kevin at oreilly.com (Kevin Bingham) Date: Thu Aug 5 00:21:17 2004 Subject: Perl Mongers Meeting Thursday the 30th Message-ID: <5.1.0.14.0.20020529110224.01f17ff8@pop3.west.ora.com> Hola Fellow Perl Mongers! The last Thursday of the month is just a few days away, and that means it's Perl time! When: Thursday, May 30, 7:30 to 9:00pm. 6:45pm for those of you interested in ordering pizza. Where: O'Reilly & Associates 1005 Gravenstein Hwy North Sebastopol, CA 95472 What? Perl of course! Directions: http://www.oreilly.com/oreilly/seb_directions.html http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=1005+Gravenstein+Hwy+N&city=Sebastopol&state=CA&zip=95472-2814&country=us Your Perl Monger Host, -Kevin kevin@oreilly.com From list at mindling.com Wed May 29 13:38:03 2002 From: list at mindling.com (Seb) Date: Thu Aug 5 00:21:17 2004 Subject: Perl Mongers Meeting Thursday the 30th In-Reply-To: <5.1.0.14.0.20020529110224.01f17ff8@pop3.west.ora.com> References: <5.1.0.14.0.20020529110224.01f17ff8@pop3.west.ora.com> Message-ID: <1022697484.2741.12.camel@localhost.localdomain> On Wed, 2002-05-29 at 11:03, Kevin Bingham wrote: > Hola Fellow Perl Mongers! > > The last Thursday of the month is just a few days away, and that means it's > Perl time! > > When: Thursday, May 30, 7:30 to 9:00pm. 6:45pm for those of you interested > in ordering pizza. Hi all. I know I was one of the "Thursday's are great!" votes last year, but I'm unfortunately committed most Thursday nights these days. I wonder if anyone else is having trouble making the Thursday meetings, or would prefer a different day? If I'm the lone voice, I'll happily suck up and deal...and do my best to make what meetings I can, but if anyone else would like to 'second' a day change vote for future meetings, I'm all ears :) The best evenings for me in order of preference are: Tuesday, Monday, Wednesday, and Sunday. Cheers -Sebastian From eric at eisenhart.com Wed May 29 14:24:14 2002 From: eric at eisenhart.com (Eric Eisenhart) Date: Thu Aug 5 00:21:17 2004 Subject: Perl Mongers Meeting Thursday the 30th In-Reply-To: <1022697484.2741.12.camel@localhost.localdomain> References: <5.1.0.14.0.20020529110224.01f17ff8@pop3.west.ora.com> <1022697484.2741.12.camel@localhost.localdomain> Message-ID: <20020529192414.GZ13816@atlantic3.devin.com> On Wed, May 29, 2002 at 11:38:03AM -0700, Seb wrote: > Hi all. I know I was one of the "Thursday's are great!" votes last year, > but I'm unfortunately committed most Thursday nights these days. I > wonder if anyone else is having trouble making the Thursday meetings, or > would prefer a different day? If I'm the lone voice, I'll happily suck > up and deal...and do my best to make what meetings I can, but if anyone > else would like to 'second' a day change vote for future meetings, I'm > all ears :) I'll second the motion; I've been busy almost everything Thursday night since 1996. (which is a big part of why I'm never at Perl Monger's meetings despite otherwise being interested) > The best evenings for me in order of preference are: Tuesday, Monday, > Wednesday, and Sunday. Sunday's frequently a bad day for me and likely a bad day for a lot of folks. If you are going to reschedule, make sure to look at stuff like http://www.linuxmafia.com/bale/ to try and avoid conflicting with the schedule of anything vaguely nearby that somebody might want to go to that would also be interested in a Perl meeting. (looking there it looks like most Mondays and some Wednesdays are unpopular) I'd suggest the order of preference be Wednesday, Monday, Tuesday, Thursday if a move away from thursdays was being considered beyond, well, Seb and myself... 2nd wednesdays are pretty popular, but the third wednesday and last wednesday of each month are both thoroughly unpopular (and therefore good choices a user group). (for those that don't know, I'm a general malcontent, one of the main NBLUG people and one of the comp.lang.perl.moderated moderators.) -- Eric Eisenhart eric-dot-sig@eisenhart.com Perl, SQL, Linux and Web ^ IRC: Freiheit@openprojects Coder, Sysadmin and geek /e\ AIM: falsch freiheit http://eric.eisenhart.com/ --- ICQ: 48217244 From kevin at oreilly.com Wed May 29 16:41:06 2002 From: kevin at oreilly.com (Kevin Bingham) Date: Thu Aug 5 00:21:17 2004 Subject: Perl Mongers Meeting Thursday the 30th In-Reply-To: <20020529192414.GZ13816@atlantic3.devin.com> References: <1022697484.2741.12.camel@localhost.localdomain> <5.1.0.14.0.20020529110224.01f17ff8@pop3.west.ora.com> <1022697484.2741.12.camel@localhost.localdomain> Message-ID: <5.1.0.14.0.20020529142859.01f86cd8@pop3.west.ora.com> Ahh, I wondered why I hadn't seen you at the meetings, Sebastian. I have no qualms on moving the date of the meeting. I too have something else I could be doing on Thursday nights, but I've been giving PM priority. An now that my Wednesday night class is over, I'm available then. It sounds like 3rd or last Wednesday of every month might work. What do you think? I will also ask the attendees on Thursday night, since I know a few of them are not on the list and just show up. Kudos! -Kevin At 12:24 PM 5/29/2002 -0700, Eric Eisenhart wrote: >On Wed, May 29, 2002 at 11:38:03AM -0700, Seb wrote: > > Hi all. I know I was one of the "Thursday's are great!" votes last year, > > but I'm unfortunately committed most Thursday nights these days. I > > wonder if anyone else is having trouble making the Thursday meetings, or > > would prefer a different day? If I'm the lone voice, I'll happily suck > > up and deal...and do my best to make what meetings I can, but if anyone > > else would like to 'second' a day change vote for future meetings, I'm > > all ears :) > >I'll second the motion; I've been busy almost everything Thursday night >since 1996. (which is a big part of why I'm never at Perl Monger's meetings >despite otherwise being interested) > > > The best evenings for me in order of preference are: Tuesday, Monday, > > Wednesday, and Sunday. > >Sunday's frequently a bad day for me and likely a bad day for a lot of >folks. > >If you are going to reschedule, make sure to look at stuff like >http://www.linuxmafia.com/bale/ to try and avoid conflicting with the >schedule of anything vaguely nearby that somebody might want to go to that >would also be interested in a Perl meeting. (looking there it looks like >most Mondays and some Wednesdays are unpopular) > >I'd suggest the order of preference be Wednesday, Monday, Tuesday, Thursday >if a move away from thursdays was being considered beyond, well, Seb and >myself... 2nd wednesdays are pretty popular, but the third wednesday and >last wednesday of each month are both thoroughly unpopular (and therefore >good choices a user group). > >(for those that don't know, I'm a general malcontent, one of the main NBLUG >people and one of the comp.lang.perl.moderated moderators.) >-- >Eric Eisenhart eric-dot-sig@eisenhart.com >Perl, SQL, Linux and Web ^ IRC: Freiheit@openprojects >Coder, Sysadmin and geek /e\ AIM: falsch freiheit >http://eric.eisenhart.com/ --- ICQ: 48217244