When developing a web application, early on, when I was a vanilla CGI programmer, I often had a certain webpage whose contents would vary based on what "mode" the page was in.

For example, for a CGI GUI to a database search, the first mode of the page would present a bunch of pulldowns to customize SQL generation. Then, on re-submission of the page, the pulldowns would turn into uneditable text, showing the results, and a table of search results might be shown.

Jesse Erlbaum calls these run-modes and he discusses them in his recent Perl.com article in the context of his flexible web application development environment which is completely webserver, database, and architeceture agnostic. That is to say, things run just as well on the popular Linux/MySQL/Apache combo as NT/Access/IIS... which is really saying something given the general preferences of the Perl community.

I suggested object-oriented multiple dispatch in a recent perlmonks.org thread and in this article Erlbaum provides info on how CGI::Application handles this same problem.

I think the question I would ask him is why he thinks that run modes should be easily and uniquely dispatched based on a single parameter, because I once had a certain webpage whose contents was a function of HTTP_REFERER and the value of the submit button. The page whose output was a function of the multiple parameters listed above was a gem display page... In some cases, you were inputting values into this page. In other cases, you were editing values on this page. In other cases, you were checkign the status of this gem. In other cases, you were confirming input values on the page.

In fact from a purely theoretical viewpoint, it is well-known that single-inheritance is not always enough to partition the space of object-oriented computation into separate methods of computation.

Other Things about CGI::Application

  • Templating EngineErlbaum makes it clear why HTML::Template is his templating module of choice. For more information on templating in general, visit this Perlmonks.org node
  • Sessioning, Security unlike HTML::Embperl, CGI::Application does not try to be your all-in-one one-stop-shop for all aspects of Web Application Development. However, he does state that related CPAN modules will fit in orthogonally with no problem.
    • Comment on Dynamic Webpage Dispatch with CGI::Application(keywd: Web Software Engr)
  • Replies are listed 'Best First'.
    Re: Dynamic Webpage Dispatch with CGI::Application(keywd: Web Software Engr)
    by BMaximus (Chaplain) on Jun 07, 2001 at 15:41 UTC
      CGI::Application is not the end all do all module for building large web applications when using mod_perl. I started using the module and saw that in some places it fit the bill perfectly. However since I was using mod_perl , it didn't quite fit in for the whole picture. I love the concept though. I need something that's meant for mod_perl so I can use the Apache::Request module for getting the parameters and cookie as well as outputting the headers with the cookie already in it. I shouldn't have to hop through hoops in order to do what needs to be done at the end of the script. But this could be due to hubris and being set in my ways (read - more stubborn than a Jackass).

      I think what Jesse had in mind as far as run-modes were concerned was that it enabled the programer to keep everything simple and organized instead of overly complicating the dispatch table. I thought using Multiple::Dispatch for what I needed was overkill, considering Damian's explanation of the module in the book. It was meant more for GUI stuff created from Perl Tcl/Tk. I wish that Conway had provided another example using Multiple::Dispatch other than the one that was in Object Oriented Perl. I think in this case that my inexperience shows or this section of the book explaining that module was poorly written. I do learn well by both example and book. But some things take better when I see it in action.

      Some occasions do call for a multiple parameter dispatch. Most can be easily solved using a single dispatch and referring to the run modes with plain English. The only bad result that I can see from this is creating a huge list of run modes within the table. Using multiple parameters would only truncate this list. The only benefit that I see from using Multiple::Dispatch is if you need to do something polymorphically. Do this if you see foo and do that if you see foo and bar and the list goes on.

      I do hope that Jesse answeres princepawn's question. I'm curious as to what he says.

      Just my usual dotty observations,

      BMaximus

      I think I have learned more from PM than I could ever imagine.
        <blockquote3> I do hope that Jesse answeres princepawn's question. I'm curious as to what he says. I emailed jesse@vm.com and the mail bounced.
          You may try to post your question in Jesse's mail list for CGI::Application (cgiapp@lists.vm.com).

          pmas

          To make errors is human. But to make million errors per second, you need a computer.

    Re: Dynamic Webpage Dispatch with CGI::Application(keywd: Web Software Engr)
    by thabenksta (Pilgrim) on Jun 07, 2001 at 19:32 UTC

      I love the "run-mode" architecture and have been using it for a long time.

      FuseBox is a similar specification that has been implemented with ColdFusion, ASP and PHP, but not Perl, yet.

      -thabenksta
      my $name = 'Ben Kittrell'; $name=~s/^(.+)\s(.).+$/\L$1$2/g; my $nick = 'tha' . $name . 'sta';
    Re: Dynamic Webpage Dispatch with CGI::Application(keywd: Web Software Engr)
    by markjugg (Curate) on Jul 18, 2001 at 08:20 UTC
      princepawn,

      To respond to your question about displaying a mode based a single parameter-- There has been a recent addition to CGI::Application to make it more flexible in this regard. Look for mode_param() in the documentation-- You can now set the run mode based on the return value of a subroutine, which you can of course do most anything with.

      I'm on the verge of releasing an application based on this framework, called Cascade

      -mark