I'm currently working on a small web app; the details are unimportant and uninteresting. What is important & interesting is that it is the pilot for a number of my ideas on how to write a web app via a bunch of Perl modules that act as infrastructure: Tangram, Class::Tangram::Generator, XML::Simple, CGI::Application, and CGI::Application::Session. The goal is basically to write as little code as possible and still get the job done. And, of course, to separate code from presentation details.
Tangram is working like a charm; the impedance mismatch between my objects and the database is effectively taken care of. Aside from building a connection string I don't really worry about the database. When I need to add extra logic to classes, I inherit from Class::Tangram, and objects of my class automatically spring to life as they are pulled from the database.
XML::Simple handles half of the object / presentation impedance mismatch. With the right settings, XMLOut() turns my objects into very clean xml that is passed through an xsl stylesheet to become an xhtml page.
CGI::Application handles flow between different "run modes," which basically correspond to the screens a user will see. With it I have a single entry point--a cgi script--that instantiates and runs a CGI::Application object. This object switches between run modes and handles persistence via CGI::Application::Session.
There are some small things I haven't yet figured out. E.g., I don't know how I will elegantly get post data back into objects. That's the other half of the object / presentation mismatch.
There are also some performance issues. I'm not obsessing about them right now because, as Knuth famously noted, "Premature optimization is the root of all evil." They are tractable & I will solve them when the time comes.
With objects at the top of the object hierarchy, bringing them over in full from the database side and then pushing them through the page will be pretty wasteful...often, you just need to display data in the first few layers. So I need to figure out a pattern for pruning object hierarchies, and it needs to be part of the database infrastructure. Also, right now I'm not persisting the database connection, so a new one is made on every page access. That's slowing things down a bit.
Posted by Alan at June 18, 2004 09:28 PM