Dancing on Windows in Stop-Motion

In short:

Perl debugger is awesome. Komodo IDE makes it even more awesome and can play with the guts of a Plack web-app while the web-app is running on a web server. And now all of this now works on Windows too, by updating Plack and applying a tiny patch to Komodo.

Recently I wanted to do some Dancer development on Windows. For me web development means making use of some fairly powerful tools in order to remove delays and increase the turnaround speed. Sadly the state of the stack under Dancer, as well as one of these tools hampered my efforts, leading me to fix them. In following I will lay out the tools, the needed fixes and my web development workflow.

My favourite tool in the vast toolbox Perl provides is the debugger. Simply adding '-d' to the command line permits stepping through a program statement by statement, halt at any line, halt only when certain conditions are fulfilled and most importantly: It permits examination of the content of any variable at runtime by simply issueing 'x %var' and even to execute arbitrary code at runtime to change variable contents, thus allowing more complex analysis on variable states or change on the program execution flow.

In short: It allows full insight and control over any Perl program.

However, as it is merely a command-line tool, all these powers are not as speedily accessible as they could be. To find out when a certain variable is changed in a program it is necessary to reissue the x-command after every statement. In order to run a program under certain conditions it is necessary to rebuild them on the command line. This can be fairly time-consuming when trying to reproduce the circumstances of a web-application, as %ENV needs to be adapted, as well as cookies provided.

Both of these problems are solved by Komodo IDE.

It is able to start Perl programs in debug mode and wraps UI elements around the debugger controls that automate certain things. It recognizes lexically close variables, provides them in a list and automatically issues the x-command on them at each step, making it possible to literally watch the program state change while stepping through it. It also provides alternate views for global variables, special variables like the contents of @_ and most importantly watches on arbitrary Perl expressions. This makes debugging a process much faster than working with the debugger manually.

Secondly it provides a network interface that programs running in debug mode can connect to, permitting remote debugging. Adding a '-d' to the hashbang line at the start of a Perl program and having the %ENV configured to load the Komodo-provided debugging library (simply a module in the vein of Devel::Cover, NYTProf, etc.) makes it possible to have a program running on a web server in London connect to Komodo IDE on a workstation in Berlin, enabling all the aforementioned inspection and control.

For me this means that my development environment consists of any web server with a few configuration settings to tweak %ENV so the Komodo debug library is loaded. Perl programs are run in CGI mode through Plack, so I can toggle them into debug mode whenever I wish without needing to restart the server. Finally, Komodo IDE on my development platform to accept any debug requests sent by the Perl programs started by the web server. In production things are run with the FastCGI handler, but even there i can switch to the CGI handler at any time if i need to look into the guts of my application.

This is where the first problem occurred: Trying to run Dancer through Plack on Windows resulted in spurious server errors and corrupted or truncated pages when using the CGI handler. This was caused by Perl's (unneeded and pointless) newline mangling on Win32, since it meant the HTTP headers sent by Plack were wrong and binary data was corrupted. After figuring this out, a patch issued to miyagawa was integrated in less than two day and the issue fixed in Plack 0.9977.

Then the second problem became obvious: Fixing the newline mangling necessitated a change that Komodo's debugger library didn't know how to deal with, resulting in the mangling staying activated. Luckily it was easy to fix and a patch sent to Activestate, which was accepted for Komodo IDE 7. If you do not use the nightlies or alphas, you can also apply the patch yourself: https://gist.github.com/960360

Simply by making sure that you have the latest Plack and the above patch applied and you can do ridiculously fast web development with Komodo IDE, using powerful and convient debugging features. (And all of the above really applies for any framework using Plack.)

Thanks to p5p, Miyagawa and Activestate for making such tools available and even more so to the latter two for acting fast on patches.


I got the impression there's an issue with Dancer, but it appears the issue was Perl's and was fixed at the Plack level.

Is there an issue with Dancer or not?

Leave a comment

About Mithaldu

user-pic Not writing much, but often found pawing at CPAN with other #perl-cats