rewrote Request lifecycle
André Walker [Fri, 5 Aug 2011 23:50:14 +0000 (20:50 -0300)]
lib/Catalyst/IOC/LifeCycle/Request.pm

index 1d6f3e3..6a5bcad 100644 (file)
@@ -1,12 +1,17 @@
 package Catalyst::IOC::LifeCycle::Request;
 use Moose::Role;
 use namespace::autoclean;
-
-# based on Bread::Board::LifeCycle::Request from OX
-# just behaves like a singleton - ::Request instances
-# will get flushed after the response is sent
 with 'Bread::Board::LifeCycle::Singleton';
 
+around get => sub {
+    my $orig = shift;
+    my $self = shift;
+
+    my $ctx       = $self->param('ctx');
+    my $stash_key = "__Catalyst_IOC_LifeCycle_Request_" . $self->name;
+    return $ctx->stash->{$stash_key} ||= $self->$orig(@_);
+};
+
 1;
 
 __END__