Quoting Thomas Klausner <[EMAIL PROTECTED]>: > Hi! > > Is it possible and advisable to write the complex part of an > application > (the Controller, if you like) in mod_perl2 and use PHP as a frontend > (or > View) ?
It should be possible, perhaps by calling php from apache subrequests in the mod_perl code, but it won't be efficient, and doesn't sound very pratical. As an alternative, you might be able to use SOAP/RPC requests in the PHP code to offload the backend work to a mod_perl SOAP/RPC server. Again, not very efficient or practical. > While I personally prefere Template::Toolkit as a presentation > language, the > project I'm currently getting involved in has quite a lot of > PHP-people and > not that many (read: me) Perl people. > So what I thought is: use Perl to implement the rather complex > business > logic, and PHP for rendering (and getting form input to the > 'backend'). If they are keen to learn new stuff (perl) provided the learning curve isn't too steep, then using HTML::Mason or embperl instead of TT might be an easier sell as the concept and syntax is similar to php. I've never used TT (and I'm certainly not knocking it), but from what I've seen it's a whole 'nother language (albeit small) to learn. You'll want to do some research on these before recommending them for a project, of course. > But: can I create a datastructure in Perl (in an ResponseHandler) and > pass > it on to PHP running also as an ResponseHandler, but afterwards. > Would I > need to stuff data in ENV? Can I pass complex data structures around? > Do I > have to serialise (to yaml/xml) between Perl and PHP? In a previous project that involved both perl and php components, I was successful in sharing nested data structures between the languages, essentially by telling perl how to import structures from php include files. In my case, we had legacy php pages that we were replacing with HTML::Mason components, but needed to share data structures (menu items and such) in the meantime. Here's a quick synopsis. Create a file 'data.dat' like: <code> <?php $data = array( "Node 1" => array( array("Node 1.1" => "foo"), array("Node 1.2" => "bar"), ), "Node 2" => array( array("Node 2.1" => "baz"), ), ); ?> </code> Now, from a php script, do: <code> include("data.dat") </code> And from a perl script, do: <code> sub array {return [EMAIL PROTECTED] } my $data; open FILE, "<data.dat"; my $script; {local $/; $script = <FILE>; } close FILE; $script =~ s/^(?:<\?php|\?>)//msg; eval $script; </code> You should be able to do nested data structures without a problem. You can't marshall objects or references using this method. If simple, nested structures will suit your needs, it should be easy enough to create a data marshalling class in perl to create PHP structures from perl structures. EDIT: As an afterthought, I checked CPAN to see if there were modules that did something similar, and found PHP::Include and PHP::Serialization. > Or is this a bad idea altogether and I should use a different > approach (Like > forcing everyone to read the Badger)? If you are in a position of influence with a potential opportunity to introduce mod_perl to PHP developers, then do the world a favour and take that challenge. :) Tony