Re: Advice needed on custom webapp framework

2004-11-17 Thread Jonathan Vanasco
I'm pretty damn sure you did get that right!
That would do EXACTLY what i want it to do!
I'm gonna play around with that approach when i get home tonight.  
Thanks!

On Nov 17, 2004, at 2:26 PM, Tom Schindl wrote:
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".

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.

--
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


Re: Advice needed on custom webapp framework

2004-11-17 Thread Tom Schindl
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<===

   PerlSetVar DBIModule Website1::DBI


   PerlSetVar DBIModule Website2::DBI

===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


Re: Advice needed on custom webapp framework

2004-11-17 Thread Jonathan Vanasco
Because i'm an idiot and didn't realize that I was doing that!
I'm just used to passing refs everywhere.  to get into the whole 'No 
More passing large vars around' thing, i just stopped passing 
everything but a ref

Silly me!
On Nov 17, 2004, at 1:25 PM, Tom Schindl wrote:
I don't answer your questions but why are you passing all objects by 
reference. An object is already a reference (normally Hash or Scalar)
and it does not improve your memory usage it only decreases your 
performance because you always have to dereference it.

--
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


Re: Advice needed on custom webapp framework

2004-11-17 Thread Tom Schindl
jonathan vanasco wrote:
I built for mod_perl1 a customer webapp framework
It functions as 2 perl modules/package sets
/lib/WebAppFramework
/lib/Website
For each website/webapp, i make a new /lib/Website that subclasses the 
WebAppFramework (which handles users, email, webpage generation, etc 
-- and makes heavy use of cpan modules -- i just wanted a way to find 
a lowest-common-denominator to interface with multiple packages, so i 
can rapidly prototype webapps)

It worked really well for everything I want it to do -- super simple 
and easy to build and add functions.

except - its a little messy
The idea I wanted to implement, is essentially this handler:
my  $DB = new Website::DB();
sub handler {
DEBUG >0 && print STDERR " NEW 
REQUEST\n\n";
my $r = shift;
my $user = new Website::User( \$r, \$DB );
 my $page = new Website::Page( \$user , \$DB );
my $html = $page->processRequest();
$r->content_type('text/html');
$r->print( $html );
return OK;
}

I don't answer your questions but why are you passing all objects by 
reference. An object is already a reference (normally Hash or Scalar)
and it does not improve your memory usage it only decreases your 
performance because you always have to dereference it.

The idea, is that any page is just a view to a user (logged in or 
not), so is rendered to that person.

Now, this is my issue -- I'm creating a user AND a page with a ref to 
the DB handle - which is wasteful. And requires a lot of extra typing 
on my part.

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

I can't figure out how to do this in a coherent way though.
Any  advice would be excellent.


--
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


Re: Advice needed on custom webapp framework

2004-11-17 Thread Jonathan Vanasco
Thanks!
Right now, I should have been more clear, though -- I'm am kinda doing 
a bit of each approach you mentioned -- but i am in need of a little 
more help.

I think what i want is more of your second approach right now...
 Let me elaborate for a moment
WebAppFramework::DB.pm
Base Class
Users Apache:DBI
Package handles all DB abstraction and connections
Website1::DB.pm
SubClass of WebAppFramework::DBI.pm
Package has configuration information (host/port/user/pass/etc)
Website2::DB.pm
	SubClass of WebAppFramework::DBI.pm
	Package has configuration information (host/port/user/pass/etc)
	Website1/Website2 are different package directories that subclass the 
framework
	I'm showing Website1/Website2 just to illustrate the namespace

In the example on my last post, my handle does this:
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

I've tried this a few different ways, but I've often ended up reading  
WebAppFramework::$DB instead of Website1::$DB
I guess I'm trying to figure out a way for the baseclasses to access 
information in the subclasses - which sounds wrong, stupid and 
impossible.

Does that make more sense?  Does your suggestion still apply?
Sorry, I'm just very confused by all this myself, and I fear that i'm 
not asking the right questions.


On Nov 17, 2004, at 12:11 PM, Michael Schout wrote:
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...

--
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


Re: Advice needed on custom webapp framework

2004-11-17 Thread Michael Schout
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



Advice needed on custom webapp framework

2004-11-17 Thread jonathan vanasco
I built for mod_perl1 a customer webapp framework
It functions as 2 perl modules/package sets
/lib/WebAppFramework
/lib/Website
For each website/webapp, i make a new /lib/Website that subclasses the 
WebAppFramework (which handles users, email, webpage generation, etc -- 
and makes heavy use of cpan modules -- i just wanted a way to find a 
lowest-common-denominator to interface with multiple packages, so i can 
rapidly prototype webapps)

It worked really well for everything I want it to do -- super simple 
and easy to build and add functions.

except - its a little messy
The idea I wanted to implement, is essentially this handler:
my  $DB = new Website::DB();
sub handler {
	DEBUG >0 && print STDERR " NEW 
REQUEST\n\n";
	my 	$r 		= shift;
	my 	$user 	= new Website::User( \$r, \$DB );
 	my 	$page 	= new Website::Page( \$user , \$DB );
	my 	$html 	= $page->processRequest();
	$r->content_type('text/html');
	$r->print( $html );
	return OK;
}

The idea, is that any page is just a view to a user (logged in or not), 
so is rendered to that person.

Now, this is my issue -- I'm creating a user AND a page with a ref to 
the DB handle - which is wasteful. And requires a lot of extra typing 
on my part.

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

I can't figure out how to do this in a coherent way though.
Any  advice would be excellent.
--
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