mod_perl, OO and Globals

Discussion in 'Perl Misc' started by M2, Oct 8, 2003.

  1. M2

    M2 Guest

    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.
     
    M2, Oct 8, 2003
    #1
    1. Advertising

  2. M2

    M2 Guest

    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.
    >
    >
     
    M2, Oct 8, 2003
    #2
    1. Advertising

  3. "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::Dumper. 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
     
    James Willmore, Oct 8, 2003
    #3
  4. M2

    pkent Guest

    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
     
    pkent, Oct 9, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sf-newsgroup
    Replies:
    1
    Views:
    1,726
    David Solimano
    Feb 12, 2012
  2. Jeff Boes

    mod_perl and 5.8.1

    Jeff Boes, Oct 15, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    76
    Rafael Garcia-Suarez
    Oct 15, 2003
  3. Pablo S
    Replies:
    1
    Views:
    316
    Tore Aursand
    Sep 1, 2004
  4. Andrew S
    Replies:
    1
    Views:
    137
    Brian McCauley
    Apr 6, 2005
  5. Replies:
    2
    Views:
    469
    Big and Blue
    Jan 25, 2006
Loading...

Share This Page