Skip to content

Commit

Permalink
The 'buffer' attribute moved from Core::Context to Core::Request
Browse files Browse the repository at this point in the history
(renamed to 'vars' to save the need for a proxy method to retrieve it)

Changed the DSL access to use the request directly.
  • Loading branch information
mickeyn authored and xsawyerx committed Jul 23, 2014
1 parent 12a9557 commit 32d772f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 38 deletions.
35 changes: 0 additions & 35 deletions lib/Dancer2/Core/Context.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/Dancer2/Core/DSL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
29 changes: 29 additions & 0 deletions lib/Dancer2/Core/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/Dancer2/Core/Role/Template.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 32d772f

Please sign in to comment.