|Think about Loose Coupling|
Plack::App::FakeApache::Request & Masonby cLive ;-) (Parson)
|on Apr 24, 2013 at 15:55 UTC||Need Help??|
cLive ;-) has asked for the
wisdom of the Perl Monks concerning the following question:
I'm trying to wrap a legacy mod_perl mason app in Plack. I started off easily enough, using Plack::App::FakeApache::Request and looking at request methods not in that module that needed adding, but now I'm hitting a slight roadbloak.
I don't want to have to edit any standard modules if I can avoid it, but the change I would need to make isn't easily overloaded.
The BEGIN block of HTML::Mason::ApacheHandler checks whether the request object ISA Apache2::RequestRec object or not. It's actually a Plack::App::FakeApache::Request so the Mason handler dies with the message:
The 'apache_req' parameter ("Plack::App::FakeApache::Request=HASH(0xa2ffd60)") to HTML::Mason::Request::ApacheHandler->new() was not a 'Apache2::RequestRec' (it is a Plack::App::FakeApache::Request=HASH(0xa2ffd60))
I was thinking of reblessing it before it hits Mason, but I can see that coming back to bite me.
Is there a better way to approach this? Should I give up on the Fake Request and just re-implement the Mason direct through Plack, using HTML::Mason::PlackHandler (say), and that the app rewrite will be less work than trying to get the existing app wrapped in the fake Apache handler?
Edit: After a bit more digging, I think I found a solution. Looks like the module I needed to look at was Plack::Request and to then tweak the Mason code, rather than trying to fake everything through the Apache handler.