Hey guys,

in addition to my previous question, I'm still unsure on what's the best
possible way to achieve the following:

I have a class which has to initialize itself with data from a database.
It connects to the database in the constructor, fetches some data from
the database and stores it in $self, like so:

package My::Structure;

use My::Database;

sub new {
  my $class = shift;
  my $self = bless {}, $class;
  $self->_init();
  return $self;
}

sub _init {
  my $self = shift;

  # the following connects via DBI->connect()
  # stores the handle in its $self hash and 
  # returns it via a method called dbh()
  $self->{_dbh} = My::Database->new()->dbh(); 

  # now make use of $self->{_dbh}, fetch some stuff from the db
  # and store it in $self for later retrieval ...
}

Furthermore I'd like to make My::Structure globally available to mason
components, thus I create it during apache startup and stuff it into the
HTML::Mason::Commands namespace:

package My::Handler;
[...]
my $structure = My::Structure->new();
[...]
sub handler {
  [...]
  $HTML::Mason::Commands::structure = $structure;
  [...]
}

Now I'd like to know if this could cause some sort of trouble because
I'm making a connection to the database during server startup (I'm also
using Apache::DBI)? What if My::Structure wants to perform other
database actions during every apache request? Is it safe to re-use the
database handle from $self->{_dbh} within My::Structure which got
initialized during server startup in the _init method? If not, what's a
better way of doing it?

Sorry for this lengthy post and thanks a lot for any help!

Tobias


All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to