Uniform::HTMX::Dancer2
A lightweight, seamless HTMX integration plugin for Dancer2 applications, built on the Uniform::HTMX base layer.
Features
- Zero-Boilerplate Inspection: Quickly check if a request came from HTMX via
is_htmx. - Clean Response Mutators: Easily set
HX-Trigger,HX-Retarget,HX-Redirect, and other HTMX response headers. - Automatic Header Flushing: Accumulated response headers are written back onto the Dancer2 response for you via an
afterhook — no manualapply()call required. - Unified API: Shared engine with
Uniform::HTMX, so the same method names and behavior carry over across PSGI, PAGI, and Mojolicious integrations.
Installation
Install directly from CPAN using cpanm:
cpanm Uniform::HTMX::Dancer2
Or from a checkout of this distribution:
cpanm --installdeps .
perl Makefile.PL
make
make test
make install
Synopsis
use Dancer2;
use Uniform::HTMX::Dancer2;
get '/items' => sub {
if (is_htmx) {
htmx->res_retarget('#item-list');
htmx->res_trigger('itemsLoaded', { count => 10 });
return template 'partials/items' => {}, { layout => undef };
}
return template 'full_page';
};
start;
A runnable demo app lives in examples/app.pl.
Documentation
Full method documentation lives in the module's POD:
perldoc Uniform::HTMX::Dancer2
or on MetaCPAN once released.
Testing
prove -Ilib -v t/
Contributing
See CONTRIBUTING.md.
Security
See SECURITY.md.
License
This software is Copyright (c) 2026 by Joshua S. Day.
This is free software, licensed under the MIT License.