[cgiapp] I am thinking of writing a "Model" class for the CGI::Application

NP Bamber np.bamber at ntlworld.com
Thu Jun 18 14:23:55 EDT 2009


I have been using CGI::Application/HTML::Template for a while now and I 
like the feeling that the code base is small enough that I can master 
its internals. However I am finding that all my code needs refactoring 
for various reasons and I need something more like a "content management 
system". I do think I should learn "catalyst" if only for professional 
reasons however I would like to continue using the Titanium framework. I 
believe I can see an approach that would not require a lot of work, but 
would allow me to push some of my data structures (particularly 
metadata) out of perl and into a database. I have managed to extract 
from my head the following manifesto:

   The L<Titanium> framework does a reasonable job of the controller
   part of the    model-view-controller concept of web site 
architecture. Various
   template modules, for example    L<HTML::Template> can function as 
the view part and they are well
   integrated with our controller.    There are various candidates for a 
model class, for example
   L<DBIx::Class>. Another part of the Titanium    framework, 
L<CGI::Application::Dispatch> can be used to translate
   from search engine friendly URLs to    a database key - in fact the 
wildcard parameter provided by the
   Dispatch fall-through rule will do nicely.    All that is missing is 
a perl module to take the Dispatch wildcard,
   pull the template file name and the    various template parameters 
from the database and in a standard run
   mode stuff the parameters into the    template. This class provides 
the abstract base, that will be
   derived from by classes such as 
L<CGI::Application::Model::DBIx-Class>.    For particular processes such 
as form processing non-standard run
   modes might be returned from the database.    The standard run mode 
for processing off the database is installed
   by the class L<CGI::Application::Plugin::Model> and this module    
will also instantiate the module object. Keeping a list of pages on
   a database enables other finctionality provided by the classes    
L<CGI::Application::Plugin::Sitemap>,
   L<CGI::Application::Plugin::RSS> and    
L<CGI::Application::Plugin::Search>.

I can also see only one candidate for an alternative in the existing 
CPAN archive. That would be to represent "web pages" as objects using 
the Class::DBI and feed them into the template using the dot notation. 
However this seems to me to commit one to usage of Class::DBI (which 
there should be no commitment to any database encapsulation layer) and 
maybe it is entangling the view and model parts. Advice, correction or 
encouragement please.






More information about the cgiapp mailing list