From 42cad48b837d255155f94f8c41e3843353b35a3b Mon Sep 17 00:00:00 2001 From: mickey Date: Thu, 29 May 2014 07:48:26 +0200 Subject: [PATCH] The 'buffer' attribute moved from Core::Context to Core::Request (renamed to 'vars' to save the need for a proxy method to retrieve it) Changed the DSL access to use the request directly. --- lib/Dancer2/Core/Context.pm | 35 ------------------------------- lib/Dancer2/Core/DSL.pm | 4 ++-- lib/Dancer2/Core/Request.pm | 29 +++++++++++++++++++++++++ lib/Dancer2/Core/Role/Template.pm | 2 +- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/lib/Dancer2/Core/Context.pm b/lib/Dancer2/Core/Context.pm index 3a59788f5..e21dfd7e3 100644 --- a/lib/Dancer2/Core/Context.pm +++ b/lib/Dancer2/Core/Context.pm @@ -39,41 +39,6 @@ has request => ( lazy => 1, ); -# a buffer for per-request variables -has buffer => ( - is => 'rw', - isa => HashRef, - default => sub { {} }, -); - -=method vars - -Returns a hashref of all per-request variables stored in this object. - -=cut - -sub vars { shift->buffer } - -=method var - -By-name interface to variables stored in this context object. - - my $stored = $context->var('some_variable'); - -returns the value of 'some_variable', while - - $context->var('some_variable' => 'value'); - -will set it. - -=cut - -sub var { - my $self = shift; - @_ == 2 - ? $self->buffer->{ $_[0] } = $_[1] - : $self->buffer->{ $_[0] }; -} =attr response diff --git a/lib/Dancer2/Core/DSL.pm b/lib/Dancer2/Core/DSL.pm index 35c20ca6b..3f9282f85 100644 --- a/lib/Dancer2/Core/DSL.pm +++ b/lib/Dancer2/Core/DSL.pm @@ -305,8 +305,8 @@ sub forward { $self->request->forward($self->context, @_); } -sub vars { shift->context->vars } -sub var { shift->context->var(@_) } +sub vars { shift->request->vars } +sub var { shift->request->var(@_) } sub cookies { shift->request->cookies } diff --git a/lib/Dancer2/Core/Request.pm b/lib/Dancer2/Core/Request.pm index 4ee189678..51d2847d4 100644 --- a/lib/Dancer2/Core/Request.pm +++ b/lib/Dancer2/Core/Request.pm @@ -142,6 +142,35 @@ has env => ( ); +# a buffer for per-request variables +has vars => ( + is => 'rw', + isa => HashRef, + default => sub { {} }, +); + +=method var + +By-name interface to variables stored in this request object. + + my $stored = $request->var('some_variable'); + +returns the value of 'some_variable', while + + $request->var('some_variable' => 'value'); + +will set it. + +=cut + +sub var { + my $self = shift; + @_ == 2 + ? $self->vars->{ $_[0] } = $_[1] + : $self->vars->{ $_[0] }; +} + + =method path() Return the path requested by the client. diff --git a/lib/Dancer2/Core/Role/Template.pm b/lib/Dancer2/Core/Role/Template.pm index b8732fca4..dc91c8640 100644 --- a/lib/Dancer2/Core/Role/Template.pm +++ b/lib/Dancer2/Core/Role/Template.pm @@ -153,7 +153,7 @@ sub _prepare_tokens_options { $tokens->{settings} = $self->context->app->config; $tokens->{request} = $request; $tokens->{params} = $request->params; - $tokens->{vars} = $self->context->buffer; + $tokens->{vars} = $request->vars; $tokens->{session} = $self->context->session->data if $self->context->has_session;