[dancer-users] Medium-Scale Dancer series updated

Warren Young wyml at etr-usa.com
Tue Dec 29 16:56:55 GMT 2015


On Dec 28, 2015, at 9:38 AM, William Carr <bill at bottlenose-wine.com> wrote:
> 
> how may I reduce the following without repeating myself?
> 
> MyApp::Module1.pm
> use Dancer2;
> use Dancer2 appname => ‘myapp’;

You only need the second “use” call.  Setting the appname property is not a separate thing from importing Dancer2.

> use Dancer2::Plugin::Ajax;
> 
> MyApp::Module2.pm
> use Dancer2;
> use Dancer2 appname => ‘myapp’;
> use Dancer2::Plugin::Ajax;

Move “use Dancer2::Plugin::Ajax;” to lib/App.pm, before the “use” calls to your other app modules.  Then anything that module exports to the global namespace will be available to those modules.

By carefully ordering your “use” statements, you can usually find a way to mention any given module only once.

There are even cases where doing so is *required*.  For example, if you say something like:

  use List::Util qw(min max);

from two different modules, and “use” both of those from a third module, you’ll get a complaint about redefined min/max.  The fix is to move that “use” call to a single central location that everyone that needs those utility functions depends on.


More information about the dancer-users mailing list