Hi,
I have this legacy application (~40k LOC) which I want to use as Plack application, mainly because:
- debugging on Apache2 / mod_perl2 is... let's say hard and inconvenient and with Plack I can use awesome StackTrace and REPL middlewares,
- I don't need any of Apache features in development,
- we've recently had some problems with mod_perl on Windows and want to investigate Apache/mod_perl alternatives such as making our app compatible with PSGI and changing the server,
- I really like an idea of programming to an interface like PSGI instead of concrete server implementation.
The application isn't that much tied to mod_perl's internals (i.e. we don't use any of mod_perl's modules directly in code, rather than we use CGI.pm), here are relevant fragment of httpd.conf:
<LocationMatch "/cgi-bin">
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
and
startup.pl (don't ask about each line, our admin configures httpd's config):
use MyLib::Configuration;
use ModPerl::MethodLookup;
ModPerl::MethodLookup::preload_all_modules( );
use Apache2::RequestRec ( );
use Apache2::RequestIO ( );
use Apache2::RequestUtil ( );
use Apache2::ServerUtil ( );
use Apache2::Connection ( );
use ModPerl::Registry ( );
use Apache2::Const -compile => ':common';
use APR::Const -compile => ':common';
So far I've managed to run the application using Plack::App::CGIBin, other solutions as CGI::PSGI could be harder to achieve because printing headers and body parts is done in various places in code which seems to be a problem. See my app.psgi below:
use constant LP_PATH => '/path/to/app';
my $lp_path = sub {
return join('/', LP_PATH, @_);
};
mount '/cgi-bin' => Plack::App::CGIBin->new(root => $lp_path->('cgi-bin'))->to_app;
mount '/' => Plack::App::File->new(root => $lp_path->('htdocs'))->to_app;
Unfortunately, I've got two problems:
1. UTF-8 handling is as mess (in our app of course). Since Apache was run with `AddDefaultCharset UTF-8`, it was a common practice in our app to return UTF-8 string (or use application/json; charset=UTF-8) as-is and treat everything coming from app as UTF-8, which is different than required by PSGI specs (no wide characters allowed). Can I get single entry / exit point in Plack / Plack::App::CGIBin to apply encode_utf8 / decode_utf8? Or how else could I deal with this problem? Is there a generic approach to treat everything coming from / to a Plack app as UTF-8 strings and treat them properly? I'd rather not mess with application code directly...
2.
http://plackperl.org/#servers lists all available servers, but I can't find any information about support for MS Windows systems. Which of those servers are best for this OS? Are Plack::Handler::Apache2 or mod_psgi only [production-ready] options?
I'd be glad if you could help me with this and show me the easiest way to migrate legacy CGI.pm / mod_perl app to Plack / PSGI.
Regards,
Grzegorz