Stop the request needing the context, just pass in the logger instead
Tomas Doran [Mon, 31 Oct 2011 18:41:00 +0000 (18:41 +0000)]
lib/Catalyst.pm
lib/Catalyst/Request.pm
t/aggregate/unit_core_action.t
t/aggregate/unit_core_ctx_attr.t
t/aggregate/unit_core_uri_for.t
t/aggregate/unit_core_uri_for_action.t
t/aggregate/unit_core_uri_for_multibytechar.t
t/aggregate/unit_core_uri_with.t

index 3a8e5c3..571f260 100644 (file)
@@ -50,13 +50,20 @@ has request => (
     is => 'rw',
     default => sub {
         my $self = shift;
-        my %p;
+        my %p = ( _log => $self->log );
         $p{_uploadtmp} = $self->_uploadtmp if $self->_has_uploadtmp;
         $self->request_class->new(\%p);
     },
     lazy => 1,
 );
-has response => (is => 'rw', default => sub { $_[0]->response_class->new({}) }, required => 1, lazy => 1);
+has response => (
+    is => 'rw',
+    default => sub {
+        my $self = shift;
+        $self->response_class->new({ _log => $self->log });
+    },
+    lazy => 1,
+);
 has namespace => (is => 'rw');
 
 sub depth { scalar @{ shift->stack || [] }; }
@@ -2008,9 +2015,6 @@ sub prepare {
     my $uploadtmp = $class->config->{uploadtmp};
     my $c = $class->context_class->new({ $uploadtmp ? (_uploadtmp => $uploadtmp) : ()});
 
-    # For on-demand data
-    $c->request->_context($c);
-
     #surely this is not the most efficient way to do things...
     $c->stats($class->stats_class->new)->enable($c->use_stats);
     if ( $c->debug || $c->config->{enable_catalyst_header} ) {
index d1614a3..997b3ba 100644 (file)
@@ -81,10 +81,10 @@ sub prepare_headers {
     return $headers;
 }
 
-has _context => (
-  is => 'rw',
-  weak_ref => 1,
-  clearer => '_clear_context',
+has _log => (
+    is => 'ro',
+    weak_ref => 1,
+    required => 1,
 );
 
 # Amount of data to read from input on each pass
@@ -265,7 +265,7 @@ around parameters => sub {
     my ($orig, $self, $params) = @_;
     if ($params) {
         if ( !ref $params ) {
-            $self->_context->log->warn(
+            $self->_log->warn(
                 "Attempt to retrieve '$params' with req->params(), " .
                 "you probably meant to call req->param('$params')"
             );
index ca84422..85ecc35 100644 (file)
@@ -38,7 +38,7 @@ my $anon_meta = Moose::Meta::Class->create_anon_class(
       request => (
         reader => 'request',
         required => 1,
-        default => sub { Catalyst::Request->new(arguments => [qw/one two/]) },
+        default => sub { Catalyst::Request->new(_log => Catalyst::Log->new, arguments => [qw/one two/]) },
       ),
     ),
   ],
index 219600f..4f21cfe 100644 (file)
@@ -8,6 +8,7 @@ use URI;
 use_ok('TestApp');
 
 my $request = Catalyst::Request->new( {
+                _log => Catalyst::Log->new,
                 base => URI->new('http://127.0.0.1/foo')
               } );
 my $dispatcher = TestApp->dispatcher;
index dad5a1c..6732024 100644 (file)
@@ -8,6 +8,7 @@ use URI;
 use_ok('TestApp');
 
 my $request = Catalyst::Request->new( {
+                _log => Catalyst::Log->new,
                 base => URI->new('http://127.0.0.1/foo')
               } );
 my $dispatcher = TestApp->dispatcher;
index f7cd481..9b34229 100644 (file)
@@ -102,6 +102,7 @@ is($dispatcher->uri_for_action($chained_action, [ 1 ]),
 #   Tests with Context
 #
 my $request = Catalyst::Request->new( {
+                _log => Catalyst::Log->new,
                 base => URI->new('http://127.0.0.1/foo')
               } );
 
index 6f5d8ae..b167818 100644 (file)
@@ -10,6 +10,7 @@ use_ok('TestApp');
 my $base = 'http://127.0.0.1';
 
 my $request = Catalyst::Request->new({
+    _log => Catalyst::Log->new,
     base => URI->new($base),
     uri  => URI->new("$base/"),
 });
index c8a3ef0..5e86318 100644 (file)
@@ -1,12 +1,14 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More;
 use URI;
+use Catalyst::Log;
 
 use_ok('Catalyst::Request');
 
 my $request = Catalyst::Request->new( {
+                _log => Catalyst::Log->new,
                 uri => URI->new('http://127.0.0.1/foo/bar/baz')
               } );
 
@@ -23,6 +25,7 @@ is(
 );
 
 my $request2 = Catalyst::Request->new( {
+                _log => Catalyst::Log->new,
                 uri => URI->new('http://127.0.0.1/foo/bar/baz?bar=gorch')
               } );
 is(
@@ -67,3 +70,5 @@ is(
     'append mode URI appends arrayref param'
 );
 
+done_testing;
+