Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Oh holy monks,

I have a question regarding Dancer2 and hooks. I would like use a specific hook from Dancer::Core::Error. It's the hook after_error. And what I am trying to do is have this hook applied to all errors in my application. But I want it applied from a module that I use. In other words, if the someone uses the module, then the hook gets applied to any errors.

Anyway, I can't seem to "export" the hook from the module to the application. I read the docs, but I am still can't get it to work. Any ideas?

Replies are listed 'Best First'.
Re: Dancer2 hook
by jcb (Parson) on Aug 12, 2019 at 06:35 UTC

    We need a Short, Self-Contained, Correct Example here. What is the code you are using?

    I realize you posted this anonymously, so you will need to post the code that is not working in a reply. Maybe someone will be able to help you.

      Thanks for the reply. The hook works fine. But it's the implementation that I am having trouble with. By implementation, I mean, putting the hook in a module that I can then use when I want the hook to be applied to errors.

      So the code part is real simple:

      hook after_error => sub { my $response = shift; };
      The problem is that this code is not catching errors from the application that uses the module. Get it?
        That is not demonstrative self contained code
Re: Dancer2 hook
by Anonymous Monk on Aug 12, 2019 at 09:37 UTC
      It doesn't work when I put it in a module that gets used. Do you understand? The hook works, yes. But it's the implementation that I am having trouble with.