<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div>It seems that the new way to do is to create a Dancer::Plugin that add a hooks. Then use it !<br></div><div><br></div><div><br></div><hr id="zwchr"><div style="color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Celogeek" &lt;me@celogeek.com&gt;<br><b>À: </b>"Perl Dancer users mailing list" &lt;dancer-users@dancer.pm&gt;<br><b>Envoyé: </b>Vendredi 28 Décembre 2012 20:33:02<br><b>Objet: </b>Re: [dancer-users] Route dispatch<br><div><br></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div>Um, seems doesn't work.<br></div><div><br></div><div><br></div><div>How can I add a "before hooks" in a Moo::Role ?<br></div><div><br></div><div><br></div><hr id="zwchr"><div style="color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Celogeek" &lt;me@celogeek.com&gt;<br><b>À: </b>"Perl Dancer users mailing list" &lt;dancer-users@dancer.pm&gt;<br><b>Envoyé: </b>Vendredi 28 Décembre 2012 20:23:36<br><b>Objet: </b>Re: [dancer-users] Route dispatch<br><div><br></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div>I'm trying right now on my apps (similar config)<br></div><div><br></div><div><br></div><hr id="zwchr"><div style="color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Alex C" &lt;calyx238@gmail.com&gt;<br><b>À: </b>"Perl Dancer users mailing list" &lt;dancer-users@dancer.pm&gt;<br><b>Envoyé: </b>Vendredi 28 Décembre 2012 19:48:33<br><b>Objet: </b>Re: [dancer-users] Route dispatch<br><div><br></div><div>Like this?</div><div><br></div><div>package MyApp::Role::Hooks;</div><div>hook before { var foo =&gt; 'bar' };&nbsp;</div><div><br></div><div>package MyApp::Routes::RouteA;</div><div>with 'MyApp::Role::Hooks';</div>
<div>get '/A' =&gt; sub { return vars-&gt;{foo} };</div><div><br></div><div>package MyApp::Routes::RouteB;</div><div>with 'MyApp::Role::Hooks';</div><div>get '/B' =&gt; sub { return vars-&gt;{foo} };</div>
<div><br></div><div>I hope that works because it looks elegant.</div><br><div class="gmail_quote">On 28 December 2012 18:35, Celogeek <span dir="ltr">&lt;<a href="mailto:me@celogeek.com" target="_blank">me@celogeek.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>Or we can push in a role the common part only between each module.<br>
</div><div><br></div><div>For example, in my case, I have a common "before" hooks which initialize the redis connexion. So I can put this in a role, and that it.<br></div><div><br></div><hr><div style="font-size:12pt;font-style:normal;font-family:Helvetica,Arial,sans-serif;text-decoration:none;font-weight:normal">
<b>De: </b>"Alex C" &lt;<a href="mailto:calyx238@gmail.com" target="_blank">calyx238@gmail.com</a>&gt;<br><b>À: </b>"Perl Dancer users mailing list" &lt;<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a>&gt;<br>
<b>Envoyé: </b>Vendredi 28 Décembre 2012 19:28:41<br><b>Objet: </b>Re: [dancer-users] Route dispatch<br><div><br></div><div>In my case, that would mean consuming 20+ roles into the same package, and I lose the benefit of package-scoping.</div>
<div><br></div><div>I think there are many people who have spread their Dancer 1 routes across many packages.&nbsp;I would like to know the recommended best practice for migrating such apps to D2.</div><br><div class="gmail_quote">
On 28 December 2012 17:58, Celogeek <span dir="ltr">&lt;<a href="mailto:me@celogeek.com" target="_blank">me@celogeek.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div><br>solution is to have only one Apps.<br></div><div><br></div><div>And transform each submodule into a Moo::Role.<br></div><div><br></div>
<div>may be<br></div><div><br></div><hr><div style="font-size:12pt;font-style:normal;font-family:Helvetica,Arial,sans-serif;text-decoration:none;font-weight:normal"><b>De: </b>"Alex C" &lt;<a href="mailto:calyx238@gmail.com" target="_blank">calyx238@gmail.com</a>&gt;<br>
 <b>À: </b>"Perl Dancer users mailing list" &lt;<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a>&gt;<br><b>Envoyé: </b>Vendredi 28 Décembre 2012 18:46:16<br><b>Objet: </b>Re: [dancer-users] Route dispatch<br>
<div><br></div>Now I understand what you mean. I also separate my routes into differnet modules, like this:<div><br></div><div><div># in MyApp::Controller</div><div><br></div><div>hook before {&nbsp; var foo =&gt; 'bar' &nbsp;};</div>
<div><br></div><div>get '/' =&gt; \&amp;MyApp::Controller::Root;</div><div><br></div><div># MyApp::Controller::Root</div><div><br></div><div>get '/' =&gt; sub {</div><div>&nbsp; &nbsp; my $var = vars-&gt;{foo};</div>
<div>&nbsp; &nbsp; ...</div><div>};</div><div><br></div><div>I have yet to play with Dancer 2 but I expect I will have the same problems as you!</div></div><div><br></div><div>I hope there is an easy solution to this or I cannot migrate to Dancer 2.</div>
<div><br></div><br><div class="gmail_quote">On 28 December 2012 17:37, Celogeek <span dir="ltr">&lt;<a href="mailto:me@celogeek.com" target="_blank">me@celogeek.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>this doesn't work with Dancer2 due to context.<br></div><div>the hook is for route in App::Main<br></div><div>so it doesn't fire with the App::Root routes<br>
</div><div><br></div><div><br></div><hr><div style="font-size:12pt;font-style:normal;font-family:Helvetica,Arial,sans-serif;text-decoration:none;font-weight:normal"><b>De: </b>"Alex C" &lt;<a href="mailto:calyx238@gmail.com" target="_blank">calyx238@gmail.com</a>&gt;<br>
 <b>À: </b>"Perl Dancer users mailing list" &lt;<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a>&gt;<br><b>Envoyé: </b>Vendredi 28 Décembre 2012 18:33:57<br><b>Objet: </b>Re: [dancer-users] Route dispatch<br>
