Mojolicious is a fun module/framework/thing for me. How do I love Mojolicious? Let me count the ways (sorry Shakespeare):
- Mojo has ridiculously few dependencies, especially when compared to other web frameworks
- Mojo brings web servers (morbo and hypnotoad) with it
- Mojo does MVC, or doesn’t do MVC, whatever I want to do
- Mojo has templates, and they’re outstanding
- Mojo does routes very simply, which is badass
- I can write an entire web application in only one file (though it could get big and may not be advisable) using Mojolicious::Lite
- Mojo has helpers which are actually helpful
- Mojo is crazy fast, so fast that if there is a performance problem I’m pretty sure it’s me
- The more I use Mojo, the more I find cool stuff that it can do
The Pre-Code Talk
So what I’m doing today is pretty simple. I’m going to make a web form which takes two inputs: hash1 and hash2. The user inputs two hashes in the format:
This should then output one hash with four keys (key1, key2, key3, and key4), with two of the keys having scalar values and the other two being array references.
It’s a pretty simple exercise, but I’m going to show you how to use Mojo a little bit more. Features of Mojo we’ll use are:
- Mojo routing for GET and POST
- We’re going to use the Mojolicious plugin Mojolicious::Plugin::Validator (see Input::Validator for more details on using this)
- We’re going to use a layout for the template
- We’re going to use the dumper within the Mojolicious::Plugin::DefaultHelpers plugin
So here we have all of the basics of a web application:
- Form input
- Form field validation
- Output of processed form input
Again, note that the templates are below the
__DATA__ token, and then see how we have the app showing error output per-field.
I know this isn’t a terribly complex web app, but I think it’s a useful demonstration of
Mojolicious::Lite for simple web applications.
One thought on “Gist of the Day: Mojo Merging Hashes”
Thanks! I love Mojolicious too. Keep up this gists of the day, please!!