Mojo Wonk Blog.

A semi-offical blog dedicated to the Mojolicious web framework

Day 20: Testing Dancer

Dancers and judges at a dance competition

Authors of Dancer (and other) PSGI applications are probably accustomed to testing with Plack::Test, and while that is a venerated option, it is pretty bare-bones.

During advent last year, I wrote about Test::Mojo, showing the many easy and (dare I say) fun ways that you can use it to test your Mojolicious applications. If you missed it, go check it out.

I expect there are at least a few of you out there who read that and think, "I'd love to use that, but I don't use Mojolicious!"; well, you're in luck! With just a little role to bridge the gap, you can use Test::Mojo to test your PSGI applications too!

Continue reading Day 20: Testing Dancer...

Day 19: You Only Export Twice

Container ship leaving port

With my Yancy documentation site built, with a custom landing page and a POD viewer, I just need to deploy the site. I could deploy the site using hypnotoad, Mojolicious's preforking server with hot deployment, but that would require me to have a server and keep it online. It'd be a lot better if I could just deploy a static website to Github like all the cool people are doing.

But to do that, I'd need to take my dynamic website and turn it into a static one, and that's impossible! Or is it? Why am I asking me, when I'm the one who wrote a way to do it: The Mojolicious export command.

Continue reading Day 19: You Only Export Twice...

Day 16: A pre-Christmas Diet for Mojolicious - A Children's Story

Too many nuts. I'm gonna need to slim down

You've just read How to lose Weight in the Browser and you want to know to slim down your Mojo app. Part of that process is preventing the browser from requesting files that hardly change. I spent a well-caffeinated afternoon trying to do that with Mojolicious. I've been 'round the houses, and spoiler alert I didn't find the answer until the very end, kind of like your favourite Christmas animated special with a small woodland creature narrating "The Gruffalo's HTTP header".

A Children's Story

Our beloved small woodland creature needed to display a web calendar with forest events pulled from a database. Perl could get the event data and package it as a JSON feed. Mojolicious could prepare the webpages with the correct JSON feed for each user. With some JavaScript libraries to display the web calendar, all would be well in the forest.

Everything except the JavaScript libraries are lightweight. And everyone knows a page reload goes so much faster if it doesn't have to download the JavaScript every time. Those libraries won't change for months! If only the client browser knew that it could use the file that it had downloaded last time.

The secret, of course, is to set the Cache-Control field of the HTTP header, but how?

Continue reading Day 16: A pre-Christmas Diet for Mojolicious - A Children's Story...