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;