j.goor has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I want to create a 'Database' class which is a layer on top of Win32::OLE and also uses some other packages (see example).
Goal is to modify the behaviour of some methods, while all other Win32::OLE database-methods will be inherited and used as if Win32::OLE was called directory.
I don't exactly know how to do it.
I guess I lack knowledge of polymorphism/inheritance, bu do not have the time to learn that now. please help!
Thanx in advance
Rgds,
John

package Database; use 5.008; use strict; use warnings; use Win32::OLE::Variant; # For timestamp readings use Win32::ADO qw/CheckDBErrors/; # For ADO errorchecking use base 'Win32::OLE'; # Inherit from 'Win32::OLE' our $VERSION = '0.01'; # Local functions sub _dbconnect { # Create database connection my $conn = CreateObject Win32::OLE "ADODB.Connection" || die "Crea +teObject: $!"; $conn->Open("<some DSN to a MSSQL database>"); return $conn; } # Constructor sub new { my $class = shift; ( bless {}, $class )->_init( {@_} ); } sub _init($) { my ($self, $args) = @_; $self->{_dbh} = _dbconnect(); $self; } # This method should replace the Win32::OLE 'Execute' method and add e +rrorchecking to it. (doesn't work now!) sub Execute { my ($self, $sql) = shift; my $rs = $self->{_dbh}->Execute($sql); my @dberrors = (); CheckDBErrors($self->{_dbh}, \@dberrors) or croak "SQL Failed at ", + __LINE__, "\n", @dberrors; return ($rs); } 1;

Replies are listed 'Best First'.
Re: Help needed on OO module
by pelagic (Priest) on Jan 10, 2005 at 11:49 UTC
    If you happen to have just a little bit of time, read merlyn's perlboot as a good start.

    pelagic
      Just tried it, but not the desired result.
      E.g.: Do I have to return the Win32::OLE's connection handler back (from 'Database'), or do I have to put it somewhere into the 'Database' datastructure, thereby returning the 'Database' class handle?
      Somehow I just can't get it into place...
      Any suggestions that can help me right away...? (or very clear hints..?)
      I would *really* appreciate it!
      Grtz,
      John