I hate CGI.pm

Discussion in 'Perl Misc' started by Ben Bullock, Jun 23, 2008.

  1. Ben Bullock

    Ben Bullock Guest

    Today I wanted to write a web interface for something, and I opted to
    use CGI.pm. It's a core module, something distributed with Perl, and
    yet it's painful to use. I started out using CGI.pm a few years ago
    when I knew next to no Perl, and at the time I blamed myself for the
    module's unuseability. Since then I've been learning more and more
    Perl, and yet coming back to CGI.pm I find that it's just as unuseable
    to me now as it was then. Some of its behaviours are just stupid and
    extremely annoying.

    What do other people think of it? Am I a lone CGI.pm hater, or do
    other people use some superior system instead of CGI.pm?

    I tried to read the documentation for Catalyst, and it makes no sense
    to me - it looks like you have to buy a book and spend hours and hours
    to understand it. Since I don't usually even write web things, I don't
    want to spend a lot of time studying the systems - I just want a
    "better CGI module". Does it exist?
     
    Ben Bullock, Jun 23, 2008
    #1
    1. Advertising

  2. Ben Bullock

    Brad Baxter Guest

    On Jun 23, 9:20 am, Ben Bullock <> wrote:
    > Today I wanted to write a web interface for something, and I opted to
    > use CGI.pm. It's a core module, something distributed with Perl, and
    > yet it's painful to use. I started out using CGI.pm a few years ago
    > when I knew next to no Perl, and at the time I blamed myself for the
    > module's unuseability. Since then I've been learning more and more
    > Perl, and yet coming back to CGI.pm I find that it's just as unuseable
    > to me now as it was then. Some of its behaviours are just stupid and
    > extremely annoying.
    >
    > What do other people think of it? Am I a lone CGI.pm hater, or do
    > other people use some superior system instead of CGI.pm?
    >
    > I tried to read the documentation for Catalyst, and it makes no sense
    > to me - it looks like you have to buy a book and spend hours and hours
    > to understand it. Since I don't usually even write web things, I don't
    > want to spend a lot of time studying the systems - I just want a
    > "better CGI module". Does it exist?


    I've had good success with CGI:Minimal. http://search.cpan.org/dist/CGI-Minimal/

    You have to bake your own cookies.

    --
    Brad
     
    Brad Baxter, Jun 23, 2008
    #2
    1. Advertising

  3. Ben Bullock wrote:
    > Today I wanted to write a web interface for something, and I opted to
    > use CGI.pm. It's a core module, something distributed with Perl, and
    > yet it's painful to use. I started out using CGI.pm a few years ago
    > when I knew next to no Perl, and at the time I blamed myself for the
    > module's unuseability. Since then I've been learning more and more
    > Perl, and yet coming back to CGI.pm I find that it's just as unuseable
    > to me now as it was then. Some of its behaviours are just stupid and
    > extremely annoying.
    >
    > What do other people think of it? Am I a lone CGI.pm hater, or do
    > other people use some superior system instead of CGI.pm?
    >
    > I tried to read the documentation for Catalyst, and it makes no sense
    > to me - it looks like you have to buy a book and spend hours and hours
    > to understand it. Since I don't usually even write web things, I don't
    > want to spend a lot of time studying the systems - I just want a
    > "better CGI module". Does it exist?


    It depends on what you mean by "painful", "unusable", "stupid",
    "annoying" and "better".

    Personally I tend to avoid CGI.pm because it's slow. As regards parsing
    form data, there are several alternative modules available, e.g.
    CGI::Lite and CGI::Minimal.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jun 23, 2008
    #3
  4. Ben Bullock

    Mirco Wahab Guest

    Ben Bullock wrote:
    > Today I wanted to write a web interface for something, and I opted to
    > use CGI.pm. It's a core module, something distributed with Perl, and
    > yet it's painful to use. I started out using CGI.pm a few years ago
    > when I knew next to no Perl, and at the time I blamed myself for the
    > module's unuseability. Since then I've been learning more and more
    > Perl, and yet coming back to CGI.pm I find that it's just as unuseable
    > to me now as it was then. Some of its behaviours are just stupid and
    > extremely annoying.
    >
    > What do other people think of it? Am I a lone CGI.pm hater, or do
    > other people use some superior system instead of CGI.pm?
    >
    > I tried to read the documentation for Catalyst, and it makes no sense
    > to me - it looks like you have to buy a book and spend hours and hours
    > to understand it. Since I don't usually even write web things, I don't
    > want to spend a lot of time studying the systems - I just want a
    > "better CGI module". Does it exist?


    Hi Ben,

    I almost always use HTML::Template and use CGI
    only sometimes for POST/GET parameter extraction
    and url encoding (seems to work). I tend to give
    the html-template exactly the same name as the
    corresponding Perl script and change the extension
    to htm (by convention: .htm is template, .html
    is static content).

    If HTML::Template doesn't fit, I use HTML::Mason
    (but that's only on somehow complicated things).

    Regards

    M.
     
    Mirco Wahab, Jun 23, 2008
    #4
  5. Ben Bullock

    brian d foy Guest

    In article <g3o7vm$4m7$>, Ben Bullock
    <> wrote:

    > Today I wanted to write a web interface for something, and I opted to
    > use CGI.pm. It's a core module, something distributed with Perl, and
    > yet it's painful to use.


    I think you'd need to define "painful to use". What was painful? What
    did you have trouble doing?
     
    brian d foy, Jun 23, 2008
    #5
  6. Ben Bullock

    Ron Bergin Guest

    On Jun 23, 6:20 am, Ben Bullock <> wrote:
    > Today I wanted to write a web interface for something, and I opted to
    > use CGI.pm. It's a core module, something distributed with Perl, and
    > yet it's painful to use. I started out using CGI.pm a few years ago
    > when I knew next to no Perl, and at the time I blamed myself for the
    > module's unuseability. Since then I've been learning more and more
    > Perl, and yet coming back to CGI.pm I find that it's just as unuseable
    > to me now as it was then. Some of its behaviours are just stupid and
    > extremely annoying.
    >
    > What do other people think of it? Am I a lone CGI.pm hater, or do
    > other people use some superior system instead of CGI.pm?
    >


    I think CGI.pm is an excellent module and fairly easy to use once you
    thoroughly read the documentation. However, it's not perfect, but
    then nothing is ever perfect.

    If you truly believe that it's that bad, why don't you write/publish
    your own version, rather than simply complaining without specific
    details and examples.
     
    Ron Bergin, Jun 23, 2008
    #6
  7. Ben Bullock

    Guest

    Ben Bullock <> wrote:
    > Today I wanted to write a web interface for something, and I opted to
    > use CGI.pm. It's a core module, something distributed with Perl, and
    > yet it's painful to use. I started out using CGI.pm a few years ago
    > when I knew next to no Perl, and at the time I blamed myself for the
    > module's unuseability. Since then I've been learning more and more
    > Perl, and yet coming back to CGI.pm I find that it's just as unuseable
    > to me now as it was then. Some of its behaviours are just stupid and
    > extremely annoying.
    >
    > What do other people think of it? Am I a lone CGI.pm hater, or do
    > other people use some superior system instead of CGI.pm?


    I like CGI.pm. I have been frustrated with it at times, but that
    frustration was usually resolved when I tried to do the same thing myself
    and thus discovered the subtleties involved, and then appreciated why CGIs
    needlessly complicated approach wasn't so needless after all.

    > I tried to read the documentation for Catalyst, and it makes no sense
    > to me - it looks like you have to buy a book and spend hours and hours
    > to understand it. Since I don't usually even write web things, I don't
    > want to spend a lot of time studying the systems - I just want a
    > "better CGI module". Does it exist?


    Have you looked at CGI::Lite? I didn't consider it better last I looked at
    it, but YMMV.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
     
    , Jun 23, 2008
    #7
  8. Ben Bullock

    cartercc Guest

    On Jun 23, 9:20 am, Ben Bullock <> wrote:
    > What do other people think of it? Am I a lone CGI.pm hater, or do
    > other people use some superior system instead of CGI.pm?


    > want to spend a lot of time studying the systems - I just want a
    > "better CGI module". Does it exist?


    I've been using Perl for about ten years for web programming. I took
    one look at CGI and decided to 'roll my own.' I use CGI to pass
    parameters from forms to scripts, but the big module that I find
    absolutely essential is DBI.

    When I develop a web project, I first start by building a module for
    database connectivity and HTML components (like the header, footer,
    buttons, menus, and so on.) I then build scripts that encapsulate
    functionality depending on the data. A very rough sample of pseudo
    code follows.

    I initialize my variables and then use heredocs to spit out HTML. To
    me, this is more intuitive than using any kind of includes tags, like
    JSP, PHP, ColdFusion, Catlyst, etc.) You can use the http header of
    the requested URL as a key into your database to dynamically generate
    pages depending on the user input. Essentially, you are writing a
    program to write a program to generate a website.

    This is what I mean:

    use strict;
    use CGI;
    use DBI;
    use myHTMLmodule;

    #passed in from an HTML form or from this script
    my $what = param('what');
    my $name = param('name');
    my $number = param('number');
    my $answer = param('answer');

    #generate dynamic page based on content drawn from database
    myHTMLmodule::header;
    myHTMLmodule::menu;
    &step_1 if $what eq 'Click Here';
    &step_2 if $what eq 'Got Name';
    &step_3 if $what eq 'Got Number';
    &step_4 if($what eq 'Ask Question';
    &error if $what eq '';
    myHTMLmodule::return_home;
    myHTMLmodule::footer;

    sub step_1
    {
    print <<step1
    <p>You want to $what</p>
    <ul>
    step1
    my @results = myHTMLmodule::return_query_results($what);
    foreach my $result (@results) { print "<li>$result</li>"; }
    print <<step1
    </ul>
    <p>This is the remainder of step 1:</p>
    <!-- HTML -->
    step1
    }

    step2, step3, step4, and error similar
     
    cartercc, Jun 23, 2008
    #8
  9. Ben Bullock

    szr Guest

    Ben Bullock wrote:
    > Today I wanted to write a web interface for something, and I opted to
    > use CGI.pm. It's a core module, something distributed with Perl, and
    > yet it's painful to use. I started out using CGI.pm a few years ago
    > when I knew next to no Perl, and at the time I blamed myself for the
    > module's unuseability. Since then I've been learning more and more
    > Perl, and yet coming back to CGI.pm I find that it's just as unuseable
    > to me now as it was then. Some of its behaviours are just stupid and
    > extremely annoying.


    Could you be kind enough to provide an example or two where CGI.pm
    didn't work well for you? Everyone can have a different experience so it
    might help to know where you're coming from via illustration :)

    Also please see my reply to your posting in the related FAQ thread.

    --
    szr
     
    szr, Jun 23, 2008
    #9
  10. Ben Bullock

    Ted Zlatanov Guest

    On Mon, 23 Jun 2008 13:20:54 +0000 (UTC) Ben Bullock <> wrote:

    BB> What do other people think of it? Am I a lone CGI.pm hater, or do
    BB> other people use some superior system instead of CGI.pm?

    mod_perl does most of the things I need (with Template Toolkit). For
    quick tasks, I like CGI::FormBuilder. I don't hate CGI.pm, just haven't
    found a compelling reason to use it instead of those two. A few times
    I've had to import utility functions, but that's about it.

    Ted
     
    Ted Zlatanov, Jun 23, 2008
    #10
  11. Ben Bullock

    Joe Schaefer Guest

    Ben Bullock <> writes:

    > I tried to read the documentation for Catalyst, and it makes no sense
    > to me - it looks like you have to buy a book and spend hours and hours
    > to understand it. Since I don't usually even write web things, I don't
    > want to spend a lot of time studying the systems - I just want a
    > "better CGI module". Does it exist?
    >


    The Apache folks, myself included, got together to write libapreq2,
    which provides APR::Request::CGI. Installing the module is a pita,
    because it depends on apache2 and mod_perl2 being installed. But
    as far as features and performance goes there are few perl modules
    capable of matching it.

    Migrating between APR::Request::CGI and APR::Request::Apache2 for
    mod_perl2 is straightforward: just change the initial
    APR::Request::CGI->handle() to APR::Request::Apache2->handle(). Otherwise
    the behavior of the library should be identical between CGI and
    mod_perl2.

    One nice feature is that parameters and cookies are subclassable
    objects, so you can change the FETCH behavior of the underlying
    tables by changing their param_class or cookie_class. It's also
    compatible with the basic param() API of CGI.pm, so you don't need
    to read a whole lot of docs in order to make basic use of it.


    --
    Joe Schaefer
     
    Joe Schaefer, Jun 24, 2008
    #11
  12. >>>>> "BB" == Ben Bullock <> writes:

    BB> What do other people think of it? Am I a lone CGI.pm hater, or
    BB> do other people use some superior system instead of CGI.pm?

    I think that using a widely available module to do something that's
    fiddly and prone to subtle problems is almost always the right thing to
    do. Parsing CGI parameters by hand is almost always the wrong thing to
    do. I find that CGI.pm has a lot of extra baggage that I don't usually
    need -- largely, the convenience methods for producing HTML, which are
    just as hard to get right as actual HTML and one step removed from the
    problem -- but I use it in preference to handrolling code.

    BB> I tried to read the documentation for Catalyst, and it makes no
    BB> sense to me - it looks like you have to buy a book and spend
    BB> hours and hours to understand it.

    Catalyst is a web application framework; to get anywhere meaningful with
    it, you have to understand how it thinks. It's also built on the
    TMTOWTDI principle, and so once you start involving plugins to do
    things, you start running into many more ways to solve problems and thus
    you need to understand more things to be able to make an intelligent
    choice.

    For large web applications, it makes sense to start with a framework.
    For one-script pages, it makes far less sense.

    BB> Since I don't usually even write web things, I don't want to
    BB> spend a lot of time studying the systems - I just want a "better
    BB> CGI module". Does it exist?

    What do you need the module to do? What do you find painful about
    CGI.pm?

    Charlton


    --
    Charlton Wilbur
     
    Charlton Wilbur, Jun 24, 2008
    #12
  13. On 2008-06-23 18:06, szr <> wrote:
    > Ben Bullock wrote:
    >> Today I wanted to write a web interface for something, and I opted to
    >> use CGI.pm. It's a core module, something distributed with Perl, and
    >> yet it's painful to use. I started out using CGI.pm a few years ago
    >> when I knew next to no Perl, and at the time I blamed myself for the
    >> module's unuseability. Since then I've been learning more and more
    >> Perl, and yet coming back to CGI.pm I find that it's just as unuseable
    >> to me now as it was then. Some of its behaviours are just stupid and
    >> extremely annoying.

    >
    > Could you be kind enough to provide an example or two where CGI.pm
    > didn't work well for you?


    * The param function doesn't deal well with non-ascii data. Newer versions
    of CGI.pm can treat the parameters as UTF-8, but that's still not
    flexible enough. So basically, you have to decode all parameters
    manually.

    * Constructing an URL with parameters is weird. It works, but I always
    need the man-page and several attempts to get it right. Doing it
    manually is a lot simpler (not just to write - also to maintain).

    * I never found a use for the "html convenience functions". They are
    slightly useful for prefilling forms with parameters (but only if you
    use ASCII only, otherwise CGI.pm's lack of consistent encoding rules
    will trip you up badly), but for anything else simply printing html is
    simpler.

    I do use CGI.pm. A lot. But only for very basic things like getting
    parameters.

    hp
     
    Peter J. Holzer, Jun 29, 2008
    #13
  14. Ben Bullock

    Guest

    "Peter J. Holzer" <> wrote:
    > On 2008-06-23 18:06, szr <> wrote:
    > >
    > > Could you be kind enough to provide an example or two where CGI.pm
    > > didn't work well for you?

    >
    > * Constructing an URL with parameters is weird. It works, but I always
    > need the man-page and several attempts to get it right. Doing it
    > manually is a lot simpler (not just to write - also to maintain).


    In what context is this? CGI.pm has tools for creating "self-referencing"
    URLs, but I don't think CGI.pm presents itself as a generic URL creating
    tool, so I'm not surprised it would be clumsy at doing that.

    When making self-referencing URLs, it would be nice if there was a way to
    say "Give me the self-referencing URL that would exist if this one
    parameter had this value instead of what it actually does." In the absence
    of that, I have to store the value, change it, get the self_url, then
    change it back.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
     
    , Jun 29, 2008
    #14
  15. Ben Bullock

    brian d foy Guest

    In article <20080629182126.868$>, <>
    wrote:


    > When making self-referencing URLs, it would be nice if there was a way to
    > say "Give me the self-referencing URL that would exist if this one
    > parameter had this value instead of what it actually does." In the absence
    > of that, I have to store the value, change it, get the self_url, then
    > change it back.


    When I want to do that, I create a second CGI.pm object. I can change
    it how I like without affecting the original data.
     
    brian d foy, Jun 30, 2008
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nicolas Matringe

    Why do we hate variables?

    Nicolas Matringe, Jan 22, 2004, in forum: VHDL
    Replies:
    4
    Views:
    4,210
    fabbl
    Jan 23, 2004
  2. Weng Tianxiang

    I hate VHDL!!!

    Weng Tianxiang, Jun 3, 2004, in forum: VHDL
    Replies:
    51
    Views:
    5,160
    roller
    Jun 19, 2004
  3. Jim Lewis

    Re: I hate VHDL!!!

    Jim Lewis, Jun 25, 2004, in forum: VHDL
    Replies:
    14
    Views:
    1,159
    Just an Illusion
    Jul 5, 2004
  4. Just an Illusion

    Re: I hate VHDL!!!

    Just an Illusion, Jun 25, 2004, in forum: VHDL
    Replies:
    7
    Views:
    709
    Jim Lewis
    Jul 17, 2004
  5. Tom  Verbeure

    Re: I hate VHDL!!!

    Tom Verbeure, Jul 19, 2004, in forum: VHDL
    Replies:
    11
    Views:
    1,076
    Jim Lewis
    Jul 31, 2004
Loading...

Share This Page