I'm hoping there's a 'best practice' or common pattern for reporting
errors and messages to templates (not necessarily just forms).

I find myself doing stuff like,

my @errors; my @messages;
# ...
if ($some_err_condition) {
  push @errors, "whoops";
} else {
  $obj->update;
  push @messages, $obj->name . " updated!";
}
# ...
$c->stash(messages => join "<br/>", @messages);
$c->stash(errors => join "<br/>", @errors);

Which is then tediously copy & pasted amongst controllers that do that
reporting.

And then my template says something like,

 [% IF errors %]
   <p class="error">[% errors %]</p>
 [% END %]
 [% IF messages %]
   <p class="messages">[% messages %]</p>
 [% END %]

At least with the template I have that as a MACRO I can call variously
but I'd at least like a way to have some kind of
context/controller-wide way of dealing with these errors & messages. I
don't quite understand Cat's object model well enough to do this
globally myself yet.

P

_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to