<div><br></div>Sorry I have no experience with Dancer 2 or multiple contexts.<div><br></div><div>This works on Dancer 1, if it is any help:</div><div><br></div><div><div>#!/usr/bin/env perl</div><div><br></div><div>use Dancer;</div>
<div><br></div><div>{</div><div>&nbsp; &nbsp; package App::Main;</div><div>&nbsp; &nbsp; use Dancer ':syntax';</div><div>&nbsp; &nbsp; hook before =&gt; sub { var xxx =&gt; "test" };</div><div>&nbsp; &nbsp; 1;</div><div>}</div><div><br></div><div>
{</div><div>&nbsp; &nbsp; package App::Root;</div><div>&nbsp; &nbsp; use Dancer ':syntax';</div><div>&nbsp; &nbsp; get "/" =&gt; sub { return vars-&gt;{xxx} };</div><div>&nbsp; &nbsp; 1;</div><div>}</div><div><br></div><div>start;</div><div><br>
</div><div>Good luck..</div><br><div class="gmail_quote">On 28 December 2012 17:25, Celogeek <span dir="ltr">&lt;<a href="mailto:me@celogeek.com" target="_blank">me@celogeek.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>it's just a not working short example :)<br></div><div><br></div><div>but Dancer use context, so in my App::Main I have a before hooks that only apply to the route present in App::Main.<br>
</div><div><br></div><div>So my App::Root doesn't have it. And it was the case in Dancer 1.<br></div><div><br></div><div>I need to fully change my apps to make it work with Dancer2<br></div><div><br></div><hr><div style="font-size:12pt;font-style:normal;font-family:Helvetica,Arial,sans-serif;text-decoration:none;font-weight:normal">
<b>De: </b>"Alex C" &lt;<a href="mailto:calyx238@gmail.com" target="_blank">calyx238@gmail.com</a>&gt;<br><b>À: </b>"Perl Dancer users mailing list" &lt;<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a>&gt;<br>
 <b>Envoyé: </b>Vendredi 28 Décembre 2012 18:18:12<br><b>Objet: </b>Re: [dancer-users] Route dispatch<br><div><br></div>Yuo are missing the semicolons after your sub declarations. Try it agian ;)<br><div><br></div><div class="gmail_quote">
On 28 December 2012 15:57, Celogeek <span dir="ltr">&lt;<a href="mailto:me@celogeek.com" target="_blank">me@celogeek.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>Can I dispatch my root thought multiple module ?<br></div><div><br></div><div>I have in App::Main : <br></div><div><br></div><div>hook before =&gt; sub {<br>
</div><div>var xxx =&gt; "test";<br></div><div>}<br></div><div><br></div><div>and in App::Root;<br></div><div><br></div><div>get "/" =&gt; sub {<br></div><div>&nbsp;return vars-&gt;{xxx}<br></div><div>}<br>
</div><div><br></div><div>But vars seems empty.<br></div><div><br></div><div>In my bin/app.psgi I have :<br></div><div><br></div><div>use Dancer;<br></div><div>use App::Main;<br></div><div>use App::Root;<br></div><div><br>
</div><div>start;<br></div><div><br></div><div><br></div></div></div><br>_______________________________________________<br> dancer-users mailing list<br> <a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
 <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br> <br></blockquote></div><br> <br>_______________________________________________<br>
 dancer-users mailing list<br><a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br><a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</div><div><br></div></div></div><br>_______________________________________________<br> dancer-users mailing list<br> <a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br> <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
 <br></blockquote></div><br></div><br>_______________________________________________<br>dancer-users mailing list<br><a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br><a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</div><div><br></div></div></div><br>_______________________________________________<br> dancer-users mailing list<br> <a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br> <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
 <br></blockquote></div><br> <br>_______________________________________________<br>dancer-users mailing list<br><a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br><a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</div><div><br></div></div></div><br>_______________________________________________<br> dancer-users mailing list<br> <a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br> <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
 <br></blockquote></div><br> <br>_______________________________________________<br>dancer-users mailing list<br><a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br><a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</div><div><br></div></div></div><br>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>dancer-users mailing list<br>dancer-users@dancer.pm<br>http://lists.preshweb.co.uk/mailman/listinfo/dancer-users<br></div><div><br></div></div><br>_______________________________________________<br>dancer-users mailing list<br>dancer-users@dancer.pm<br>http://lists.preshweb.co.uk/mailman/listinfo/dancer-users<br></div><div><br></div></div><br>_______________________________________________<br>dancer-users mailing list<br>dancer-users@dancer.pm<br>http://lists.preshweb.co.uk/mailman/listinfo/dancer-users<br></div><div><br></div></div></body></html>