From: Tomas Doran Date: Mon, 8 Oct 2012 19:04:40 +0000 (+0100) Subject: Enable hooking parameters into req/res construction. Useful if you are dynamically... X-Git-Tag: 5.90017~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=0df490ef10f0a2deaa3b7950e721fa44659de860 Enable hooking parameters into req/res construction. Useful if you are dynamically applying request or response roles --- diff --git a/Changes b/Changes index 9f23ad3..a7b3758 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ # This file documents the revision history for Perl extension Catalyst. + - Refactor request and response class construction to add methods + that roles can hook to feed extra parameters into the constructor + of request or response classes. + 5.90016 - 2012-08-16 15:35:00 - prepare_parameters is no longer an attribute builder. It is now a method that calls the correct underlying functionality (Bill Moseley++) diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index ea5507d..b959d7c 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -52,20 +52,30 @@ has request => ( is => 'rw', default => sub { my $self = shift; - my %p = ( _log => $self->log ); - $p{_uploadtmp} = $self->_uploadtmp if $self->_has_uploadtmp; - $self->request_class->new(\%p); + $self->request_class->new($self->_build_request_class_construction_parameters); }, lazy => 1, ); +sub _build_request_class_construction_parameters { + my $self = shift; + my %p = ( _log => $self->log ); + $p{_uploadtmp} = $self->_uploadtmp if $self->_has_uploadtmp; + \%p; +} + has response => ( is => 'rw', default => sub { my $self = shift; - $self->response_class->new({ _log => $self->log }); + $self->response_class->new($self->_build_response_class_construction_parameters); }, lazy => 1, ); +sub _build_response_class_construction_parameters { + my $self = shift; + { _log => $self->log }; +} + has namespace => (is => 'rw'); sub depth { scalar @{ shift->stack || [] }; }