[dancer-users] Controller-hierarchy, best practise?

Jochen Lutz jlu at gmx.de
Thu Aug 6 22:30:26 BST 2015


Am 06.08.15 um 13:08 schrieb Henk van Tijen ||:
[…]

> To be more specific, I intend to structure my app along route definitions like:
>
> use MyDancer::Controller::FoobarController;
> get ‘/Foobar/jump’ => sub {
>      my $fb = FoobarController->new;
>      $fb->jump;
> };
>
> Is this okay or ‘ugh’  ?

With this, you'd create a new instance of 
MyDancer::Controller::FoobarController for *every* request, this is 
definitively 'ugh'.

If your controller does not hold any state, you can skip the whole OO 
thing, and just call a sub in another package:

use MyDancer::Controller::FoobarController;
get '/Foobar/jump' => sub {
     MyDancer::Controller::FoobarController::jump();
};


   Jochen


More information about the dancer-users mailing list