Showing posts from 2014

Please don't create tests like this in Perl

I just came across a test like:And of course, it was silently doing something/nothing/everything. I'd guess most experience Perl coders will notice that the eval will only run the test if the request doesn't throw an exception. Which might be kind of ok but there is no catch or check of the $@ later. If a check is added for $@ later, it will make the test pattern pretty messyPlease don't write this type of test. Please. Instead use Test::Exception and drop into a sub. Something along the lines of: This is better for a couple of reasons: test will show some output in case of exceptiontest will stop instead of just pushing on with a bunch of mostly false error (unless the test wants to this to check bad input :)test is simpler to understand (no response, give up)__END__

Dancer Sessions using PSGI

A few weeks on #dancer channel, a user was having issues using Dancer::Session::PSGI. I've never worked directly with Plack besides reading the handbook and few play apps. (well a few weeks ago, I dug into Dancer::Debug.). Using both together was an intriguing problem stuck in my mind.The person on the channel was reporting unreliable reading of session data and other odd behavior. As I started to dig into the problem, I realized that i need to create two apps, one pure Plack and one Dancer with middleware wrapper. I created a public repo on github with my test apps: Dancer and Plack session. Since, I didn't want to deal with html and wanted a bit of structure with return data, I made both test apps return JSON and have pretty simple routes I started off using the documentation from Plack::Middleware::Session to create this test app: Next I created a Test Dancer PSGI app, which basically had a way to show value and update it. Here is the non-exciting Dancer app: I updated bin/…

Template Toolkit Debugging inside of Perl Dancer

The other day someone was asking how to enable Template Toolkit debugging inside of Perl Dancer in the #dancer IRC channel, it seemed like a good time for a write up. The template engine configuration directive supports passing through various options like start_tag and stop_tag as explained in Dancer::Template::TemplateToolkit POD. And alludes to being able to pass other options. How To pass TT options like those found in Template::Constants, there must be a DEBUG section in engines -> template_toolkit, usually found in config.yml. Example Snippet Here is an example:A few notesRemove leading DEBUG_ from TT constants. The option DEBUG_PLUGINS becomes plugins.Multiple options can be separated with a comma. Example:DEBUG: "provider,plugins". Be warned, some of these options can lead to tons of information :) __END__