Skip to content

Commit 42cad48

Browse files
committed
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.
1 parent 1ccd067 commit 42cad48

File tree

4 files changed

+32
-38
lines changed

4 files changed

+32
-38
lines changed

lib/Dancer2/Core/Context.pm

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,6 @@ has request => (
3939
lazy => 1,
4040
);
4141

42-
# a buffer for per-request variables
43-
has buffer => (
44-
is => 'rw',
45-
isa => HashRef,
46-
default => sub { {} },
47-
);
48-
49-
=method vars
50-
51-
Returns a hashref of all per-request variables stored in this object.
52-
53-
=cut
54-
55-
sub vars { shift->buffer }
56-
57-
=method var
58-
59-
By-name interface to variables stored in this context object.
60-
61-
my $stored = $context->var('some_variable');
62-
63-
returns the value of 'some_variable', while
64-
65-
$context->var('some_variable' => 'value');
66-
67-
will set it.
68-
69-
=cut
70-
71-
sub var {
72-
my $self = shift;
73-
@_ == 2
74-
? $self->buffer->{ $_[0] } = $_[1]
75-
: $self->buffer->{ $_[0] };
76-
}
7742

7843
=attr response
7944

lib/Dancer2/Core/DSL.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ sub forward {
305305
$self->request->forward($self->context, @_);
306306
}
307307

308-
sub vars { shift->context->vars }
309-
sub var { shift->context->var(@_) }
308+
sub vars { shift->request->vars }
309+
sub var { shift->request->var(@_) }
310310

311311
sub cookies { shift->request->cookies }
312312

lib/Dancer2/Core/Request.pm

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,35 @@ has env => (
142142
);
143143

144144

145+
# a buffer for per-request variables
146+
has vars => (
147+
is => 'rw',
148+
isa => HashRef,
149+
default => sub { {} },
150+
);
151+
152+
=method var
153+
154+
By-name interface to variables stored in this request object.
155+
156+
my $stored = $request->var('some_variable');
157+
158+
returns the value of 'some_variable', while
159+
160+
$request->var('some_variable' => 'value');
161+
162+
will set it.
163+
164+
=cut
165+
166+
sub var {
167+
my $self = shift;
168+
@_ == 2
169+
? $self->vars->{ $_[0] } = $_[1]
170+
: $self->vars->{ $_[0] };
171+
}
172+
173+
145174
=method path()
146175
147176
Return the path requested by the client.

lib/Dancer2/Core/Role/Template.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ sub _prepare_tokens_options {
153153
$tokens->{settings} = $self->context->app->config;
154154
$tokens->{request} = $request;
155155
$tokens->{params} = $request->params;
156-
$tokens->{vars} = $self->context->buffer;
156+
$tokens->{vars} = $request->vars;
157157

158158
$tokens->{session} = $self->context->session->data
159159
if $self->context->has_session;

0 commit comments

Comments
 (0)