Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

やっぱり大域脱出はしたい

  • Loading branch information...
commit bce7d4bb680d820117ac179411bfaa0299cae55a 1 parent c1a1675
@nekokak authored
View
9 lib/Kamui/Web/Context.pm
@@ -178,6 +178,15 @@ sub redirect {
$self->{is_finished} = 1;
$self->res->content_type("text/html");
$self->res->redirect($uri->as_string);
+ $self->detach;
+}
+
+our $DETACH = 'KAMUI_DETACH';
+sub detach { die $DETACH }
+sub is_detach {
+ my ($self, $detach) = @_;
+ return unless $detach;
+ $detach =~ /^${DETACH} at/;
}
sub initialize {
View
22 lib/Kamui/Web/Handler.pm
@@ -69,20 +69,16 @@ sub dispatch {
eval {
$controller->authorize($dispatch_code, $context);
- return 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 if $context->is_finished;
-
- $controller->call_trigger('after_dispatch', $context, $context->dispatch_rule->{args});
- return if $context->is_finished;
-
- $context->render;
+ unless ($context->is_finished) {
+ $controller->call_trigger('before_dispatch', $context, $context->dispatch_rule->{args});
+ $controller->$method($context, $context->dispatch_rule->{args});
+ $controller->call_trigger('after_dispatch', $context, $context->dispatch_rule->{args});
+ $context->render;
+ }
};
- if ($@) {
+ return if $context->is_detach($@);
+
+ if($@) {
warn $@;
$context->handle_500;
}
View
25 t/020_web/context/detach.t
@@ -0,0 +1,25 @@
+use t::Utils;
+use Test::More;
+use Test::Exception;
+use Kamui::Web::Context;
+use Mock::Web::Handler;
+
+subtest 'detach' => sub {
+ my $c = Kamui::Web::Context->new(
+ app => 'Mock::Web::Handler',
+ );
+ throws_ok(sub {$c->detach}, qr/^KAMUI_DETACH at/);
+ done_testing;
+};
+
+subtest 'is_detach' => sub {
+ my $c = Kamui::Web::Context->new(
+ app => 'Mock::Web::Handler',
+ );
+ ok not $c->is_detach(undef);
+ eval {$c->detach};
+ ok $c->is_detach($@);
+ done_testing;
+};
+
+done_testing;
View
2  t/020_web/context/redirect.t
@@ -8,7 +8,7 @@ subtest 'redirect' => sub {
my $c = Kamui::Web::Context->new(
app => 'Mock::Web::Handler',
);
- $c->redirect('/');
+ throws_ok(sub {$c->redirect('/')}, qr/^KAMUI_DETACH at/);
my $res = $c->res;
isa_ok $res, 'Kamui::Web::Response';
is $res->status, '302';
Please sign in to comment.
Something went wrong with that request. Please try again.