PerlDancer / PerlDancer/Dancer2
params('query') returns undef until params() has been called
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 604
- Forks
- 288
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 5
Description
Status: confirmed against main @ 21bc21d9
lib/Dancer2/Core/Request.pm:130 and 346-349. _query_params is a bare hash read with no lazy builder, unlike its two siblings which both self-initialise:
sub _body_params { $_[0]->{'_body_params'} ||= $_[0]->body_parameters->as_hashref_mixed }
sub _query_params { $_[0]->{'_query_params'} } # <-- no ||=
sub _route_params { $_[0]->{'_route_params'} ||= {} }
Reproduction
A) params("query") BEFORE any params() call: UNDEF
B) params("query") AFTER params() call : hashref
Impact
It usually works inside a route handler, because dispatch calls _set_route_params → _build_params → _parse_get_params on the way in. It breaks in early hooks that run before route matching, and in any code path reaching params('query') first. In list context it is worse — %{ undef }.
Suggested fix
sub _query_params { $_[0]->{'_query_params'} ||= $_[0]->_parse_get_params }
Note _parse_get_params already returns early with $self->_query_params when the value is set (line 539). That guard still terminates once the accessor is lazy, because _set_query_params writes the hash element directly rather than going through the accessor — but it is subtle enough to deserve a test.
Suggested test
params('query') returns a hashref on a fresh request with no prior params() call.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/Dancer2/Core/Request.pm at _query_params around line 130 and the related logic around lines 346-349 and 539. Verify params('query') on a fresh request before any params() call, then add coverage showing it returns a hashref and that the existing lazy-parse guard still behaves correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100