Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Folks
Recently I read an article about building Web sites with mod_perl. In the doc, I could see the author saying that the app and proxys are running in different machines and they communicate thru http. Can any one explain me the details about how the interaction between Model and View is done in perl with some examples? Based on the example, if the app server is running in a different machine how the controller is instantiating a Model object? I apologize for asking a stupid question

Replies are listed 'Best First'.
Re: mod_perl and MVC
by tachyon (Chancellor) on Apr 14, 2002 at 16:36 UTC

    For a code example of how you do this see MP3 server with IO::Socket. HTTP is a request response protocol where a client sends requests to a server that then produces a response. Essentially you create a Socket connection (using IO::Socket is easiest) to communicate across the network. Once the socket is created you talk across it using HTTP and tcp/ip. There are a number of modules that implement HTTP client/server functionality on CPAN, see HTTP:: for details. Although many think of WWW and HTTP together this need not be the case.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: mod_perl and MVC
by perrin (Chancellor) on Apr 14, 2002 at 19:53 UTC
    I'm the author of that article. Glad to hear it got you thinking about MVC and mod_perl.

    It sounds to me like you're getting confused between two different concepts. The proxy servers have nothing to do with MVC per se. They are there to help performance by handling requests for static files and by caching any pages that the app servers say can be cached (by looking at the Expires headers). They also handle sending out the result to the client, which keeps slow modem users from tying up a process on the app servers during download. The communication between the proxies and the app servers is HTTP, as you said.

    The MVC stuff is all in the app servers. The model, controller, and view components are separate classes (well, technically the views are all Template Toolkit templates in this case), and they communicate to each other through standard method calls. None of the components is ever active on the proxy servers. Those are really just web serrvers with mod_proxy and mod_rewrite installed, and they don't run any Perl code.

    I hope that clears it up for you. If you have more questions, ask away.

      Sir, Thanks a lot for the explanation.It really helped me to understand that the MVC is in the app.server side.You also mentioned that the business data objects like the product data is cached and if my understanding from the doc.is right,you mentioned that the caching mechanism in written in C (for performance in the app side).So the question is , are you using socket in the model layers to communicate it to the cache to fetch the data objects? If so, do we have any custom written message protocol to accomplish this. Too much of interest in your article is making me to ask these kind of foolish questions, so kindly bear with me.
        The caching of data objects was done using BerkeleyDB. We wrote a simple cache interface on top of it to keep track of an expiration time for each entry and only return unexpired items. These days, you could just use Cache::Cache for this. That module wasn't around when we started.

        The part in C was a daemon on each app server to broadcast shared data to all the other app servers. The only data we shared was the read-only product data which should be the same on any server.