Jesse Erlbaum wrote: > As you have already identified, the Model is simply a Perl module. The most > important thing to think of when writing a Model module is to make sure you > make it entirely separate from the user interface. It helps me to think of > the methods in the Model as potentially being called from a web application, > a cron script, or an email-based interface. The Model should not contain > anything specific about any of the interfaces through which it might be > accessed.
Hi, Jesse. I think this part is probably an evolution from the earlier days of CGI::Application, at least in the applications your company wrote for my former, now defunct, employer. :) There was a tendency to make the CGI::Application-derived modules both M and V. I'm glad to see that's less the case these days. My current approach is to use Mason for implementing the controller and view, with a lot of the business logic put in the "model". I'm probably going to explore using CGI::Application and either HTML::Template or Template Toolkit for a current side project. Do you have a favorite approach for writing the Model objects? At Investorama we created a class called TableObject that would deal with getting/setting values from the database, plus doing data verification like checking for values being present and well-formed XML in fields that needed it. I still use that approach on my consulting projects. It's not a very complex object, and it doesn't do things recursively, like mapping an attribute to an object and handling that object as well. TableObject doesn't act as a base class. It just becomes one of the attributes of the object. A typical invocation is something like this: my %fields = ( id => { type => 'num', pkey => 1, sequence => 'seq_users' }, email => { type => 'string', required => 1 }, password => { type => 'string', required => 1 }, first_name => { type => 'string', required => 1 }, last_name => { type => 'string', required => 1 }, valid => { type => 'num', required => 1}, member_id => { type => 'num' }, ); my $table = NAIC::TableObject->new(DBH => $self->dbh, OBJECT => $self, TABLE => 'users', FIELDS => \%fields, VERIFY => 1); $table is then put into $self as an attribute called '_table'. Storing/retrieving/verifying are done with $self->_table->store etc. It expects that the attributes of an object like $self->email match the database columns. -- Barry Hoggard Tristan Media LLC e: [EMAIL PROTECTED] p: 212-627-1596 aim: hoggardb