koha-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Koha-devel] Repetitious behavior repeatedly


From: paul POULAIN
Subject: Re: [Koha-devel] Repetitious behavior repeatedly
Date: Tue Oct 1 08:44:29 2002
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826

Andrew Arensburger wrote:
On Tue, Oct 01, 2002 at 01:32:49PM +0200, paul POULAIN wrote:
  

  
	I agree that this is a good idea, but I think the API could be
better.
	95+% of the time, a script needs to:
	1) Read the config file
	2) Open a connection to the database
	3) Read any locally-stored tables (stopwords, branches, etc.)
	4) Do whatever the script is supposed to do
	5) Close the connection to the database
I agree.
Steps 1-3 can be done in &C4::Context::import, so that the script only
needs to have

	use C4::Context;
	# ...Do useful stuff...

Step 5 can be done in an END{} block in C4::Context.

	In the vast majority of cases, the script will only have one
context (configuration, connection to database, theme, etc.), so from
the script-writer's perspective, it'd be nice not to have to worry
about those details.
	&C4::Context::import can create a new connection to the
database and store it in its own variable; then, when some other
function needs the database handle, it can use a class method (not an
object method) to fetch it:

	use C4::Context;
	...
	my $dbh = &C4::Context::db_handle();
	$dbh->prepare(...);
I'm OK, but i don't see well the diff between this and the OO method ? Why choose this and not the other ?

Each method would handle its own error handling, when appropriate.
Adding methods for 'param' and 'stopwords' would also be really easy.
Let me know if you need any help, if you decide to go this route.  I
now write most of my code in an object-oriented style, because I find
it much easier to keep track of where everything is.  Then you can
also inherit methods from other objects, and all sorts of fun stuff
(perhaps down the road a ways).
      
	I like a lot of things about OO, but I'm not fanatical about
it. The main thing it has going for it is encapsulation: it allows you
to hide unnecessary details from the programmer. Methods also give you
a fair amount of control over what happens (e.g., reconnecting to the
database if the connection was broken).
I'm very poor at Perl-OOP, so any help is greatly welcomed ;-)
    
	Take a look at part 2 of
http://www.ooblick.com/text/perl/
Wooh... Doc beginning by

package english
print "hello";
package french
print "Bonjour"

IS a GOOD doc ;-)

So : download > XGhostscript > Print > All...
--
Paul

reply via email to

[Prev in Thread] Current Thread [Next in Thread]