[Catalyst] Lightweight error/messages reporting to templates

John Napiorkowski jjn1056 at yahoo.com
Thu May 24 17:20:02 GMT 2007


--- Paul Makepeace <paulm at paulm.com> wrote:

> 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
> 
Hi,

This doesn't cover communicating errors to templates
but this journal at
"http://bricas.vox.com/library/post/catalyst-exceptionclass.html"
gives an example for creating custom Exception objects
that Catalyst can use.  Might be something here to
give you ideas (I know it did for me) but probably
doesn't qualify as lightweight.

--john


--John

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Catalyst mailing list