[Catalyst] Lightweight error/messages reporting to templates

Paul Makepeace paulm at paulm.com
Fri May 25 02:28:11 GMT 2007


Thanks folks - this and Michael's suggestion were just what I was
after. I'll check out the exceptions stuff too.

P

On 5/24/07, Nathaniel Nuss <ogmoid at gmail.com> wrote:
> On Wed, May 23, 2007 at 07:29:57PM +0100, Paul Makepeace wrote:
> > I'm hoping there's a 'best practice' or common pattern for reporting
> > errors and messages to templates (not necessarily just forms).
>
> I've opted for defining a function in a Controller base class.
>
> <contrived example>
>
>
> package MyApp::Controller::Base;
>
> sub sysmsg {
>     my ( $self, $c, $type, $msg ) = @_;
>     # Push [ $type, $msg ] onto the flash to preserve the message across
>     # redirect.
>     push @ {$c->flash->{sysmsg}}, [ $type, $msg ];
> }
>
>
> package MyApp::Controller::Whatever;
>
> use base 'MyApp::Controller::Base';
> ...
>     if ( $something_noteworthy ) {
>         $self->sysmsg( $c, 'err', 'Error. Halt Catch Fire.' );
>     }
> ...
> 1;
>
>
> msg template [here TT2 and part of a series of WRAPPERs]
>
> [%- IF c.flash.sysmsg.size %]
> [%- FOREACH msg IN c.flash.sysmsg %]
> [%- IF msg.0.length %]
> <div class="[% msg.shift %]">[% msg.shift %]</div>
> [%- END ; #IF %]
> [%- END ; #FOREACH %]
> [%- END ; #IF %]
>
>
> </contrived example>
>
> I also implemented breadcrumb dropping similarly.
>
> --
> Nate Nuss
>
> [ The IF wrapper around the <div> was for an issue I was having (but haven't
> yet followed up on) where the same content skeleton exists on the second try
> but the content has been consumed (now empty) ]
>
> ( [Kind] critique welcomed. )
>
> _______________________________________________
> List: Catalyst at 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/
>



More information about the Catalyst mailing list