i've held off for some time now on using the CGI::Application framework for building applications. recently i decided to take a good hard look at it and i can definately see some merit to the idea. so i decided to port a few of my apps to it. i've encountered a few problems.

the biggest one, that i'm hoping someone else might have some useful insight on is that under mod_perl, using CGI::Application seems to trigger problems with HTML::Template.

i have a class Foo that is instantiated during the setup() routine and the instance is stored using the param() mechanism. Foo does a bunch of useful things including producing HTML::Template instances with some common params already set. so the typical usage looks something like this:

sub some_runmode { my $self = shift; my $foo = $self->param('Foo'); my $template = $foo->template("some_template.tmpl"); # ... # do some stuff and pass other params to the template # ... return $template->output(); }

this runs fine in a plain CGI environment and in mod_perl when run in single process mode (httpd -X). in a regular, multi-process mod_perl environment though, it gets a little sketchy. about 50% of the time it will die with the following error:

Error executing run mode 'some_runmode'. Eval of code '$self->some_ru +nmode' resulted in error: HTML::Template->new() : Unknown or unmatche +d TMPL construct at templates/some_template.tmpl : line 1. at /usr/li +b/perl5/site_perl/5.8.0/HTML/Template.pm line 2130.

of course, the template file itself is fine (obviously, since it runs half the time and in non-mod_perl environments). it seems to be something to do with how CGI::Application plays with mod_perl and HTML::Template.

i haven't gone through the source for CGI::Application yet. is it just not written to work safely under mod_perl? i'm pretty confident in the Foo module and the rest of the code i wrote without CGI::Application; it's been running just fine under mod_perl for a while now. it just breaks when i convert it from a collection of seperate .pl files to a single CGI::Application module.

the other (more minor) pet peeve i have with CGI::Application is that it overrides $SIG{__DIE__} so exception handling with eval { die; } doesn't work. i can work around that though. it's the problems under mod_perl that are preventing me from adding it to my toolkit.

anders pearson


In reply to mod_perl, CGI::Application, and HTML::Template: bad combination? by thraxil

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.