Permalink
Browse files

やっぱりevalで...

  • Loading branch information...
1 parent 9d0f6bc commit c1a16756dc9c96328a52fc4ef49b8cc7908e2737 @nekokak committed Nov 12, 2010
Showing with 24 additions and 17 deletions.
  1. +5 −4 lib/Kamui/Web/Context.pm
  2. +18 −13 lib/Kamui/Web/Handler.pm
  3. +1 −0 t/030_plugin/basic.t
View
@@ -200,17 +200,18 @@ sub initialize_plugins {
}
sub finalize {
- my ($self, $response) = @_;
+ my $self = shift;
- $self->finalize_plugins($response);
+ $self->finalize_plugins;
$self->finalize_encoding;
+ $self->res->finalize;
}
sub finalize_plugins {
- my ($self, $response) = @_;
+ my $self = shift;
for my $plugin (@{$self->_plugins('finalize')}) {
- $self->$plugin->finalize($response);
+ $self->$plugin->finalize($self->res);
}
}
View
@@ -36,10 +36,9 @@ sub handler {
my $rule = $self->dispatcher->determine($context);
$context->dispatch_rule($rule);
- my $response = $self->dispatch($context);
- $context->finalize($response);
+ $self->dispatch($context);
- $response->finalize;
+ $context->finalize;
};
}
@@ -68,23 +67,29 @@ sub dispatch {
if (my $dispatch_code = $controller->can($method)) {
- $controller->authorize($dispatch_code, $context);
- return $context->res if $context->is_finished;
+ eval {
+ $controller->authorize($dispatch_code, $context);
+ return if $context->is_finished;
- $controller->call_trigger('before_dispatch', $context, $context->dispatch_rule->{args});
- return $context->res if $context->is_finished;
+ $controller->call_trigger('before_dispatch', $context, $context->dispatch_rule->{args});
+ return if $context->is_finished;
- $controller->$method($context, $context->dispatch_rule->{args});
- return $context->res if $context->is_finished;
+ $controller->$method($context, $context->dispatch_rule->{args});
+ return if $context->is_finished;
- $controller->call_trigger('after_dispatch', $context, $context->dispatch_rule->{args});
- return $context->res if $context->is_finished;
+ $controller->call_trigger('after_dispatch', $context, $context->dispatch_rule->{args});
+ return if $context->is_finished;
- return $context->render;
+ $context->render;
+ };
+ if ($@) {
+ warn $@;
+ $context->handle_500;
+ }
} else {
warn q{can not find dispatch method.};
- return $context->handle_404;
+ $context->handle_404;
}
}
View
@@ -40,6 +40,7 @@ subtest 'finalize test' => sub {
env => $env,
app => 'Mock::Web::Handler',
);
+ $c->res->status('200');
is $c->fin->call, 'finalize';
stdout_is(sub { $c->finalize }, 'call finalize hook');
done_testing;

0 comments on commit c1a1675

Please sign in to comment.