NAME
Punk::Controller - base class for Punk controllers
SYNOPSIS
package MyApp::Controller::Web::Book;
use Punk::Controller;
sub list {
my ($c) = @_;
my $page = $c->model('Book')->search({}, { limit => 20 });
return $c->render('book/list', { books => $page->{rows} });
}
1;
DESCRIPTION
Controller methods are plain subs receiving the Punk::Context - no instance, no dispatch overhead; the coderef is resolved once at to_app and called directly per request. The base class marks the package as a controller and is the natural home for shared helper subs an app wants every controller to inherit.
use Punk::Controller makes the caller a controller and turns on strict and warnings, the way use Punk::Model does for a model. The older form still works and is unchanged:
use parent 'Punk::Controller'; # same base class, no pragmas
so existing controllers need no edit; the one-line form is simply what the scaffolder writes now.
Route targets name controllers relative to the application's Controller:: namespace: 'Web::Book#list' in MyApp resolves to MyApp::Controller::Web::Book::list. A fully qualified name (one that already starts with the namespace) passes through unchanged.
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)