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

Nathan Bailey web at polynate.net
Tue Aug 22 04:52:53 BST 2017

Hi all,
  I get the sense that we are using Main.pm very poorly and a bit of
Dancer2 architectural insight would greatly improve the quality of our code.

What is the best pattern for the breakdown between perl module/Dancer2
route handler/TT file?

For example, if you have a sub-system for administrators that manages the
fees tables and reports, would you put these into separate route handlers?
ReportsHandler.pm => Route handler for reports
- Instantiates an instance of Reports.pm in it's "before" hook so we only
need to do this once (or in the module itself?)
- the 'view' and 'save' routes call the appropriate 'get' and 'set' methods
for that table in Reports.pm

and a separate handler for Fees, with an overarching Main.pm route handler
that largely deals with mainstream userspace routes (any significant user
workflows get their own router handler module like ReportsHandler and

Ideally, I'd like all our code in the perl modules, with the route handler
doing nothing but dispatch (with error handling) and the TT doing basic
interface presentation.
But at the moment, each route handler is 20-30 lines long - I think they
should be ~5 lines long or less.

An exemplar Main.pm + TT file would be very helpful!

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

More information about the dancer-users mailing list