Re: [Maypole] Multiple controllers

From: Vsevolod (Simon) Ilyushchenko (simonf at cshl.edu)
Date: Thu Jan 13 2005 - 21:07:33 GMT


> I'm interested in this area and haven't ever seen any complete
> solutions. Data::FormValidator looks interesting but I haven't had time
> to try it yet. Simon, is there any chance of you posting [some of] your
> code so we can get a better idea of the advantages and drawbacks that
> you have found?

Okay, but this is going to be messy. Here's a part of the code that I am
working on right now. It saves an object with two date fields,
created_date and complete_date, and two employee-related field groups,
'employee' and 'contact' (user, full name, department).

(Yes, having more than one column for employee information breaks
relational rules, but emails make bad keys because they are not always
unique or constant, and employee numbers are a pain to deal with. This
in not relevant to my issue anyway.)

This code is called when an object is saved. Several steps already
happened before - the object was first initialized with the data from
the database, and after that all its simple fields have already been
initialized with CGI parameteres.

The empChecker and contactEmpChecker objects are of the type
EmployeeChecker, createdDateChecker and completeDateChecker are of the
type DateChecker.

$self->model refers to the model object.

I can kinda construct an abstraction on top of this to list dependent
checkers and iterate over them, but it's not going to be pretty. This is
not pretty either, though. :( We first pass values to the checkers, then
save them back to the model if they are okay.

sub postInit
{
     my ($self) = @_;

     #Get all CGI parameters that pass security checks.
     #(Not all users can modify all fields.)
     my $args = $self->webArgs;

     $self->empChecker->init($args);
     if ($self->empChecker->verified)
     {
         $self->empChecker->saveToModel($self->model);
     }

     $self->contactEmpChecker->init($args);
     if ($self->contactEmpChecker->verified)
     {
         $self->contactEmpChecker->saveToModel($self->model);
     }

     $self->createdDateChecker->initDate({webArgs => $args, date =>
$self->model->created_date});
     $self->completeDateChecker->initDate({webArgs => $args, date =>
$self->model->complete_date});

     my $start_date = $self->createdDateChecker->sqlDate;
     unless ($start_date)
     {
         $start_date = CSHL::Util->sqlDate;
         $self->createdDateChecker->initDate({date => $start_date});
     }

     $self->model->created_date($start_date);
 
$self->model->complete_date($self->completeDateChecker->sqlDate()) if
$self->completeDateChecker->sqlDate();
}

Simon

-- 

Simon (Vsevolod ILyushchenko) simonf at cshl.edu http://www.simonf.com

Terrorism is a tactic and so to declare war on terrorism is equivalent to Roosevelt's declaring war on blitzkrieg.

Zbigniew Brzezinski, U.S. national security advisor, 1977-81

_______________________________________________ maypole mailing list maypole at lists.netthink.co.uk http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT