<div dir="ltr">Hi David<div><br></div><div>Check this out:</div><div><br></div><div><a href="http://advent.perldancer.org/2014/9">http://advent.perldancer.org/2014/9</a><br></div><div><br></div><div>I suspect it doesn't directly address your question since it's Dancer2 rather than Dancer, but seeing as you're using Plack your already half way there:)</div><div><br></div><div>cheers</div><div><br></div><div>Andrew</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 23, 2015 at 5:15 AM, Warren Young <span dir="ltr"><<a href="mailto:wyml@etr-usa.com" target="_blank">wyml@etr-usa.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Apr 22, 2015, at 6:42 PM, David H <<a href="mailto:untg99@gmail.com">untg99@gmail.com</a>> wrote:<br>
><br>
> What is the best way to separate these code bases into separate files?<br>
<br>
</span>Dancer makes this really easy.  The ‘dancer’ generator already created a “lib” directory for you and added it to the module path.  By default, that lib directory only holds <a href="http://myapp.pm" target="_blank">myapp.pm</a>, but there’s nothing preventing you from adding more files to that tree.<br>
<br>
For my app (which has about 5x the amount of Perl code you’re talking about) I chose to keep lib/<a href="http://myapp.pm" target="_blank">myapp.pm</a> as the “Dancer core” module, containing little more than the route handlers.<br>
<br>
Those route handlers are mostly one-liners that call off into one of the other modules which live in lib/myapp/*.pm.<br>
<br>
At the top of lib/<a href="http://myapp.pm" target="_blank">myapp.pm</a>, you see a bunch of stuff like:<br>
<br>
    use myapp::SomeComponent;<br>
    use myapp::AnotherComponent;<br>
    use etc…<br>
<br>
Those modules then export classes, functions, and globals in the normal way, for use by the Dancer core module.<br>
<br>
Sometimes I write these modules to require fully-qualified names rather than export function to global level.  A route handler thus might look like this:<br>
<br>
    prefix '/api' => sub {<br>
        prefix '/sc' => {<br>
            get ‘foo’ => sub {<br>
                return myapp::SomeComponent::GetFoo(param ‘bar’);<br>
            };<br>
        };<br>
    };<br>
<br>
If you didn’t know you could nest things with “prefix” this way, aren’t you glad you know now? :)<br>
<br>
As you can see, I’m mirroring my Perl module component hierarchy with my URL hierarchy: /api/sc/* is handled by myapp::SomeComponent, etc.<br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">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>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Andrew Solomon<div><br></div><div>Mentor@Geekuni <a href="http://geekuni.com/" target="_blank">http://geekuni.com/</a></div><div><a href="http://www.linkedin.com/in/asolomon" target="_blank">http://www.linkedin.com/in/asolomon</a><br></div></div></div>
</div>