Skip to content

Instantly share code, notes, and snippets.

@kazeburo
Created August 7, 2012 07:29
Show Gist options
  • Select an option

  • Save kazeburo/3282828 to your computer and use it in GitHub Desktop.

Select an option

Save kazeburo/3282828 to your computer and use it in GitHub Desktop.
diff --git a/lib/Plack/Middleware/Scope/Container.pm b/lib/Plack/Middleware/Scope/Container.pm
index ec35abe..294fd4a 100644
--- a/lib/Plack/Middleware/Scope/Container.pm
+++ b/lib/Plack/Middleware/Scope/Container.pm
@@ -4,14 +4,25 @@ use strict;
use warnings;
use parent qw(Plack::Middleware);
use Scope::Container;
+use Plack::Util;
our $VERSION = '0.02';
sub call {
my ( $self, $env) = @_;
my $container = start_scope_container();
- $env->{'scope.container'} = $container;
- $self->app->($env);
+ my $res = $self->app->($env);
+ Plack::Util::response_cb($res, sub {
+ my $res = shift;
+ return sub {
+ my $chunk = shift;
+ if ( ! defined $chunk ) {
+ undef $container;
+ return;
+ }
+ return $chunk;
+ };
+ });
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment