On Tue, Apr 25, 2017 at 9:13 AM, iaw4 <[email protected]> wrote:

> get '/' => sub {
>   sub callme {  calldeeper($@);  }
>   sub calldeeper { my $somethingbadhashappened=1;
> ($somethingbadhashappened) and completelyredirect($@);  }
>   sub completelyredirect { my $c=shift; $c->flash( message => "you are too
> young to die" );  $c->redirect_to("/respawn"); }
>   callme($@);
>   $_[0]->render(text => 'this is index, not aborted');
> };
>

I'm not sure what to do with this.  This approach is either a design
pattern beyond my level or incomplete.

The key thing that you have missed is that you need to `return if
callme();`  Not understanding the code above, it seems that, yes, your code
might generate both a flash and redirect and then still render text.  I
think this is what you don't want to happen.  That's why you need to
return.  And, you do not want to *exit* -- you want to *return*.

Notice my sample urlrequest action: it *returns* flash and redirect if
there is a problem with callme.  It doesn't allow the urlrequest action to
keep processing.

sub urlrequest {

  my $c = shift;

  if ( my $x = callme() ) {

    return $c->flash(message=>$x->{message})->redirect_to($x->{route});
  }

  ...do more with $x...

}

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to