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

For an app I'm working on, we need a "universal request" object, similar in spirit to Catalyst::Request. We need the code to function the same regardless of whether or not we're using CGI, Apache::Request, SOAP or CLI interface (or whatever interface someone cares to add to it. I'm sure there's a generic request object out there somewhere, I just can't seem to find it.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re: Universal request objects
by dragonchild (Archbishop) on Dec 23, 2005 at 19:17 UTC
    You're not looking for Catalyst::Request - you're looking for Catalyst::Engine. In the C::R docs, it says that it's filled in by C::E. So, you need C::E subclasses that DWIM, plus some dispatcher that uses the right C::E subclass.

    Sounds to me like you just want to use Catalyst and go from there.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

      Actually, we don't want to use Catalyst. There is a Catalyst component, but it's optional. Thus, if the users don't want to install it, they shouldn't be dependent on it.

      Cheers,
      Ovid

      New address of my CGI Course.

        Break out the parts you want, create a new CPAN module, and offer it back to the Catalyst devteam as a separate distro that's useful without the rest of Catalyst. Then, Catalyst can use it as a dependency.

        My criteria for good software:
        1. Does it work?
        2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
        The Catalyst::Engine standalone rewrite is called Isotope, and although it's being worked on, the author is apparently somewhat famous for not commiting very often.

        Some time early in the new year, I'm going be (hopefully) helping to get Isotope $done, so I can replace the engine-layer of my own web application system with it.

        With you and I and a few others, I reckon we should be able to push it through to completion reasonably promptly. What do you say? :)
Re: Universal request objects
by samtregar (Abbot) on Dec 23, 2005 at 19:02 UTC
    CGI.pm works pretty well, with the possible exception of SOAP, depending on how you're taking requests. It definitely works for CGI, mod_perl and on the command-line.

    -sam

      Right. Doesn't work for SOAP or CLI. I know people have worked on this problem before, so I assume there's something out there. I just don't know if it's open source or not :)

      Cheers,
      Ovid

      New address of my CGI Course.

        CGI does work on the command-line. Witness:

        $ perl -Ilib htdocs/story.pl 'rm=edit&story_id=1' Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http +://www.w3.org/TR/html401/loose.dtd"> ...

        If you don't like that way of loading params you can load them yourself after calling CGI->new().

        -sam

Re: Universal request objects
by Joost (Canon) on Dec 23, 2005 at 23:23 UTC
    CGI.pm works fairly well on the command line, it's very good as the mod_perl and CGI interface. SOAP adds a whole new abstraction level on top of HTTP so it just plain can't be interchangeble with basic CGI unless you're willing to make a lot of assumptions (i.e. constict the SOAP interface). In the same way, CGI.pm's command line interface doesn't allow you to easily simulate POSTs and HTTP headers (though you can, if you're willing to set environment variables and feed STDIN).

    If I were you I'd probably go with CGI or CGI::Simple's (edit: or CGI::Lite::Request's) input parsing interface and expand that with whatever SOAP functionality you want (but as I don't know what you expect of the SOAP interface this is a hard question to answer in more detail).

Re: Universal request objects
by nothingmuch (Priest) on Dec 23, 2005 at 23:50 UTC
Re: Universal request objects
by ph713 (Pilgrim) on Dec 23, 2005 at 23:56 UTC
    I really wish people would stop recommending CGI.pm for anything. It was a workhorse in its time, but for the love of dog let it die. CGI::Simple is a really good replacement without all the html crap.
      Thanks for pointing this out. It looks interesting. However, in the bottom of the docs it says:

      BUGS
      As this is 0.01 there are almost bound to be some. Not recommended for production use.

      That worries me a little. Is that just the author being humble, or is this a fairly new and untested module? One nice thing about CGI.pm's widespread use is knowing that others have already worked out all the strange bugs.
        CGI::Simple is fairly robust in my book. That comment has (obviously) been there since 0.01, but it's at version 0.77 now. I've used it in a couple of production environments with great success. (I'm the "Brandon Black" credited at the bottom of the docs for doing some testing and bugfixing on this module way back when).

      I thought getting an HTML generator was one of the reasons why CGI.pm is so great! You'll take CGI from me over my dead body. HTML widget construction is supposed to be as easy as CGI.pm makes it and I know of no replacements for it. Care to englighten me?

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