Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > mod_perl, OO and Globals

Reply
Thread Tools

mod_perl, OO and Globals

 
 
M2
Guest
Posts: n/a
 
      10-08-2003
Hi,
I'm looking for a way to store some common objects (e.g. a database handle)
in such a way that it may be accessed from anywhere within an OO based
mod_perl application.

My first attempt used the UNIVERSAL package to stash it but that felt
clunky, not to mention risky. For my second attempt I made all objects
inherit from a single object which returned them from a global. Of course
this has the potential for some dire issues under mod_perl even though
they're reset on each execution.

Outside of this I cannot seem to find a way to get the data accessible
without passing it around all over the place which I would dearly like to
avoid.

Am I missing something?

Matt.


 
Reply With Quote
 
 
 
 
M2
Guest
Posts: n/a
 
      10-08-2003
Post having written this I am pondering about the use of class variables. If
you have a class variable in an object that is inherited by all objects
would you have only a single instance of that variable? Would mod_perl cause
any issue?

"M2" <> wrote in message
news:v7Ngb.76$_...
> Hi,
> I'm looking for a way to store some common objects (e.g. a database

handle)
> in such a way that it may be accessed from anywhere within an OO based
> mod_perl application.
>
> My first attempt used the UNIVERSAL package to stash it but that felt
> clunky, not to mention risky. For my second attempt I made all objects
> inherit from a single object which returned them from a global. Of course
> this has the potential for some dire issues under mod_perl even though
> they're reset on each execution.
>
> Outside of this I cannot seem to find a way to get the data accessible
> without passing it around all over the place which I would dearly like to
> avoid.
>
> Am I missing something?
>
> Matt.
>
>



 
Reply With Quote
 
 
 
 
James Willmore
Guest
Posts: n/a
 
      10-08-2003
"M2" <> wrote in message news:<v7Ngb.76$_>...
> Hi,
> I'm looking for a way to store some common objects (e.g. a database handle)
> in such a way that it may be accessed from anywhere within an OO based
> mod_perl application.
>
> My first attempt used the UNIVERSAL package to stash it but that felt
> clunky, not to mention risky. For my second attempt I made all objects
> inherit from a single object which returned them from a global. Of course
> this has the potential for some dire issues under mod_perl even though
> they're reset on each execution.
>
> Outside of this I cannot seem to find a way to get the data accessible
> without passing it around all over the place which I would dearly like to
> avoid.
>
> Am I missing something?


A couple of suggestions:

1) _Don't_ use UNIVERSAL unless you know what you're doing. It is my
understanding that it makes all objects available to all classes - and
that _may_ not be what you want to do. It can create inheirtance
issues, as well as overwriting methods and attributes. I could be
wrong about this, but (as of today) that's my understanding.

2) read the documentation on OO: perltoot, perlboot, perlbot.

3) As silly as this may sound, try mapping out what you want to do
first. During this exercise, you may find an easier, faster way to do
things. Redundancy can be eliminated and cleaner code could be
written - just by putting pencil to paper.

4) Get familiar with Data:umper. It's a great tool to see where
your values are and how they're being handled.

5) You could investigate some of the DBIx modules (yes, x at the end).
Some of them _may_ deal with what you want to do already.
Persistance with DBI is sometimes a pain. These modules may have
addressed this issue for you.

HTH

Jim
 
Reply With Quote
 
pkent
Guest
Posts: n/a
 
      10-08-2003
In article <v7Ngb.76$_>, "M2" <>
wrote:

> I'm looking for a way to store some common objects (e.g. a database handle)
> in such a way that it may be accessed from anywhere within an OO based
> mod_perl application.


Just keep the data in package globals, and it can persist as long as the
mod_perl child exists. It also doesn't matter that your application is
OO, or not, or only partly, if you were wondering.

Don't forget you can also tie hashes to DBMs, or serialize data
structures to disk if you want disk-backed caching.

P

--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
different sessions and globals =?Utf-8?B?YmJkb2J1ZGR5?= ASP .Net 2 08-15-2005 05:09 PM
what are PyObject *globals and PyObject *locals ? Olivier Sessink Python 0 02-24-2005 02:06 PM
On eval and its substitution of globals Paddy Python 6 02-24-2005 04:28 AM
static and globals Abhishek Pandey C++ 3 01-13-2005 02:35 PM
Python API, objects, globals, and forking. David M. Wilson Python 0 04-05-2004 03:11 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57