Hi Anthony, good idea about overriding the table names. I had a feeling
there would be a conf file somewhere. As I am outputting the results of the
SELECT to an HTML::Template I am already using a Conf file which is another
class. This leads me on to another question. If I instantiate my class and
create a Conf object within $log->view then the Conf file won't be loaded
till this method is invoked. I want to have all the Conf details available
at the same time, I don't want to instantiate the Conf class several times
and hold several copies of the Conf in memory when only one is required. So
how or where should I instantiate it?
Cheers,
G :)
From: "Anthony Ettinger" <[EMAIL PROTECTED]>
To: "Graeme McLaren" <[EMAIL PROTECTED]>
CC: beginners@perl.org
Subject: Re: OO Perl question
Date: Thu, 8 Jun 2006 00:50:07 -0700
MIME-Version: 1.0
Received: from lists.develooper.com ([63.251.223.186]) by
bay0-mc4-f9.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.1830); Thu, 8
Jun 2006 00:50:55 -0700
Received: (qmail 30649 invoked by uid 514); 8 Jun 2006 07:50:32 -0000
Received: (qmail 30640 invoked from network); 8 Jun 2006 07:50:32 -0000
Received: from x1a.develooper.com (HELO x1.develooper.com) (216.52.237.111)
by lists.develooper.com with SMTP; 8 Jun 2006 07:50:32 -0000
Received: (qmail 22138 invoked by uid 225); 8 Jun 2006 07:50:32 -0000
Received: (qmail 22131 invoked by alias); 8 Jun 2006 07:50:31 -0000
Received: pass (x1.develooper.com: domain of [EMAIL PROTECTED] designates
64.233.184.235 as permitted sender)
Received: from wr-out-0506.google.com (HELO wr-out-0506.google.com)
(64.233.184.235) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Thu,
08 Jun 2006 00:50:15 -0700
Received: by wr-out-0506.google.com with SMTP id i24so350408wra for
<beginners@perl.org>; Thu, 08 Jun 2006 00:50:07 -0700 (PDT)
Received: by 10.85.2.9 with SMTP id e9mr1043594aui; Thu, 08 Jun 2006
00:50:07 -0700 (PDT)
Received: by 10.85.9.6 with HTTP; Thu, 8 Jun 2006 00:50:07 -0700 (PDT)
X-Message-Info: LsUYwwHHNt33w3Rs6VlmTi0/QtJPVei9e3LxwGYZQ3U=
Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
Precedence: bulk
List-Post: <mailto:beginners@perl.org>
List-Help: <mailto:[EMAIL PROTECTED]>
List-Unsubscribe: <mailto:[EMAIL PROTECTED]>
List-Subscribe: <mailto:[EMAIL PROTECTED]>
List-Id: <beginners.perl.org>
Delivered-To: mailing list beginners@perl.org
Delivered-To: beginners@perl.org
X-Spam-Status: No, hits=-2.6
required=8.0tests=BAYES_00,DK_SIGNED,DK_VERIFIED,SPF_PASS
X-Spam-Check-By: la.mx.develooper.com
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta;
d=gmail.com;
h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth;
b=MWpGrVpwc5GSsI/9QwtAXq29UU6v9M/50xwMNviV4k/doYyXT+zT5tJLPgmP6oAPZipEEyHZjjeRrTsRnULP2Vd1zGUb7fIG8mhvVu6fvZqgDb/TTWKjPbG/u61Z566xW5C4j1kzLrf2ghHEJs2IVm8kXf2bf5x/b/mGFixB+ZE=
References: <[EMAIL PROTECTED]>
X-Google-Sender-Auth: 13b1a86a963908ff
Return-Path: [EMAIL PROTECTED]
X-OriginalArrivalTime: 08 Jun 2006 07:50:55.0355 (UTC)
FILETIME=[45AEC4B0:01C68AD0]
On 6/8/06, Graeme McLaren <[EMAIL PROTECTED]> wrote:
Hi all, this class that I have written lists the contents of a "log" table
when the $log->view method is invoked. There is some hardcoded SQL in
this
method and all I do is pass it a number which then looks up the relevant
records. This really isn't a reusable class as far as I understand it
because it assumes that anyone else using it would have a log table with
various fields of a certain name defined. How can I make this completely
reuseable, should it be documented saying that you need to create a log
table with various fields before using it or should I code it so that the
table name and fields have to be passed in and the script would then take
care of it?
Your thoughts and comments are as always - appreciated.
Cheers,
G :)
Interesting. Reusable by who? Is it part of a package you're going to
distribute? is there an included mypkg.sql file they have to run?
Typically, package installs come with a config file where a user can
specify tablename_prefix. so it would be pretty seamless if all they
had to do was edit mypkg.conf and change:
table_prefix = mypkg_
so then "log_table" would become "mypkg_log_table", while columns
would remain the same.
You could have your module simply read the config file inside the
implementation of $log->view();
The table structure(s) should stay the same, but give them a chance to
override the table names incase they collide with pre-existing tables.
I've found this to be the best way to ensure not dropping tables on
accident, especially if you load an sql file with "drop table foo if
foo exists". I almost did that at work the other day on a table with 1
character diff in the name (i was lucky, and added dp_ to all my table
namespaces).
--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>