Skip to content

Commit

Permalink
more consistent flow control examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 28, 2013
1 parent 658c6cb commit 9202173
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -584,17 +584,17 @@ leading to the next dispatch cycle will be automatically assigned to it.
my $self = shift;

# Wait 3 seconds and then give visitors a 50% chance to continue
my $continue;
my $next;
Mojo::IOLoop->timer(3 => sub {

# Loser
return $self->render(text => 'No luck.') unless int rand 2;

# Winner
$continue->();
$next->();
});

return \$continue;
return \$next;
});
$foo->route('/bar')->to(controller => 'foo', action => 'bar');

Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -59,8 +59,8 @@ sub dispatch {
}
}

my @copy = @{$c->match->stack};
return undef unless @copy && $self->_next($c, \@copy);
my @stack = @{$c->match->stack};
return undef unless @stack && $self->_next($c, \@stack);
$self->auto_render($c);
return 1;
}
Expand Down
6 changes: 3 additions & 3 deletions t/mojolicious/group_lite_app.t
Expand Up @@ -25,16 +25,16 @@ under('/missing' => sub {1})->route->to('does_not_exist#not_at_all');
under '/suspended' => sub {
my $self = shift;

my $continue;
my $next;
Mojo::IOLoop->timer(
0 => sub {
return $self->render(text => 'stopped!') unless $self->param('ok');
$self->stash(suspended => 'suspended!');
$continue->();
$next->();
}
);

return \$continue;
return \$next;
};

get '/' => sub { shift->render(inline => '<%= $suspended %>\\') };
Expand Down
6 changes: 3 additions & 3 deletions t/mojolicious/lib/MojoliciousTest/Foo.pm
Expand Up @@ -57,15 +57,15 @@ sub stage2 { return shift->some_plugin }
sub suspended {
my $self = shift;

my $continue;
my $next;
Mojo::IOLoop->timer(
0 => sub {
$self->res->headers->append('X-Suspended' => 1);
$continue->();
$next->();
}
);

return \$continue;
return \$next;
}

sub syntaxerror { shift->render('syntaxerror', format => 'html') }
Expand Down

0 comments on commit 9202173

Please sign in to comment.