http://qs321.pair.com?node_id=1226747


in reply to Multiuser app with SQLite, Dancer2 and CLI

Hi, I usually separate out the Dancer route handling code and the actual do-the-work code into separate modules precisely so I can access the latter outside the framework.

Sometimes there are three layers because the Dancer route-handling code that makes use of the true back end libraries (that you want to consume separately) gets so voluminous that I want to keep it out of the actual route handling classes. In that case I wind up with a somewhat parallel structure for the first two layers, like maybe:

lib/ +++ Routes.pm +++ Route/ +++++++++ Account.pm # handles routing for /account +++++++++ Account/ +++++++++++++++++ User.pm +++ API/ +++++++ Account.pm # does stuff with an account +++++++ Account/ +++++++++++++++ User.pm +++ Config.pm +++ DB.pm # provides access to the database +++ LowLevelBizStuff.pm
etc., where a cron script or whatever can access the database outside the Dancer framework.

On the other hand, if your database needs are simple, you can use Dancer2::Plugin::Database to greatly simplify your web app code, but in that case you'd have to write other code to get at your data off line. All depends how complex your data is, how complex your app is, and how complex the actions your want to take on the data off line are.

Hope this helps!


The way forward always starts with a minimal test.