I want to summarize some of the thoughts on this thread
and see if there's any strong disagreement.

o The model should validate its data.

o The controller should (directly or indirectly) validate
  all the form input so you're pretty sure the model(s)
  can handle it.

o Where the model and the controller validation overlap,
  the validation code should be shared.

o The validation code that runs in the controller is
  responsible for generating the end-user error messages
  and i18n.

o If a validation error makes it to the model, it should
  raise an exception.

o When raising exceptions in the model, use
  Exception:Class so it's catchable. From Dave Rolsky's
  example:

  eval {
     $user->update( %bunch_of_stuff );
  };

  if (my $e = Exception::Class->caught(
        'My::App::Exception::DataValidation') ) {
    # $e->errors contains multiple data validation error messages
    # stuff them in the session
    # save the user's form submission in the session
    # redirect back to form
  } elsif ( my $e = $@ ) {
     die $e;
  }

Anyone think there's a better approach within the context
of large-scale website development?

Thanks,

Maurice

_______________________________________________
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/

Reply via email to