in reply to Re^2: Dancer2 hook
in thread Dancer2 hook

That is not demonstrative self contained code

Replies are listed 'Best First'.
Re^4: Dancer2 hook
by Anonymous Monk on Aug 13, 2019 at 00:51 UTC
    Correct. Here you go:
    package Dancer2::Plugin::TestHook use Dancer2; use Dancer2::Core::Error; hook after_error => sub { my $content = shift; $content->{content} .= "hello world"; } 1;
    This hook works fine, but it doesn't get called when I use the module (Dancer::Plugin::TestHook) somewhere else. That's the problem.

      Still incomplete.

      Where is the app that triggers an error?

        package Howdy; use Dancer2; use Dancer2::Plugin::TestHook; get '/' => sub { template 'index' => { 'title' => 'Howdy' }; }; get '/hello' => sub { die "We are out of ponies\n"; return "Welcome to Dancer2 Web Application"; }; true;