PerlDancer / PerlDancer/Dancer2
`prefix` peculiarities
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 604
- Forks
- 288
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 5
Description
Not sure if this is a bug or a feature, but it should be documented. If you are using prefix and have your routes spread across several packages, you need to ensure that prefix is undefined at the end of each package of routes, or you'll get weird 404 errors. My situation:
I've got a wrapper app that holds all my routes:
package WrapperApp;
use Routes::Here; ## routes starting with /here
use Routes::There; ## routes starting with /there
1;
I was using the prefix '/here'; syntax because I kept getting strange 404 errors with the prefix '/here' => sub { ... }; syntax.
I added a new package with a /test route, but got 404s whenever I tried to access it. By chance, I tried /there/test, which returned my test page. When I set prefix to undef at the end of Routes::There, I could access /test correctly. Swapping around the order of the packages in WrapperApp demonstrated that the prefix from the previously-listed package was carried over. When I converted all of my prefixed routes to the prefix '/blah' => sub { ... }; syntax, or added prefix undef to each package, the problem vanished.
This may be an edge case, but I think it's worth adding something to the docs about undefining prefix at the end of each package if you're using the prefix '/blah' syntax.
On a different note, it would be really useful if prefixacted more like the route handlers (get,post, etc.) and you could set variables (using var) and do other such things based on the partial route match provided by prefix.
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 with the WrapperApp imports and the Routes::Here/Routes::There examples described in the issue, then inspect the existing prefix documentation and routing entry point. Document that prefix state can carry between packages and that prefix undef resets it, with an example; separately assess the request for prefix to support var and other handler behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- backend-api-design, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100