<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rlucas.net: The Next Generation &#187; template</title>
	<atom:link href="http://blog.rlucas.net/tag/template/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rlucas.net</link>
	<description>...fighting entropy one financing round at a time</description>
	<lastBuildDate>Sat, 04 Sep 2010 01:45:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CGI.pm hangs in read_from_client under Catalyst / TT</title>
		<link>http://blog.rlucas.net/bugfix/cgi-pm-hangs-in-read_from_client-under-catalyst-tt/</link>
		<comments>http://blog.rlucas.net/bugfix/cgi-pm-hangs-in-read_from_client-under-catalyst-tt/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 04:20:12 +0000</pubDate>
		<dc:creator>rlucas</dc:creator>
				<category><![CDATA[bugfix]]></category>
		<category><![CDATA[catalyst]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[hair-pulling-out]]></category>
		<category><![CDATA[hang]]></category>
		<category><![CDATA[madness]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://blog.rlucas.net/?p=383</guid>
		<description><![CDATA[Aahhh.  The joys of a Monday evening with the Perl debugger. I have a quite simple Web front-end to a relatively complex back-end system.  The Web app is written in Perl with Catalyst as a framework, and Template Toolkit (TT) as the templating engine.  Since we are smart-asses, we aped the Ruby on Rails &#8220;link_to&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Aahhh.  The joys of a Monday evening with the <a href="http://www.perl.org/">Perl</a> debugger.</p>
<p>I have a quite simple Web front-end to a relatively complex back-end system.  The Web app is written in Perl with <a href="http://www.catalystframework.org/">Catalyst</a> as a framework, and <a href="http://template-toolkit.org/">Template Toolkit</a> (TT) as the templating engine.  Since we are smart-asses, we aped the <a href="http://rubyonrails.org/">Ruby on Rails</a> &#8220;link_to&#8221; function, intending to use it within our templates.  Seems simple enough; and originally, we used <a href="http://search.cpan.org/dist/CGI.pm/">CGI.pm</a>&#8216;s escapeHTML function to handle the anchor text escaping.  Old habits (using the &#8217;90s era CGI mod) die hard, I guess.</p>
<blockquote>
<pre># in our Catalyst root; we use CGI.pm
use CGI qw/escapeHTML/; #OOPS
# ...
# mimics the Rails "link_to", and can be used directly in template toolkit
sub link_to {
 my $self = shift;
 my $anchor_text = escapeHTML(+shift); #ANOTHER OOPS HERE
 my @args = @_;
 my $uri = $self-&gt;uri_for(@args);
 return '&lt;a href="' . $uri . '"&gt;' . $anchor_text . '&lt;/a&gt;';
}</pre>
</blockquote>
<p>Well, as it turns out, I was getting a particularly maddening behavior whereby my app, when loaded in a single-process server instance, AND when a login action is the very first POST submitted (as is meet, right, and good), would inexplicably hang.  Not being intimately familiar with Catalyst, and being generally irate, I muttered a curse at the choice of framework and assumed that my contractors must have enabled some kind of recursion or infinite loop.  Nope; even ensuring that View::TT had RECURSION =&gt; 1 and a reasonable WHILE_MAX, I still got the hang.</p>
<p>So, into the debugger I dove.  A couple hours later, I&#8217;d tracked it down:</p>
<blockquote>
<pre>DB&lt;6&gt; CGI::read_from_client((eval 505)[/usr/share/perl/5.8/CGI.pm:895]:5):
5:          return $MOD_PERL
6:              ? $self-&gt;r-&gt;read($$buff, $len, $offset)
7:              : read(\*STDIN, $$buff, $len, $offset);</pre>
</blockquote>
<p>(Aside: why doesn&#8217;t WordPress have a &#8220;paste as code??&#8221;)</p>
<p>In CGI.pm&#8217;s &#8220;init,&#8221; it sets itself up to read from the browser input (on STDIN).  But if Catalyst has already slurped in STDIN, there&#8217;s nothing there to read, and CGI blocks.  (Either that, or something about CGI being init&#8217;ed from within the context of a Template that&#8217;s compiled and eval&#8217;ed under a mountain of cruft doesn&#8217;t sit right with CGI).</p>
<p>For the meantime, my solution is to use HTML::Entities and its encode_entities instead of CGI.  But beware using CGI when also using Catalyst; there&#8217;s a lot of dragons in CGI that you probably don&#8217;t want to have to understand and work around if you wake them up.  <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg07493.html">At least one other Catalyst / TT developer has had similar hang problems</a>.  Better to use the equivalent functionality from cleaner, more predictable modules.</p>
<p>(Mad props to CGI and its rock star author, Lincoln D. Stein.  But any module that&#8217;s got workarounds for mosaic and mid-90&#8242;s server bugs has got baggage, period.)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rlucas.net/bugfix/cgi-pm-hangs-in-read_from_client-under-catalyst-tt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->