intuiting catalyst_component_name
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / LifeCycle / Request.pm
index f350e3a..39468d7 100644 (file)
@@ -1,10 +1,46 @@
 package Catalyst::IOC::LifeCycle::Request;
 use Moose::Role;
 use namespace::autoclean;
+use Carp;
+with 'Bread::Board::LifeCycle';
 
-# 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;
+
+    # FIXME - ugly, but the only way it'll work
+    # we should find out why
+    my $ctx = {@_}->{'ctx'}
+        or confess qq/This component has a Request lifecycle.\n/ .
+                   qq/The 'ctx' parameter is mandatory./;
+
+    my $stash_key = "__Catalyst_IOC_LifeCycle_Request_" . $self->name;
+    return $ctx->stash->{$stash_key} ||= $self->$orig(@_);
+};
 
 1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Catalyst::IOC::LifeCycle::Request - Components that last for one request
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+=head1 AUTHORS
+
+Catalyst Contributors, see Catalyst.pm
+
+=head1 COPYRIGHT
+
+This library is free software. You can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut