It's not that hard.  I subclassed it for the purpose of allowing
logical database names that we map to the real DBI resource 
strings.  Among other things, that gives us one place to change
where a given database/schema really is.  I'm attaching that 
code so you can see what you have to do to subclass DBI.

As for the $class = ref($invocant) || $invocant code, it is 
something thrown out there for use in some, but not all, class
methods.  Perl isn't strict OO of course, so it's all pretty 
loose in these areas ...  The distinction I use is this:  If it
makes sense to allow an existing object to invoke a class method
(e.g., creating a new object from an existing one), then I allow 
it.  If not, then I don't use it.

"Programming Perl" refers to such methods as "dual-nature" methods
(instance or class).  That kind of stuff keeps the OO purists 
awake at night, but I sleep easy despite my OO background.  8-)

 <<Connection.pm>> 
----
Steve Sapovits
Global Sports Interactive
Work Email: [EMAIL PROTECTED]
Home Email: [EMAIL PROTECTED]
Work Phone: 610-491-7087
Cell:       610-574-7706
Pager:      877-239-4003

> -----Original Message-----
> From: Paul D. Smith [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, April 20, 2001 11:56 AM
> To:   [EMAIL PROTECTED]
> Subject:      Re: ISA inheritance vs. DBI?
> 
> %% "M.W. Koskamp" <[EMAIL PROTECTED]> writes:
> 
>   mwk> sub connect{
>   mwk>     my $class = shift;
>   mwk>     my $class = ref($class) || $class;
>   mwk>     return bless $class->SUPER::connect(@_), $class;
>   mwk> }
> 
> I don't see how either of these are any different from what I said I
> already tried in my original message:
> 
>   sub connect {
> 
>     #... figure connect info $data_source, $username, $password
> 
>     my $this = $class->SUPER::connect($data_source, $username, $password);
> 
>     return bless($this, $class);
>   }
> 
> ?
> 
> %% Stephen Clouse <[EMAIL PROTECTED]> writes:
> 
>   sc> On Thu, Apr 19, 2001 at 05:42:43PM -0400, Paul D. Smith wrote:
> 
>   >> I'm trying to create a subclass of the DBI class.
> 
>   sc> Look at t/subclass.t in the DBI distribution for an example.
>   sc> Subclassing DBI isn't as simple as setting @ISA -- but it isn't
>   sc> terribly hard either.
> 
> Hmm.  I'll check it out to see if it's worthwhile.
> 
> I really feel that my need _is_ for subclassing, not a "use" situation:
> I want to override the connect method and I want to add my own methods
> that "feel" like normal DBI methods.
> 
> However, this may be too complicated.  The new methods I have are in
> some ways just intermediate steps in moving to a completely DBI solution
> (except I'll probably keep my own connect function); I thought it would
> be easy to subclass DBI and get it all "for free" but if it's not
> trivial then maybe I'll just leave them as functions, as they'll be
> removed at some point anyway.
> 
> Thx.
> 
> -- 
> --------------------------------------------------------------------------
> -----
>  Paul D. Smith <[EMAIL PROTECTED]>    HASMAT--HA Software Methods &
> Tools
>  "Please remain calm...I may be mad, but I am a professional." --Mad
> Scientist
> --------------------------------------------------------------------------
> -----
>    These are my opinions---Nortel Networks takes no responsibility for
> them.

Connection.pm

Reply via email to