[dancer-users] How do you minimise code in Main.pm? (looking for good Dancer2 patterns)

Scott H scott.harpster at gmail.com
Wed Aug 23 15:33:16 BST 2017


So I think the advent reply was pretty good, I wish that was in the docs as
a way to do it. I started with Dancer 1 a few years ago and the tutorials
and cookbook were a good start but I ran into your problem as well. I had
to find a way to split up my code so my main app.pm was not just loaded
with stuff.

I took more of a MVC approach and made in my libs  lib/models and
lib/controllers folders and in my controllers put my routes for different
things so I would have authentication.pm, dashboard.pm, etc..

on my models stuff I will have more of a lib perl modules scenario where my
libraries and their functions exist. Such as Users.pm, Logging.pm etc...

In my main app.pm I will call
use controllers::dashboard;
use controllers::authentication;

my controllers will then use the model libs with use model::libname and
then pull any functions they need out to perform the controlling of the
view and then like a route load the view at the end.

It works good enough for me as its laid out nice. I would consider the
advent way by loading the functions directly to the route. Hopefully this
gives you another idea of how to lay it out.

-Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20170823/962cee72/attachment.html>


More information about the dancer-users mailing list