Re: Advice needed on custom webapp framework
[prev]
[thread]
[next]
[Date index for 2004/11/17]
Jonathan Vanasco wrote:
> package Website1;
> my $DB = new Website1::DB();
> # make a new ref for the website
> sub handler
> {
> my $r = shift;
> my $user = new Website::User( \$r, \$DB );
> my $page = new Website::Page( \$user , \$DB );
> my $html = $page->processRequest();
> }
>
> what i would like is:
> sub handler
> {
> my $r = shift;
> my $user = new Website::User( \$r );
> my $page = new Website::Page( \$user );
> my $html = $page->processRequest();
> }
>
> now, i guess what i'm trying to do within
> Website1::User
> Website1::Page
> is access the
> $DB in the base of Website1 that i define just before the handler
> BUT
> I'm trying to do so in a way that both:
> Website1::PackageName
> Website2::PackageName
> WebAppFramework::PackageName
> Will all retreive the correct DB from the script that defines the
> handler
>
Ok. This means you want to make your Website::User and Website::Page
more intelligent. If I got you right the only thing have to implement
for each user is Website1::DBI and Website2::DBI.
What you really need here when talking about Pattern-Programming is a
"Factory-Class" which creates the
appropiate WebAppFramework::DBI-Sub-Class for you and design all your
Website*::DBI-classes as "Singletons".
===================8<===================
package WebAppFramework::DBIFactory;
sub getDb {
my $dbiModule = shift;
require($dbiModule); ## load the apprioate module
return $dbiModule->instance(); ## get an instance of the module
}
1;
===================8<===================
===================8<===================
package WebAppFramework::User;
sub new {
my $class = shift;
my $r = shift;
my $this =
{
db =>
WebAppFramework::DBIFactory::getDb($r->dir_config("DBIModule"));
};
bless $this, $class;
}
1;
===================8<===================
===================8<===================
<Location /webapp1>
PerlSetVar DBIModule Website1::DBI
</Location>
<Location /webapp2>
PerlSetVar DBIModule Website2::DBI
</Location>
===================8<===================
Hope I got you right? If you don't want to use config values you could
also use the name of the package
in the handler e.g. Website1, Website2 and add "::DBI" in your factory
method.
Tom
--
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