On Wed, 17 Nov 2004, jonathan vanasco wrote:

> Ideally, I would have the packages  in Website and WebAppFramework
> lookup the right DB for the Website

There are many ways to solve this problem.  I'll show you 2 ways.  I'll
focus just on the database part to keep this as short as possible, but
the same ideas apply to the user object...

One way is to put the databse in a separate package and access it
using static methods.

e.g.:

my $dbh = Website::Database->dbh;

You could even make this a method of WebAppFramework.  Then you are
simply left with the problem of getting the right database handle for
each website.  There are many ways to do that.  One way would be to just
have a hash or something in WebAppFramework that stores the database
handles for each partuclar website, and then have your dbh() (or
whatever you decide to call it) method figure out which handle to
retrieve.  The downside is that you have to modify WebAppFramework
everytime you create a new application (or, create methods for managing
the datbase hash, and call them from within your appliaction). If you
don't want to do it that way, another way would be to simply subclass
WebAppFramework for each site, and then have the individual appliactions
subclass it.  e.g.:

package WebAppFrameWork::SomeSite;

use base 'WebAppFrameWork';

sub dbh {
    # return database appropriate for "SomeSite"
}
...
__END__

package WebApp::SomeSite::SomeApp;

use base 'WebAppFrameWork::SomeSite';

# calling $self->dbh in here calls WebAppFrameWork::SomeSite->dbh
# plus you can call any methods provided by WebAppFrameWork
...

__END__

Regards,
Michael Schout

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Reply via email to