At the last Biblibre‘s CodeRun (beginning of May 2010), i wrote the first lines of a CGI wrapper for Dancer. The initial goal was to be able run legacy CGI.pm scripts written with the OO style on the top of Dancer
- with a minimal amount of changes (or even better: no change at all)
- every required changes must keep CGI compatibility.
- add the ability to share the bytecoding and the values of the loaded modules between http requests (as mod_perl does) to reduce time response and load average.
- make the CGI applications easier to debug (using dancer standalone server, the debug console and warning catch)
The proof of concept is to make Koha ILS run on top of Dancer. I wrote a kohadance.pl script for that.
I spent some time to work on it since, wrote some test files to make sure that i’m able to use %ENV, return correct http responses, correctly provide access to the http get and post parameters, correctly transmit the $query->header settings to Dancer, handle cookies, … . All the test suite runs successfully.
The results seems to be better than expected:
- the only code i had to change in koha is to replace the exit call by an safe_exit subroutine
sub psgi_env { any { /^psgi\./ } keys %ENV }
sub safe_exit {
if ( psgi_env ) { die 'psgi:exit' }
else { exit }
}
and make the CGI wrapper see the psgi:exit die as a normal termination. If anyone have an idea to trap ‘exit’ as it in the code: i’ll be very pleased to know.
- I’m now able to mix CGI.pm and Dancer code. So if you choose to break the CGI compatibility, you can port your script to a Dancer app step by step.
But there are still bugs! Speaking about koha: i can now log in and out the intranet, navigate on koha pages without experimenting some weird error or crash but (lot of)? stuff doesn’t work (for example: the main search doesn’t work). If you want to try yourself:
* git clone http://github.com/sukria/Dancer.git and git://github.com/eiro/Dancer-CGI-wrapper.git
* go to your koha root
* apply Dancer-CGI-wrapper/koha/0001-add-PSGI-ability.patch
* export KOHA_CONF
* run perl Dancer-CGI-wrapper/koha/kohadance.pl
* connect to http://localhost:3000 and http://localhost:3000/opac with your browser
* enjoy the kohadance « no search » opac
Next steps are:
* use koha to go on debugging by identifying malfunctions, write tests and make them work
* make the package more CPAN ready. It’s already packaged thanks to module-starter but it is not a real Dancer plugin yet (bad namespaces, no use of Dancer::Plugin mechanics, no real documentation)
Help or feedback are welcome. please fork me on github
.