CUSTOMIZING
Customizing you usage of Minima is quite straightforward once you understand how it works and a few PSGI concepts. If you haven't yet, check "How it works" in Minima.
Setup
The setup process can be completely skipped. If your goal is to create a custom app, load your configuration hash and create Minima::App yourself:
app.psgi
use Minima::App;
my $app = Minima::App->new(
environment => $env,
configuration => $config,
);
sub { $app->run }
Controllers
A controller is where you implement your application’s logic. Its main role is to return a valid PSGI response.
By default, controllers inherit from Minima::Controller, which provides convenient lifecycle hooks and helper methods.
However, inheritance is not required. A controller can simply provide the action methods declared in routes.map
. In that case, Minima will call the methods directly and expect them to return a valid PSGI response. This makes it easy to write very minimal controllers if you prefer.
When Minima::App instantiates and calls your controller, it will pass two named arguments to new
:
app => $self,
route => $m,
Depending on your implementation details (whether your controller is a class, package, or another type of object) you may or may not use these arguments.
Arguments
app
-
A reference to the Minima::App instance which is initializing your controller.
route
-
The matched route as returned by Minima::Router.
Lifecycle Hooks
Controllers may also define optional lifecycle hooks:
before_action ($method)
-
Runs before the action is executed. If it returns a PSGI response, the action itself is skipped and that response is returned immediately.
after_action ($response)
-
Runs after the action has completed. It receives the response returned by the action, which can be modified in place if needed.
For more details, see the run method in Minima::App.
As your controller is called last, remember to return a valid PSGI response and you're good to go.
Templating System
If you want to customize how Template Toolkit is used in Minima::View::HTML, check "Configuration" in Minima::View::HTML.
If you don't want to use Template Toolkit at all, just skip Minima::View::HTML. Your controller logic is solely responsible for calling it, so feel free to create your own views.
SEE ALSO
Minima, Minima::Manual::FAQ, perlclass.
AUTHOR
Cesar Tessarin, <cesar@tessarin.com.br>.
Written in September 2024.