Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Constructive thoughts on Dancer2 v Mojolicious

by perlfan (Vicar)
on Jun 04, 2020 at 02:59 UTC ( #11117680=note: print w/replies, xml ) Need Help??

in reply to Constructive thoughts on Dancer2 v Mojolicious

It's dealer choice and YMMV, etc. But I will point out that the "hello world" of Dancer2:
#!/usr/bin/env perl use Dancer2; get '/hello/:name' => sub { return "Why, hello there " . route_parameters->get('name'); }; dance;
and that of that of mojo are equally dead simple:
#!/usr/bin/env perl use Mojolicious::Lite; get '/' => {text => 'I <3 Mojolicious!'}; app->start;

Was moving from CGI::Application/::Dispatch (and there from CGI), I tried Dancer2 first and stopped there. I just needed something and it fit the bill. I do like that the route handler in Dancer2 is a subref rather than a hash ref, now looking more closely at the two. What did Dancer2 give me that I wanted so badly? Simple access to routing. As you can see, had I looked at Mojo first I may very well have chosen that.

Why did I choose CGI::Application over CGI? Because it was not overcomplicated and ridiculous like some of the other frameworks I had to choose from when I was looking. It was also extensible. But it didn't have routes (yes I used CGI::Application::Dispatch for a while happily), and when I learned what routes were, I knew that was the way to go.

Besides routes, it provided a simple introduction to PSGI. And I really liked the idea of never having to configure httpd again. This meant, control over where, when, and how I deployed the application. Both Dancer2 and Mojo provide this. Mojo does seem more suited for very precised composition of your application. If I needed all of that, I might (and may very well) give it a shot.

Here's my advice: no matter what framework you choose between the two, it'll be way better than what our options were in the first part of this century; the trick is to maintain clean separation between your business logic and controllers so that you can easily switch from Dancer2 to Mojo or vice versa (or the next leap in framework evolution) without much effort. By effort, I mean you should not have much if any framework specific bits buried in what you would classify as the essence of your application. This included: templates and other assets, business logic, authentication, database access, and all the stuff you do with it.

Replies are listed 'Best First'.
Re^2: Constructive thoughts on Dancer2 v Mojolicious
by davido (Cardinal) on Jun 04, 2020 at 07:07 UTC

    Your two examples are not equivalent. For the Mojolicious app to do the same thing you're doing in the Dancer 2 app, it would look like this:

    #!/usr/bin/env perl use Mojolicious::Lite -signatures; get '/hello/:name' => sub ($c) { $c->render(text => 'Why, hello there ' . $c->param('name')); }; app->start;

    Spruced up to provide the same functionality as the Dancer 2 app, the code looks substantially similar. The two frameworks do have many useful differences. But at the heart of it they're both lightweight web frameworks, and both are quite capable. I prefer Mojolicious too, but some of that is due to familiarity and having used it in production a number of times. I've heard people whine about the Mojolicious framework coming with "too much stuff." I disagree with this premise; it comes complete, and useful, and still in a tarball under 800KB.


      I just copied from both sites directly. Also, you're free to disagree obviously. I just wanted to share my experience. I use Dancer2, so I have decided for myself. Sounds like you have also. One thing that seems to be a common theme is that poeple tend to stop at the one they try first. I think that's an important and interesting effect. That tells you for many, they are equivalent in terms of meeting needs - i.e., "quick start".

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11117680]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2021-04-22 02:55 GMT
Find Nodes?
    Voting Booth?

    No recent polls found