[Koha-devel] Repetitious behavior repeatedly

paul POULAIN paul.poulain at free.fr
Tue Oct 1 08:44:29 CEST 2002


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/koha-devel/attachments/20021001/58d78825/attachment-0002.htm>


More information about the Koha-devel mailing list