<div dir="ltr"><div>Hello,<br><br></div><div>I'm having some issues with the hooks, because it seems that runs more than one time each time that I'm calling from my Dancer2 application.<br><br></div><div>I have this plugin:<br><br>--<br>package Dancer2::Plugin::MyPluginTest;<br>use Dancer2::Plugin;<br><br>register_hook 'my_new_hook';<br><br>register new_function => sub {<br> execute_hook 'my_new_hook';<br>}; <br><br>register_plugin;<br>--<br><br></div><div>And I have this Dancer test application:<br><br>--<br>use strict;<br>use warnings;<br><br>use Test::More;<br>use Plack::Test;<br>use HTTP::Request::Common;<br>{<br>    package MyTestApp;<br>    use Dancer2;<br>    use Dancer2::Plugin::MyPluginTest;<br><br>    my $var = 0;<br> <br>    get '/' => sub {<br>      new_function;<br>      $var;<br>    };<br><br>    hook 'my_new_hook' => sub {<br>      $var++;<br>      debug "Executing hook -  $var";<br>    };<br>};<br><br>my $test = Plack::Test->create( MyTestApp->to_app );<br>my $res  = $test->request( GET '/' );<br>is( $res->content, '1', 'Var is 1 after one call on  /' );<br>done_testing();<br>--<br><br><br></div><div>When I run the test, the hook it's executed twice.<br><br>--<br>[MyTestApp:6554] debug @2015-09-17 08:26:33> Executing hook -  1 in <a href="http://plugin.pl">plugin.pl</a> l. 21<br>[MyTestApp:6554] debug @2015-09-17 08:26:33> Executing hook -  2 in <a href="http://plugin.pl">plugin.pl</a> l. 21<br><br>not ok 1 - Var is 1 after one call on  /<br>1..1<br><br>#   Failed test 'Var is 1 after one call on  /'<br>#   at <a href="http://plugin.pl">plugin.pl</a> line 29.<br>#          got: '2'<br>#     expected: '1'<br># Looks like you failed 1 test of 1.<br>Dubious, test returned 1 (wstat 256, 0x100)<br>Failed 1/1 subtests <br>--<br><br></div><div>I just isolate this example of a plugin that I'm working on, but it had the same problem (but execute the hooks three times).<br><br></div><div>Any advice?<br></div><div></div><div><div><div><div><div><br></div><div>Thanks in advance.<br></div><div><br>-- <br><div class="gmail_signature"><div dir="ltr">____________________________<br>Rubén Darío Amórtegui Medina<br>MCE - Ingeniero de Sistemas</div></div>
</div></div></div></div></div></div>