Punk: a MVC framework
Every web framework does a certain amount of thinking on every request. It looks at the path and decides which route matched. It works out which chain of before filters are applied. It resolves 'Web::Book#view' into an actual coderef. It checks whether this action wants JSON. None of that work depends on the request in any interesting way, the answers are the same on request one and request one…
Punk is a Perl MVC framework that operates on the principle of pre-processing all necessary computations at startup, resulting in a frozen structure that eliminates the need for repeated work during request handling. This unique approach leads to faster request processing and error detection at startup, rather than during user requests.
The framework relies on a declarative DSL (Domain Specific Language) built with several keywords - get, post, put, patch, del, any, and under - to define routes, their corresponding actions, and optional guards. These guards either return a response, short-circuiting the request, or pass it along. For example, an admin area can be created with a guard that checks for an authorization header and redirects if missing.
Punk also supports static file serving, session management, and security features like CSRF protection. Configuration and secrets are managed externally, with the application loading YAML files and resolving secret values at boot time. Additionally, Punk can mount OpenAPI 3.1 specifications, allowing the framework to interpret the declared routes and associated data for seamless integration.
However, one notable limitation of Punk is that it does not allow for any runtime changes to the application structure, as the framework is fully compiled during boot. Consequently, if runtime additions or modifications are required, Punk may not be the ideal choice. Nonetheless, the application's wiring is guaranteed to be sound upon startup, providing a stable foundation for development.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.
