<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Mark Stosberg</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/" />
    <link rel="self" type="application/atom+xml" href="http://mark.stosberg.com/blog/atom.xml" />
    <id>tag:mark.stosberg.com,2008-11-25:/blog/2</id>
    <updated>2010-01-26T03:06:51Z</updated>
    <subtitle>balancing simplicity and technology in Richmond, Indiana</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.33-en</generator>

<entry>
    <title>generating HTTP headers: sorted or unsorted?</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2010/01/generating-http-headers-sorted-or-unsorted.html" />
    <id>tag:mark.stosberg.com,2010:/blog//2.318</id>

    <published>2010-01-26T01:42:21Z</published>
    <updated>2010-01-26T03:06:51Z</updated>

    <summary> Recently I&#8217;ve been reviewing how various Perl frameworks and modules generate HTTP headers. After reviewing several approaches, it&#8217;s clear that there are two major camps: those which put the response headers in a specific order and those which don&#8217;t....</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cgipm" label="CGI.pm" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="cgiapplication" label="CGI::Application" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="cgisimple" label="CGI::Simple" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="catalyst" label="Catalyst" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="Perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="plack" label="Plack" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p><div class="floatimgright"><a href="http://www.flickr.com/photos/markstos/4304868291/" title="A midwinter box bike ride by Mark Stosberg, on Flickr"><img src="http://farm5.static.flickr.com/4021/4304868291_0b6e3e2052_m.jpg" width="240" height="180" alt="A midwinter box bike ride" /></a></div> Recently I&#8217;ve been reviewing  how various Perl frameworks and modules generate HTTP headers. After reviewing several approaches, it&#8217;s clear that there are two major camps: those which put the response headers in a specific order and those which don&#8217;t. Surely one approach or the other would seem like it would be more spec-compliant, but RFC 2616 provides <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2">conflicting guidance on this point</a>. </p>

<p>The bottom line is that spec says that <em>&#8220;the order in which header fields with differing field names are received is not significant&#8221;</em>. But then it goes on to say that it is a &#8220;good practice&#8221; (and it puts &#8220;good practice&#8221; in quotes) to order the headers a particular way. So, without strict guidance from the spec about the importance of header ordering, it would be interesting to know if header order caused a problem in practice.</p>

<p>The <a href="http://search.cpan.org/perldoc?Plack::Middleware::RearrangeHeaders">Plack::Middleware::RearrangeHeaders</a> documentation suggests there is some benefit to strict header ordering: <em>&#8220;to work around buggy clients like very old MSIE or broken HTTP proxy servers&#8221;</em></p>

<p>You might wonder what the big deal is&#8212; why not just stick to the &#8220;good practice&#8221; recommendation all the time? The difference can be seen in the benchmarks provided by <a href="http://search.cpan.org/perldoc?HTTP::Headers::Fast">HTTP::Headers::Fast</a>. By ignoring the good-practice header order, an alternate implementation was able to speed-up header generation to be about twice as fast. Considering that a web-app needs to generate a header on every single request, making header generation smaller and faster is potentially a tangible win, while also still being spec-compliant. </p>
]]>
        <![CDATA[<p>So let&#8217;s look at who is doing what:</p>

<ul>
<li><a href="http://search.cpan.org/perldoc?CGI::Application">CGI.pm</a> does not order headers by default or have an option to do so. CGI.pm is used by default by CGI::Application and also by Mason and Jifty when they run under CGI.</li>
<li>CGI::Simple predictably models CGI.pm&#8217;s behavior</li>
<li><a href="http://search.cpan.org/perldoc?Dancer">Dancer</a> generates headers itself, without regard to order</li>
<li><a href="http://search.cpan.org/perldoc?Plack">Plack</a> is a mixed bag. If you generate your own headers, I believe they will be passed through unmodified, but if you use <a href="http://search.cpan.org/perldoc?Plack::Request">Plack::Request</a> they will be ordered (with no option to disable this). With Plack you also have the option to the the RearrangeHeaders Middleware if you want to be certain that your headers are in the &#8220;good practice&#8221; order. </li>
<li><a href="http://search.cpan.org/perldoc?Mojo">Mojo</a> generates its own headers, always in the &#8220;good practice&#8221; order, with no way to disable the ordering.</li>
<li><a href="http://search.cpan.org/perldoc?Catalyst">Catalyst</a>, Plack and others rely on <a href="http://search.cpan.org/perldoc?HTTP::Headers">HTTP::Headers</a> to generate headers. HTTP::Headers also currently always generates headers in good-practice order, although there has been <a href="http://www.mail-archive.com/libwww@perl.org/msg06573.html">some discussion</a> about adding an option to produce the headers in an unsorted order. </li>
<li>And finally, I found <a href="http://search.cpan.org/perldoc?HTTP::Headers::Fast">HTTP::Headers::Fast</a> which is used by HTTP::Engine and provides the user equal options to generate headers in a sorted or unsorted order.</li>
<li>For a bonus consultation, I looked at Rack, a web server written in Ruby sometimes paired with Rails, and one of the inspirations for Plack. It appears that that <a href="http://github.com/chneukirchen/rack/blob/master/lib/rack/handler/cgi.rb">Rack does not order HTTP headers either</a>. </li>
</ul>

<p>So which approach is best? I think what makes most sense to me is leave HTTP headers unsorted by default. This complies with the spec and can be accomplished with a simpler implementation and better performance. The good-practice ordering is a nice-to-have option if you know you need it or want the tradeoff.  </p>

<p>And should we be worried about header ordering issues in practice? With CGI.pm in use for over a decade, I can&#8217;t recall any header-ordering bugs of the hundreds of CGI.pm bugs I&#8217;ve triaged in that bug tracker. I&#8217;m interested to know if there are any real-world web clients or proxies that require or benefit from the good-practice ordering. </p>
]]>
    </content>
</entry>

<entry>
    <title>A vision for CGI.pm and CGI::Simple</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2009/09/a-vision-for-cgipm-and-cgisimple.html" />
    <id>tag:mark.stosberg.com,2009:/blog//2.311</id>

    <published>2009-09-24T01:19:23Z</published>
    <updated>2009-09-24T02:02:34Z</updated>

    <summary> I&#8217;ve spent a lot time recently triaging bugs for CGI.pm. I&#8217;ve enjoyed the process, and respect CGI.pm as a widely used Perl module. I&#8217;m not in love all aspects of module. I don&#8217;t use or recommend the HTML generation...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cgipm" label="CGI.pm" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="cgisimple" label="CGI::Simple" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="psgi" label="PSGI" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p><a href="http://www.flickr.com/photos/markstos/3933330782/" title="baby sleeps again by Mark Stosberg, on Flickr"><img src="http://farm3.static.flickr.com/2508/3933330782_e081dcf5ac_m.jpg" width="240" class="floatimgleft" height="180" alt="baby sleeps again" /></a> I&#8217;ve spent a lot time recently <a href="http://mark.stosberg.com/blog/2009/08/almost-100-cgipm-bugs-closed-help-with-the-50-still-open.html">triaging bugs for CGI.pm</a>. I&#8217;ve enjoyed the process, and respect CGI.pm as a widely used Perl module. I&#8217;m not in love all aspects of module. I don&#8217;t use or recommend the HTML generation features&#8212; I recommend using HTML template files and <a href="http://search.cpan.org/perldoc?HTML::FillInform">HTML::FillInForm</a> for filling them.</p>

<p>Whenever I think about how I&#8217;d like to change CGI.pm,what I have mind is often the same choice that <a href="http://search.cpan.org/perldoc?CGI::Simple">CGI::Simple</a> made.  There was a time years ago that I focused my attention on CGI::Simple and tried it in production, only to be bit by a compatibility issue, so I reverted back to CGI.pm. I don&#8217;t remember what the specific issue, and it&#8217;s likely been fixed by now. But the pragmatic point remained with me: CGI::Simple may have clean code and a good test suite, but it&#8217;s not necessarily free of defects and in particularly it lacks the vastly larger user base that CGI.pm has to provide real world beta testing. </p>
]]>
        <![CDATA[<p>I recently took another look at CGI::Simple, it&#8217;s <a href="http://mark.stosberg.com/blog/2008/12/cookie-handling-in-titanium-catalyst-and-mojo.html">cookie handling implementation</a>, and its bug queue. One thing became clear: CGI::Simple forked from CGI.pm in 2001, and they have not evolved in parallel since then. Each has had different bugs filed against it, with some issues fixed in one and not the other. They both have test suites, but they have evolved with different test coverage as new tests are written to respond to bugs filed against one particular module. </p>

<p>And, unfortunately for the better design of CGI::Simple, it is CGI.pm that continues to receive far more of the attention and updates. (Although to be fair, some of this relates to the HTML functions, which are intentionally omitted from CGI::Simple). </p>

<p>I would like to say that CGI::Simple is a clear path forward from CGI.pm if you are willing to let go of the HTML generation functions. Unfortunately, the current situation is ripe for running into subtle differences that have been created since the projects forked about eight years ago. </p>

<p>My vision for a solution is simple: CGI.pm and CGI::Simple should be maintained together. Where their features overlap, the combined project should have the best version of the documentation from both projects, the best code from both projects, and the combined test coverage of both projects. CGI::Simple is intentionally incompatible in a few ways in the name of better design, and I support that. Still, the projects should strive to maintain compatible whenever possible to make it easy for people to transition from CGI.pm to CGI::Simple. When a change comes in that could affect either module, it should be changed in both modules. </p>

<p>A great example of a possible collaboration point is the <a href="http://rt.cpan.org/Public/Bug/Display.html?id=49943">request</a> to add <a href="http://bulknews.typepad.com/blog/2009/09/psgi-perl-wsgi.html">PSGI</a> support to CGI.pm. Ideally if the proposal is accepted, it could be added to both CGI.pm and CGI::Simple at the same time, with the same API, tests and documentation. </p>
]]>
    </content>
</entry>

<entry>
    <title>Almost 100 CGI.pm bugs closed, help with the 50 still open</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2009/08/almost-100-cgipm-bugs-closed-help-with-the-50-still-open.html" />
    <id>tag:mark.stosberg.com,2009:/blog//2.308</id>

    <published>2009-08-15T01:28:23Z</published>
    <updated>2009-08-15T02:14:08Z</updated>

    <summary> Get off the couch and pull your weight&#8212; There&#8217;s CGI.pm bug with your name on it. There were nearly 150 active entries in the CGI.pm bug tracker when I was approved recently as a new co-maintainer. As I had...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cgipm" label="CGI.pm" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<div class="floatimgright"> 
<a href="http://www.flickr.com/photos/markstos/3802117476/" title="new bikes-at-work trailer by Mark Stosberg, on Flickr"><img src="http://farm3.static.flickr.com/2634/3802117476_bd83c36b1f_m.jpg" width="240" height="180" alt="new bikes-at-work trailer" /></a>Get off the couch and pull your weight&#8212; <br/>There&#8217;s CGI.pm bug with your name on it.</div> 

<p>There were nearly 150 active entries in the CGI.pm bug tracker when I was approved recently as a new co-maintainer. As I had time in the evenings after the baby was sleep, I went through and reviewed every one of these bug reports. Many had already been addressed by Lincoln some time ago. Those were simply closed.  Still, I found about 20 fairly ready-to-go patches, and those have now been processed and <a href="http://cpansearch.perl.org/src/LDS/CGI.pm-3.45/Changes">released today as CGI.pm 3.45</a>. Whenever code changes were made, I also strived to make sure new automated tests were added that covered those cases. You may be surprised how many methods in CGI.pm have no automated tests for them at all. </p>

<p>Now there are still about 50 open issues in the <a href="http://rt.cpan.org/Public/Dist/Display.html?Name=CGI.pm">CGI.pm bug tracker</a>. For these, I have tried to use the subject line some summary indication of what is needed to move it forward, like &#8220;Needs Test: &#8220;, or &#8220;Needs Peer Review: &#8221; or &#8220;Needs Confirmation&#8221;. Generally, I plan to wait patiently for volunteers to help with these. If you use CGI.pm, consider helping to move one of these forward. </p>
]]>
        <![CDATA[<p>To make collaboration easier, <a href="http://github.com/markstos/CGI.pm/tree/master">CGI.pm is now on github</a>. You are welcome to fork and send pull requests through there, although posting patches to the bug tracker continues to work file for small changes.  The full CVS history has not been translated yet, but may be eventually. </p>

<p>CGI.pm has been in the Perl core since 5.4. With its maturity comes quirks. I&#8217;m not a fan of the HTML generation functions. I find the support for both OO and procedural styles awkward. As I have more time, I also hope to continue updating the CGI.pm documentation to promote more modern practices, and de-emphasize other parts of it, like the HTML generation functions and the procedural interface. </p>

<p>I would like to thank Lincoln Stein for building and releasing CGI.pm, and for maintaining it for over a decade. Many projects from <a href="http://www.cgi-app.org">CGI::Application</a> to <a href="http://www.movabletype.com">Movable Type</a> depend on it. I also appreciate his willingness to allow for direct help on the project, and his receptiveness to the documentation overhaul idea. Lincoln is continuing his involvement. He completed the final review and release of the changes proposed for 3.45. </p>

<p>I understand that CGI.pm is broadly used, but like ExtUtils::MakeMaker, not always well loved. It&#8217;s true that some day it will be completely replaced by next-generation tools, and some reasonable candidates exist now. Until then, there are thousands of existing users will appreciate our collective maintenance of the module.  Let&#8217;s get the bug tracker back down to zero!</p>
]]>
    </content>
</entry>

<entry>
    <title>Movable Type fork is an opportunity to harness CPAN</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2009/06/movable-type-fork-is-an-opportunity-to-harness-cpan.html" />
    <id>tag:mark.stosberg.com,2009:/blog//2.301</id>

    <published>2009-06-23T16:21:51Z</published>
    <updated>2009-06-24T13:21:20Z</updated>

    <summary><![CDATA[ Today Melody was announced as a fork of the perl-based Movable Type platform. I helped the Melody project as it prepared to launch, in part advising on how to best to relate to the Perl community.&nbsp; One of the...]]></summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Movable Type" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cgiapplication" label="CGI::Application" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="melody" label="Melody" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="Perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="fork" label="fork" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="movabletype" label="movabletype" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="melody-logo-mark-on-white-thumb-200x200-7.jpg" src="http://mark.stosberg.com/blog/images/melody-logo-mark-on-white-thumb-200x200.jpg/melody-logo-mark-on-white-thumb-200x200-7.jpg" class="mt-image-right" style="margin: 0pt 0pt 20px 20px; float: right;" height="200" width="200" /></span>
Today <a href="http://www.openmelody.org/">Melody</a> was announced as a fork of the perl-based <a href="http://www.movabletype.org/">Movable Type platform</a>. I helped the Melody project as it prepared to launch, in part advising on how to best to relate to the Perl community.&nbsp; One of the stated interests of Melody is to refactor the project to use <a href="http://www.cgi-app.org/">CGI::Application</a>, which I maintain. Tim Appnel has already spelled out&nbsp; <a href="http://wiki.movabletype.org/Proposal:Foundry">a vision of what a "CPANization" of Movable Type might look like</a>, and I've looked in depth at what the <a href="http://wiki.movabletype.org/Proposal:QueryObjectRefactor">initial steps towards using CGI::Application</a> could be.<br /><br />My own vision for Melody is a code base that's very focused on publishing and content management, with all the infrastructure outsourced to <a href="http://search.cpan.org/">CPAN</a> modules that are well-written, well-documented, and well-tested.&nbsp; The collaboration between Melody and CPAN would be a two-way code flow. While there are more CPAN modules that Melody could make use of, there are number of pieces of Melody which should be packaged as independent modules on their own and released to CPAN. One example is the great "dirification" that already exists in Movable Type. This is the functionality that turns any given string of words into a reasonable representation in URLs. It seems like an easy problem on the surface, but Movable Type has a sophisticated solution that takes into account what it means to do this well across many different languages. I also couldn't find any existing CPAN module which already takes on this problem space, so I started to extract this out of Movable Type myself and <a href="http://www.sixapart.com/pipermail/mtos-dev/2008-December/002249.html">published a draft of String::Dirify</a>. For that initial release, I ripped out all the fancy multi-language support, and there is still more significant work to be done to untangle this layer from from Movable Type. ( If you want to pick up that project and work on it, there's also <a href="http://www.sixapart.com/pipermail/mtos-dev/2008-September/001982.html">some discussion of testing String::Dirify</a>).<br /><br />While Movable Type already had an open source release, I expect Melody to have&nbsp; a more adventerous evolution, and I look forward to it becoming a shining star in the Perl community, not just for the exterior functionality, but also because internals have an opportunity to become an example of best practices. <br />]]>
        
    </content>
</entry>

<entry>
    <title>Towards a Pure Perl HTML::FillInForm: 61% tests passing</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2009/04/towards-a-pure-perl-htmlfillinform-61-tests-passing.html" />
    <id>tag:mark.stosberg.com,2009:/blog//2.279</id>

    <published>2009-04-28T02:50:44Z</published>
    <updated>2009-04-28T03:16:02Z</updated>

    <summary> I have a goal of distributing Titanium along with all of its dependencies. The vision is to have a pure perl stack, so it&#8217;s easy to unpack and start using the distribution, without worrying about binaries tied to a...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p><a href="http://www.flickr.com/photos/markstos/3478645938/" title="kentucky creek by Mark Stosberg, on Flickr"><img  align="left"
style="margin-right: 10px" src="http://farm4.static.flickr.com/3540/3478645938_d4c1817754.jpg" width="103" height="500" alt="kentucky creek" /></a> I have a goal of distributing <a href="http://search.cpan.org/perldoc?Titanium">Titanium</a> along with all of its dependencies. The vision is to have a pure perl stack, so it&#8217;s easy to unpack and start using the distribution, without worrying about binaries tied to a specific platform. </p>

<p>One stumbling block with this has been <a href="http://search.cpan.org/perldoc?HTML::Parser">HTML::Parser</a>, which requires XS and is dependency of <a href="http://search.cpan.org/perldoc?HTML::FillInForm">HTML::FillInForm</a>, which is used by <a href="http://search.cpan.org/perldoc?CGI::Application::Plugin::ValidateRM">CGI::Application::Plugin::ValidateRM</a>. </p>

<p>I&#8217;ve been working with Ron Savage on a Pure Perl replacement for HTML::Parser, and I made good progress over the weekend based on his foundation.  He created <a href="http://search.cpan.org/perldoc?HTML::Parser::Simple">HTML::Parser::Simple</a>, which is really is two major parts in a one. First, it provides a pure-perl HTML parser. Secondly, it also provides a specific use of the parser, which is store a representation of a HTML documentation as a <a href="http://search.cpan.org/perldoc?Tree::Simple">Tree::Simple</a> data structure. </p>

<p>In a future version, I&#8217;d like to see the Tree::Simple part split into it&#8217;s own
module to clarify the parts, and to eliminate this dependency for people who
don&#8217;t use it. For example, in the new sub-class I created, I don&#8217;t use the
Tree::Simple object at all.</p>

<p>I made a short-term goal of getting all the tests for HTML::FillInForm to pass when we modify one line in HTML::FillInForm to say that it &#8220;isa&#8221; HTML::Parser::Simple::Compat&#8221; rather than being a sub-class of HTML::Parser. Then I run the HTML::FillInForm test suite and see how many tests pass and file. Currently our parser emulates enough of HTML::Parser to pass 61 percent of the tests. </p>

<p>The idea with &#8220;HTML::Parser::Simple::Compat&#8221; is provide an API that is compatible (enough) with the HTML::Parser 2.x API.  I think the approach seems promising, but there is still more to do:</p>

<ul>
<li>I have a focused on getting tests to pass, so the documentation is still poor</li>
<li>Perhaps my &#8220;Compat&#8221; sub-class should really be merged into the parent class. I&#8217;ll discuss this with Ron</li>
<li>There are few of our own tests, as I&#8217;ve been focusing on getting HTML::FillInForm tests to pass. Perhaps more of those tests could be &#8220;ported&#8221; into own test suite.</li>
<li>Performance and memory consumption have not been benchmarked. </li>
</ul>

<p>If this project interests you, feel free to fork the project on github and start contributing code or other feedback.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Titanium:  A new release and more</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2008/12/titanium-a-new-release-and-more.html" />
    <id>tag:mark.stosberg.com,2008:/blog//2.254</id>

    <published>2008-12-11T00:21:56Z</published>
    <updated>2008-12-11T01:43:59Z</updated>

    <summary> Titanium 1.01 was released recently. The new release include includes a README with clearer instructions on how to install Titanium if you are not already familiar with installing modules from CPAN. Initial feedback on Titanium has been positive. A...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cgiapplication" label="CGI::Application" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="titanium" label="Titanium" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p><a href="http://www.flickr.com/photos/markstos/2955858790/" title="Derrek on the EZ-Sport recumbent by Mark Stosberg, on Flickr"><img align="right" style="margin-left: 10px; border: 1px" src="http://farm4.static.flickr.com/3282/2955858790_82d97a4b83_m.jpg" width="240" height="180" alt="Derrek on the EZ-Sport recumbent" /></a> Titanium <a href="http://search.cpan.org/~markstos/Titanium-1.01/">1.01 was released</a>
recently. The new release include includes a README with clearer instructions
on how to install Titanium if you are not already familiar with installing
modules from <a href="http://search.cpan.org/">CPAN</a>.</p>

<p>Initial feedback on Titanium has been positive. A couple recent quotes from
users:  &#8220;Titanium is much, much simpler [than Catalyst] and has the advantages
that entails.&#8221; <a href="http://news.ycombinator.com/item?id=374314">1</a>,
&#8220;CGI::Appplication and Titanium (including modules like HTML::Template and
HTML::FillInForm) are simple to use, work with all of the authentication stuff
that I interface with, and scale perfectly for the number of users that I
typically have.&#8221; <a href="http://news.ycombinator.com/item?id=374340">2</a>.
Simplicity is a goal of Titanium and our feedback confirms our success with it. </p>
]]>
        <![CDATA[<p>Jaldhar Vyas has also made important contributions to making it easier to get
going with Titanium. He has <a href="http://packages.ubuntu.com/jaunty/libtitanium-perl">packaged Titanium for
Ubuntu</a>, appearing first in
the upcoming Jaunty Jackalope release.  He also released a new version of
<a href="http://search.cpan.org/dist/Module-Starter-Plugin-CGIApp/">Module::Starter::Plugin::CGIApp</a>,
which includes a &#8220;titanium-starter&#8221; script used to start Titanium projects.
This modules comes as a part of installing Titanium and its dependencies. </p>

<p>To test the performance of Titanium, I made a <a href="/blog/2008/11/startup-benchmarks-for-mojo-catalyst-titanium-httpengine-and-cgiapplication.html">simple
benchmark</a>
to compare it with some other Perl systems in vanilla CGI. It confirmed what I
already knew:Titanium runs fine in vanilla CGI as well as scaling up persistent
environments like FastCGI and mod_perl.</p>

<p>When the results first came out,
<a href="http://search.cpan.org/perldoc?HTTP::Engine">HTTP::Engine</a> had by far the
worst results&#8212; unacceptable performance for vanilla CGI. But soon afterwards
the developers embarked on a successful effort to improve the performance in
vanilla CGI. In just a few days time, they had a version that benchmarked
nearly 10x faster, while still keeping all the essential features. This is the philosophy
that CGI::Application and Titanium have always had&#8212; we provide the essential features
you need with low overhead.</p>

<p>To help out new users get started with this kind of web development, Mark Rajcok created
a <a href="http://docs.google.com/View?docID=dd363fg9_77gb4hdh7b&amp;revision=_latest">CGI::Application Tutorial and Jumpstart Application</a>. He used CGI::Application and some plugins to create a solution much like Titanium that performs well in a typical shared hosting environments. He includes a <a href="http://perlmvccgiapp.sourceforge.net/cgi-bin/app1/main.cgi">demp</a>, so you can see test the performance for yourself. Mark is another person who appreciates the <a href="/blog/2008/11/the-benefits-of-vanilla-cgi-vs-fastcgi-for-perl-apps.html">benefits of vanilla CGI</a>.</p>

<p>With this positive initial feedback I plan to continue my work on making Titanium <a href="/blog/2008/09/progress-on-making-a-self-contained-titanium-distribution.html">even easier to install</a> by shipping all of its dependencies with it. </p>
]]>
    </content>
</entry>

<entry>
    <title>Cookie handling in Titanium, Catalyst and Mojo </title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2008/12/cookie-handling-in-titanium-catalyst-and-mojo.html" />
    <id>tag:mark.stosberg.com,2008:/blog//2.253</id>

    <published>2008-12-10T02:23:12Z</published>
    <updated>2008-12-10T02:38:49Z</updated>

    <summary>This weekend I spent some quality time with HTTP Cookie Specs ( RFC 2109 and RFC 2695 ), and looked closely how at the cookie parsing and handling is done in three Perl frameworks: Titanium, Catalyst and Mojo. Titanium uses...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cgipm" label="CGI.pm" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="cgiapplication" label="CGI::Application" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="cgisimple" label="CGI::Simple" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="catalyst" label="Catalyst" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mojo" label="Mojo" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="titanium" label="Titanium" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="cookies" label="cookies" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="framework" label="framework" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p>This weekend I spent some quality time with HTTP Cookie Specs 
( <a href="http://www.ietf.org/rfc/rfc2109.txt">RFC 2109</a> and <a href="http://www.ietf.org/rfc/rfc2965.txt">RFC 2695</a> ),
and looked closely how at the cookie parsing and handling is done in three Perl
frameworks: <a href="http://search.cpan.org/perldoc?Titanium">Titanium</a>,
<a href="http://search.cpan.org/perldoc?Catalyst">Catalyst</a> and
<a href="http://search.cpan.org/perldoc?Mojo">Mojo</a>. Titanium uses 
<a href="http://search.cpan.org/perldoc?CGI::Cookie">CGI::Cookie</a>
by default, while Catalyst uses
<a href="http://search.cpan.org/perldoc?CGI::Simple::Cookie">CGI::Simple::Cookie</a> and Mojo uses built-in
modules including <a href="http://search.cpan.org/perldoc?Mojo::Cookie::Request">Mojo::Cookie::Request</a>.</p>

<p>I&#8217;ll look at these solutions through the filters of Standards, Security, and
Convenience.</p>

<h2>Standards: Max-Age, Set-Cookie2 and commas</h2>

<p>Max-Age is cookie attribute which gives the expiration time as a relative
value. This is considered a more secure replacement for the &#8220;Expires&#8221; header,
which gives the time as an absolute value, making it vulnerable to clock skew
on the user&#8217;s systems. CGI.pm and Mojo support it, but CGI::Simple does not. 
This is potentially an issue for Catalyst users, if they believe they have Max-Age support
because the documentation refers them to CGI::Cookie, but they actually don&#8217;t because they are using CGI::Simple::Cookie. </p>

<p>Set-Cookie2 is a standard from 2000 to replace Set-Cookie, which became a
standard in 1997. Mojo is the only of the three that supports it. However,
Set-Cookie2 <a href="http://www.mnot.net/blog/2006/10/27/cookie_fun">never caught on</a>.
Firefox 3 doesn&#8217;t even support it, and neither does IE 6. Still, I like the
idea of deciding for myself about supporting new standards, rather than having
tools that only support older standards. Mojo wins here. </p>

<p>The RFCs say that servers should accept a comma as well as semicolon between
cookie values.  CGI.pm and Mojo comply here, CGI::Simple does not. (I&#8217;ve
submitted a <a href="http://rt.cpan.org/Ticket/Display.html?id=34310">patch to address
this</a>,  along with a few other
places I felt CGI::Simple cookie parsing lagged CGI.pm)</p>

<h2>Security</h2>

<p>CGI::Simple cookies are potentially less secure because they lack &#8220;Max-Age&#8221;
support. Mojo&#8217;s cookie implementation appears to be vulnerable to an injection attack
where untrusted data in a cookie value can write a new HTTP body. I have
notified the developers of my findings there. CGI.pm and CGI::Simple both
avoid the injection attack by URI-encoding the cookie values, (a spec-compliant
solution). </p>

<h2>Convenience</h2>

<p>CGI.pm and CGI::Simple share several convenient user interface features which
Mojo currently lacks. They allow you to set multiple-values for a single
cookie, including setting a hashref. They also provide a convenient shorthand
for giving expiration times, like &#8220;+10m&#8221; for &#8220;10 months in the future&#8221;. Mojo
lacks these features. If you have a Catalyst app that uses
the multiple-values features, a port to Mojo could mean a painful cookie transition, since
Mojo does not have a built-in understanding of the format CGI.pm uses to store
cookie values. (This detail is not dictated by the cookie spec so both value formats are &#8220;spec compliant&#8221;). </p>

<h2>Conclusions</h2>

<p>Sebastian Riedel, the Mojo author, promotes Mojo as being focused on standards.
From my findings here, I have to say that I agree that Mojo is a leader here,
currently at the expense of a potentially serious security issue, and lacking some usability features that the others offer. </p>

<p>CGI::Simple has a reputation but being a lighter and better enigeneered version
of CGI.pm. Certainly the overall the design and focus of CGI::Simple is an
improvement. But the reality is that CGI::Simple was forked from CGI.pm in
2001. CGI.pm has received many improvements since then including improved
cookie handling, like adding support for &#8220;Max-Age&#8221;. However, CGI::Simple
doesn&#8217;t seem to make a point of tracking and merging improvements that
originate in CGI.pm. CGI::Simple is perhaps more like a lighter, tighter
alternative to CGI.pm as it existed several years ago. </p>

<p>The mature-but-maligned CGI.pm comes out fairing the best for cooking handling in my opinion. It did not have any of the potential security issues I found with the other two, and
it has a range of convenient methods for cookie access. </p>

<p>But as a final note, I encourage to you check with the specific projects for
the most current information, as some of the deficiencies I found here may
already be addressed.</p>
]]>
        

    </content>
</entry>

<entry>
    <title> HTTP::Engine drops Moose for Shika, gains massive speedup</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2008/12/httpengine-drops-moose-for-shika-gains-massive-speedup.html" />
    <id>tag:mark.stosberg.com,2008:/blog//2.252</id>

    <published>2008-12-02T04:08:46Z</published>
    <updated>2008-12-02T00:00:04Z</updated>

    <summary>When I recently benchmarked several Perl website development tools, HTTP::Engine had dismal performance. The slowest performer, it took 1.5 seconds just to print &quot;Hello World&quot; in a CGI environment and took 14.6 megs of memory to it. Today the first...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[When I <a href="http://mark.stosberg.com/blog/2008/11/startup-benchmarks-for-mojo-catalyst-titanium-httpengine-and-cgiapplication.html">recently benchmarked</a> several Perl website development tools, HTTP::Engine had dismal
performance. The slowest performer, it took 1.5 seconds just to print "Hello
World" in a CGI environment and took 14.6 megs of memory to it.
<p>
Today the first HTTP::Engine release appeared that replaces <a href="http://search.cpan.org/perldoc?Moose">Moose</a> with <a href="http://search.cpan.org/perldoc?Shika">Shika</a>. Shika provides the
essential class-building tools that HTTP::Engine needs with a Moose-compatible
syntax, and strips out the rest of the magic.
</p><p>
The performance improvement was dramatic. The "Hello World" time dropped to
0.19seconds on the same hardware (almost 10 times as fast!) and the memory
usage dropped to 6.6 Megs.
</p><p>
Catalyst is currently slated to use Moose in the next major version. Now that
HTTP::Engine has switched away from Moose for better performance and memory
savings, will other projects follow suit?</p>]]>
        
    </content>
</entry>

<entry>
    <title>The benefits of vanilla CGI vs FastCGI for Perl apps</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2008/11/the-benefits-of-vanilla-cgi-vs-fastcgi-for-perl-apps.html" />
    <id>tag:mark.stosberg.com,2008:/blog//2.249</id>

    <published>2008-11-23T04:57:29Z</published>
    <updated>2008-11-30T18:53:55Z</updated>

    <summary> There&#8217;s a lot of trash talk among professional web programmers regarding using vanilla CGI, like Stevan Little&#8217;s recent comment &#8220;There is no excuse to still use vanilla CGI as it is simply just a waste of resources&#8221;. As an...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="cgi" label="CGI" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="cgiapplication" label="CGI::Application" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="catalyst" label="Catalyst" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="fastcgi" label="FastCGI" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="framework" label="framework" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mod_perl" label="mod_perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p><a href="http://www.flickr.com/photos/markstos/2662094343/" title="Grover's recumbent, side view by Mark Stosberg, on Flickr"><img align="left" style="margin-right: 10px" src="http://farm4.static.flickr.com/3078/2662094343_c0cd06dd49_m.jpg" width="180" height="240" alt="Grover's recumbent, side view" /></a> There&#8217;s a lot of trash talk among professional web programmers regarding using
vanilla CGI, like Stevan Little&#8217;s <a href="http://mark.stosberg.com/blog/2008/11/startup-benchmarks-for-mojo-catalyst-titanium-httpengine-and-cgiapplication.html#comment-50">recent comment</a> <em>&#8220;There is no excuse to still use
vanilla CGI as it is simply just a waste of resources&#8221;</em>.</p>

<p>As an experienced professional website developer myself, I find that CGI has its place.
First, let&#8217;s recap what we&#8217;re talking about.</p>
]]>
        <![CDATA[<p>In &#8220;vanilla CGI&#8221;, a Perl interpreter is loaded each time a request is made, the
code is compiled and run on the fly, the content is delivered, and the whole
process shuts down again.</p>

<p>In FastCGI or mod_perl, the interpreter along with some compiled application
code can remain <em>persistent</em> in memory between requests, so just the run-time
effort needs to be done for each request. </p>

<p>For anything that&#8217;s particularly high traffic or a complex application to load,
the persistence feature will be a win. Performance is dramatically improved
because loading the interpreter is done once and the compile-time effort is not
repeated. </p>

<p>However, there are other considerations besides performance that still make vanilla
CGI the better option for some applications, particularly on low to moderate traffic applications.</p>

<p>In case there&#8217;s a lack of imagination about applications that may always be
small or low traffic, here&#8217;s some examples:</p>

<ul>
<li>A company provides a few dozen sales reps a private area to access
dynamically generated spreadsheets. As a private application with limited
users, traffic is always low. Beyond this, the company has a tiny web
presence.</li>
<li>A college has a customized online application to an off-campus program. Less
than 100 people submit the application each year.</li>
<li>A small business needs a customized contact form and a custom event
registration form. Each are expected to be used10 times per day or less</li>
<li>A university needs a public search engine for a database on a niche topic. </li>
</ul>

<p>I have helped build and deploy applications like each of the above in vanilla
CGI, with reasonable performance. There are many website needs out there which
are unique enough to merit custom programming but are neither large, nor destined to
become high traffic attractions.</p>

<p>This brings us to some specific benefits of vanilla CGI:</p>

<p><strong>Hosting Availability</strong>. Googling for &#8220;CGI Hosting&#8221; today I get 166,000 results,
but searching for &#8220;FastCGI hosting&#8221; I get just 225. Plain CGI hosting is far
more widely available. If you just need to add one dynamic form on your site
that is lightly used, do you want to switch hosts just for FastCGI support?
For low traffic applications, a FastCGI site could chew more memory while the
persistent part sites idle, while the equivalent CGI system would completely
free up the memory. A host can support more plain CGI customers (again,
assuming  low to moderate traffic), because their memory is constantly being
freed up for use for other customers. A persistent FastCGI process has an
persistent memory cost for the host. </p>

<p><strong>Persistence-specific bugs</strong>.  Generally, well written code will run in a
persistent environment with no problems. Still, there a number of hang-ups you
have to aware of which aren&#8217;t a concern in CGI scripts. Just look at the
extensive amount <a href="http://perl.apache.org/docs/1.0/guide/porting.html">details</a>
documented for people moving from vanilla CGI to mod_perl. It&#8217;s not that has to
be hard or time consuming to write Perl for persistent environments, but there
are clearly extra considerations. </p>

<p><strong>You can easily scale up, but not down</strong>. Using <a href="http://www.cgi-app.org/">CGI::Application</a> with it&#8217;s
built-in support for <a href="http://search.cpan.org/perldoc?CGI">CGI.pm</a> and <a href="http://search.cpan.org/perldoc?HTML::Template">HTML::Template</a>, you&#8217;ve got a great framework
of lightweight components for building applications that will perform well in vanilla CGI. They will
generally also work in a persistent environment without <em>any</em> changes. This is
what I do myself.  When a mod_perl project comes along,  it&#8217;s easy to scale up using Titanium with additional plugins to provide more features, with the same familiar
framework of CGI::Application underneath. On the other hand,  there&#8217;s the choice to develop by default with a framework designed for a persistent environment, like
<a href="http://www.catalystframework.org/">Catalyst</a>. II&#8217;m not aware of any of these heavier frameworks that
have an option to <em>scale down</em> in a way that performs well in plain CGI will
still retaining the same feel and features. Such a path is a commitment to either also deploy smaller, low-traffic applications in a persistence environment because the heavy framework requires it for decent performance, or you&#8217;ll need to learn a second framework just for small apps. I&#8217;d rather use one framework that performs well in both CGI and persistent environments.</p>

<p><strong>In summary: Simplicity</strong>. Vanilla CGI is the simplest to code for and deploy.
If performance is good enough, why not use the simpler option?</p>

<p><strong>Update</strong>&#8212; it was pointed out my examples of &#8220;low traffic&#8221; were all <em>very</em> low traffic. A more interesting question is what the upper limit for traffic is, before vanilla CGI performance degrades. My <a href="/blog/2008/11/startup-benchmarks-for-mojo-catalyst-titanium-httpengine-and-cgiapplication.html">recent benchmarks</a> inform this.  A &#8220;Hello World&#8221; CGI::Application project benchmarks at 0.20s. So, being very generous it&#8217;s reasonable to assume that a complete CGI script written this framework could be expected to be complete and shutdown in under a second. Which means a rough upper bound is 1 CGI request per second. Busy websites regulary exceed this request rate but I think that illustrates that vanilla CGI is a capable performer for many uses.</p>

<h2>See Also</h2>

<ul>
<li>Ian Bicking&#8217;s post <a href="http://blog.ianbicking.org/2008/01/12/what-php-deployment-gets-right/">What PHP Deployment Gets Right</a> pins some of PHP&#8217;s success on its CGI-like model. </li>
</ul>
]]>
    </content>
</entry>

<entry>
    <title>Startup benchmarks for Mojo, Catalyst, Titanium, HTTP::Engine, CGI::Application and CGI.pm</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2008/11/startup-benchmarks-for-mojo-catalyst-titanium-httpengine-and-cgiapplication.html" />
    <id>tag:mark.stosberg.com,2008:/blog//2.247</id>

    <published>2008-11-16T03:32:52Z</published>
    <updated>2008-12-01T22:55:31Z</updated>

    <summary>What&#8217;s the minimum time it could take a serve a web page using a given Perl-based solution using CGI? What&#8217;s the minimum amount of memory it would take? To check the relative differences between several options listed below, I made...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="titanium" label="Titanium" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="framework" label="framework" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mojo" label="mojo" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="web" label="web" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p>What&#8217;s the minimum time it could take a serve a web page using a given  Perl-based solution using CGI? What&#8217;s the minimum amount of memory it would take?</p>

<p>To check the relative differences between several options listed below, I made the simplest possible &#8220;Hello World&#8221; page, and benchmarked the time and memory used to serve it. To create a base line, I also measured the results for an empty Perl script that just prints &#8220;Hello World&#8221;.</p>

<p>The result summary is after the jump.</p>
]]>
        <![CDATA[<p>If it&#8217;s not already clear, these benchmarks are not meant to represent real world applications or web servers. Of course, physics dictate that would be difficult of any application to perform any <em>faster</em> than these times, using the same systems and hardware. </p>

<table border="0" style="margin-left: 10px">
<tr><th> System             </th><th> Version    </th><th>Startup*</th><th>Memory**</th></tr>
<tr><td><strong>Empty Script       </strong></td><td style="color:#BBBBBB"> Perl 5.8.8 </td><td> 0.01s </td><td>  4.7M  </td></tr>
<tr><td><strong>CGI::Simple</strong></td><td style="color:#BBBBBB"> 1.103       </td><td> 0.08s </td><td>  5.5M  </td></tr>
<tr><td><strong>CGI.pm             </strong></td><td style="color:#BBBBBB"> 3.42       </td><td> 0.11s </td><td>  5.7M  </td></tr>
<tr><td><strong>CGI::Application   </strong></td><td style="color:#BBBBBB"> 4.20       </td><td> 0.21s </td><td>  6.0M  </td></tr>
<tr><td><strong>Mojo               </strong></td><td style="color:#BBBBBB"> 0.8.9      </td><td> 0.29s </td><td>  8.3M  </td></tr>
<tr><td><strong>Mojolicious        </strong></td><td style="color:#BBBBBB"> 0.8.9      </td><td> 0.31s </td><td>  8.8M  </td></tr>
<tr><td><strong>Titanium           </strong></td><td style="color:#BBBBBB"> 1.0        </td><td> 0.14s </td><td>  6.0M  </td></tr>
<tr><td><strong>Titanium w/Dispatch</strong></td><td style="color:#BBBBBB"> 1.0        </td><td> 0.39s </td><td> 10.1M  </td></tr>
<tr><td><strong>Catalyst           </strong></td><td style="color:#BBBBBB"> 5.8000_03  </td><td> 0.80s </td><td> 13.5M  </td></tr>
<tr><td><strong>HTTP::Engine       </strong></td><td style="color:#BBBBBB"> 0.0.18     </td><td> 1.50s </td><td> 14.9M  </td></tr>
<tr><td><strong>HTTP::Engine/Shika</strong></td><td style="color:#BBBBBB"> 0.0.99_01 </td><td> 0.19s </td><td> 6.6M  </td></tr>
</table>

<div style="font-size: smaller; color:#777777">
* The &#8220;real&#8221; time in seconds as timed with `time -p perl foo.pl` on a 1.1 Ghz ThinkPad T23 laptop with Ubuntu 8.04 Linux.
** The virtual memory size when the script is about to exit, as timed by printing the output of this at the end of the script run: `ps -o pid,user,rss,vsize,ucomm -C perl`;
</div>

<p>Let&#8217;s go through some of the numbers. </p>

<p><a href="http://search.cpan.org/perldoc?CGI::Simple">CGI::Simple</a>, a lighter-weight CGI.pm alternative turns in the best time and memory consumption.  Before considering using it, note that it has a different interface in a few places, like file upload handling, and there are still some cases that CGI.pm can handle but it can&#8217;t, like <a href="http://rt.cpan.org/Public/Bug/Display.html?id=14838">some kinds of file uploads</a>. </p>

<p>Next there&#8217;s much-maligned <a href="http://search.cpan.org/perldoc?CGI">CGI.pm</a>, still appearing here with a respectable second-fastest start time and low memory consumption. Both CGI::Simple and CGI.pm help process an HTTP request and prepare an HTTP response, which is functionality targeted by most of the options listed here. </p>

<p><a href="http://www.cgi-app.org/">CGI::Application</a> is next on the list. It explicitly doesn&#8217;t provide any of the functionality of CGI.pm itself, and I don&#8217;t think CGI.pm would even be loaded for this bare-bones &#8220;Hello World&#8221; case. CGI::Application  provides basic application structure, control flow, and a callback system for plugins. As a long time user, It&#8217;s no surprise to confirm that CGi::Application is a very lightweight solution. </p>

<p><a href="http://www.mojolicious.org">Mojo</a> is next. It&#8217;s functionality includes supporting several server backends and abstracting the HTTP server response and request. This is a bit similar to what CGI.pm does, since CGI.pm also supports mod_perl and FastCGI as well has helping with the HTTP request and response. (Of course the Mojo and CGI approaches couldn&#8217;t be more different!). Mojo also provides a similar amount of functionality as HTTP::Engine.  Mojo&#8217;s result shows that it can be a rather lightweight solution itself, perhaps suitable for running in a CGI environment.  Overall, the performance of Mojo is impressive here.</p>

<p>Next up we have Mojolicious and Titanium, which had very similar speed benchmarks.  <a href="http://search.cpan.org/perldoc?Mojolicious">Mojolicious</a> adds dispatching and a file-extension based templating system to Mojo, including the ability to serve static pages and a simple built-in templating system. It&#8217;s perhaps similar to the amount of functionality that CGI::Application covers when combined with CGI.pm and HTML::Template, but again the approach is very different. </p>

<p>Of the group of systems tested here, I would say <a href="http://search.cpan.org/perldoc?Titanium">Titanium</a> covers the largest scope of functionality, since it goes beyond usual framework offerings, including additional methods for managing database handles, config files, sessions, form validation and form filling. I often run Titanium-style apps under CGI with good performance. In a persistent environment, the smaller memory footprint would be a more significant win here, allowing more application processes to be run concurrently. </p>

<p>Second to last on the list we have <a href="http://www.catalystframework.org/">Catalyst</a>, the Perl framework which needs no introduction.  It&#8217;s slower startup time is not particularly considered a concern here, as it is not targeted at being deployed in CGI environments. That it uses a bit more memory does show some kind of additional overhead, although for many deployments a bit extra memory per-process won&#8217;t matter. </p>

<p>Finally, taking far more time and still more memory, we have <a href="http://search.cpan.org/perldoc?HTTP::Engine">HTTP::Engine</a>. Considering its scope of functionality competes with Mojo, this performance and memory overhead is disappointing. HTTP::Engine explicitly has a CGI interface, but taking 1.5 seconds and almost 15 megs of memory just to print &#8220;Hello World&#8221; is dismal. <em>Update 12/1/2008-</em> HTTP::Engine replaced &#8220;Moose&#8221; with &#8220;Shika&#8221; and massive speed and memory gains, apparently without any reduction in functionality. The run time of 0.19 seconds and memory usage of 6.6 megs is rather respectable. </p>

<p>I can already anticipate the feedback to this article saying that the startup times don&#8217;t matter because much of this is compile-time work, which doesn&#8217;t apply to persistent-environments, because compilation would only then happen once at server start-up time, and is not per-request. And there&#8217;s the perception I expect to hear echo&#8217;ed back again: <em>No one uses straight CGI anymore, right?</em></p>

<p>As a professional website developer with over a decade of experience, nearly all the web applications I&#8217;ve written have run in CGI, and have performed just fine this way. Why do anything more complicated, when the simple solution works?</p>

<p>A web framework is a bit like an operating system, it&#8217;s there to prop up the layer where the real value-added work happens. For an OS, that&#8217;s the application. For a web-app, that&#8217;s the custom application logic.  If your web application is going to be slow and hog memory it  should because your custom application does that, not because the framework itself takes almost two seconds to boot up and uses 15 megabytes of memory before your application really gets started. </p>

<p>If your application is not expected to be high-traffic, several of the solutions mentioned here are candidates for running under CGI, saving the complexity and overhead of deploying in FastCGI or mod<em>perl. If you creating your applications with best practices like avoiding global variables, it will likely be easy to convert it to run under mod</em>perl or FastCGI later. </p>

<p>As a disclosure, some of the testing scripts I used are below. For Catalyst, Mojo, and Mojolicious, I used the default CGI scripts that came bundled with them. </p>

<p><strong>CGI.pm</strong></p>

<pre><code>use CGI;
my $q = CGI-&gt;new;
print $q-&gt;header;
print "Hello from CGI\n";
</code></pre>

<p><strong>CGI::Application</strong></p>

<pre><code>package HelloWorld;
use base 'CGI::Application';

sub setup {
    my $self = shift;
    $self-&gt;start_mode('hello_world');
    $self-&gt;run_modes([qw/hello_world/]);

}

sub hello_world {
    my $self = shift;
    return "Hello World\n".
}

HelloWorld-&gt;new-&gt;run;


# Titanium with Dispatching, dispatch.pl
use CGI::Application::Dispatch;
CGI::Application::Dispatch-&gt;dispatch(
    default =&gt; 'hello-world/hello_world',
);
</code></pre>

<p><strong>Titanium with Dispatching, HelloWorld.pm</strong></p>

<pre><code>package HelloWorld;
use base 'Titanium';

sub setup {
    my $self = shift;
    $self-&gt;start_mode('hello_world');
    $self-&gt;run_modes([qw/hello_world/]);

}

sub hello_world {
    my $self = shift;
    return "Hello World\n";     
}
1;


# HTTP::Engine
use HTTP::Engine;
my $engine = HTTP::Engine-&gt;new(
      interface =&gt; {
          module =&gt; 'CGI',
          request_handler =&gt; 'main::handle_request',
      },
  );
$engine-&gt;run;

sub handle_request {
      my $req = shift;
      HTTP::Engine::Response-&gt;new( body =&gt; "Hello from HTTP::Engine\n\n");
}
</code></pre>

<p><strong>Empty.pl</strong>l</p>

<pre><code>print "Hello World\n";
</code></pre>
]]>
    </content>
</entry>

<entry>
    <title>Review of  Mojo 0.8.7, a new Perl web framework</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2008/11/review-of-mojo-087-a-new-perl-web-framework.html" />
    <id>tag:mark.stosberg.com,2008:/blog//2.245</id>

    <published>2008-11-07T15:57:53Z</published>
    <updated>2008-11-08T03:01:00Z</updated>

    <summary> Here&#8217;s my take on Mojo 0.8.7, a new web framework for Perl. The primary author of Mojo, Sebastian Riedel was once as a primary contributor to Catalyst. There are clearly some similarities, and it&#8217;s easy for me to see...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="catalyst" label="Catalyst" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mojo" label="Mojo" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="framework" label="framework" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="web" label="web" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="Mojo Perl web framework logo" src="http://mark.stosberg.com/blog/images/mojo.png" width="210" height="86" class="mt-image-right" style="float: right; margin: 0 0 20px 20px;"  /></span></p>

<p>Here&#8217;s my take on <a href="http://mojolicious.org/">Mojo</a> 0.8.7, a new web framework
for Perl. </p>

<p>The primary author of Mojo, Sebastian Riedel was once as a primary contributor
to Catalyst. There are clearly some similarities, and it&#8217;s easy for me to
see Mojo as an evolution of Catalyst. </p>

<p>One major difference with Catalyst sparked my interest in Mojo. Catalyst now depends 
on Moose among other things, with a very long overall dependency change. How long?
I downloaded Catalyst 5.8 along with all of it&#8217;s non-core Perl module dependencies. 
The result was over <strong>250</strong> modules, not counting the Catalyst modules themselves,
or anything in the Test::* name space. Bleh. </p>

<p><em>What to see for yourself? Get
my &#8220;self-contained&#8221; patch out of the local::lib tracker and run the following.
It will install Catalyst and all it non-core dependencies into a &#8220;Catalyst&#8221;
folder. Be aware, this could take half an hour or more&#8230; (The TinyURL points a Catalyst 5.8 tarball)</em></p>

<pre><code>perl -MCPAN -Mlocal::lib=--self-contained,Catalyst  \ 
-e 'install "http://tinyurl.com/5hbzoo"'
</code></pre>

<p>Leaning on dependencies can be a great thing. It works well when you are able
to outsource part of your needs to an external module that is already well
written, documentation and tested. I&#8217;m sure there&#8217;s some of that happening in
the Catalyst dependency chain. But there&#8217;s also a good deal of duplication, as
different authors solve things different ways. For example: Exporter.pm,
Sub::Exporter and Moose::Exporter all serve the same function, and are
dependencies somewhere along the way. Class::Accessor::Fast competes with MooseX::Emulate::Class::Accessor::Fast. And this is where a long dependency
chain can start to look and feel like bloat, and it can be difficult to
overcome if the owners of the dependencies don&#8217;t share the projects preferences
about how to export subroutines or build accessors. </p>

<p>It could perhaps be said though that Mojo suffers from re-using too
little.  Mojo::Base is yet-another accessor-generation solution, like
Class::Accessor.  </p>

<p>The potential I see in Mojo is the summed up in the following:</p>

<ul>
<li>No dependency chain, for less complexity and easy deployment</li>
<li>Built-in support for several backends, for portability</li>
<li>A rewrite of HTTP request and response objects, as a sanely designed evolution of what CGI.pm has been used for</li>
<li>No ties to a specific framework design beneath the server/response-request object layer, for flexibility and potential code sharing between frameworks based on it. </li>
</ul>

<p>It is this last item that has allowed me to ignore the bundled Mojolicious framework for this review&#8212; It&#8217;s not required for use with Mojo and could use it&#8217;s own review. </p>

<p>Overall, I feel positive about the Mojo project, although I
have no current plans to quit developing with
<a href="http://search.cpan.org/dist/Titanium/lib/Titanium.pm">Titanium</a>-style projects
myself. In theory, they could be used together. Mojo could provide the backend-server support and query object, and CGI::Application could run inside the Mojo handler() in much the same way CGI::Application apps can run in a mod_perl handler. Now, CGI::Application can already run under various servers and with different query objects, so whether or not you&#8217;d actually want to use CGI::Application with Mojo is left up to the reader. </p>

<p>I don&#8217;t recommend using Mojo yet&#8212; it needs more documentation and tests for my taste.
It&#8217;s Mojo&#8217;s clean, scalable and extensible design that make it a project worth following. 
 I&#8217;ll be keeping my eye on Mojo. </p>

<p><em>This post is being <a href="http://www.reddit.com/r/programming/comments/7c2lj/review_of_mojo_087_a_new_perl_web_framework_mark/">discussed on reddit.com</a></em></p>
]]>
        

    </content>
</entry>

<entry>
    <title>Progress on making a self-contained Titanium distribution</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2008/09/progress-on-making-a-self-contained-titanium-distribution.html" />
    <id>tag:mark.stosberg.com,2008:/blog//2.227</id>

    <published>2008-09-28T01:24:07Z</published>
    <updated>2008-09-27T22:00:06Z</updated>

    <summary>Today I made progress on making a self-contained distribution of the Titanium web framework.The goal is to have a single archive file you can unpack and have a complete web framework to work with-- no more CPAN dependencies to install!...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p>Today I made progress on making a self-contained distribution of the <a href="http://search.cpan.org/perldoc">Titanium</a> web framework.</p><p>The goal is to have a single archive file you can unpack and have a complete web framework to work with-- no more CPAN dependencies to install! You can play with it on your desktop or laptop with the built-in web server, and upload a directory to your web server when you read to go live.</p><p>After I <a href="http://rt.cpan.org/Ticket/Display.html?id=39644">patched the great local::lib</a> module, I can now use this simple command to create a "Titanium" directory, into which Titanium and all of it's non-core dependencies will be installed.</p><p><code><br>perl -MCPAN -Mlocal::lib=--self-contained,Titanium -e 'install Titanium'<br></code></p><p>The next step is to hopefully eliminate required dependencies on XS code. The following  modules need to be address:</p><ul><li> Compress::Raw::Zlib </li><li> HTML::Parser </li><li> Params::Validate </li></ul><p>Params::Validate should be easy to handle, since it has a Pure Perl alternative. I haven't decided now to deal with the other two yet.</p><p>I can post an archive of what I have so far if it's of interest. The XS modules above are compiled for 'i486-linux-gnu-thread-multi'.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Devel::Declare: A good fit for .pmc files?</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2008/09/develdeclare-a-good-fit-for-pmc-files.html" />
    <id>tag:mark.stosberg.com,2008:/blog//2.226</id>

    <published>2008-09-25T18:17:50Z</published>
    <updated>2008-09-25T15:00:03Z</updated>

    <summary>Devel::Declare seems to be the new hotness, quickly inspiring several more modules to use it including Method::Signatures, MooseX::Method::Signatures, Sub::Curried, Sub::Auto, and CGI::Application::Plugin::RunmodeDeclare.But whose ready to run this hairy black magic and production? Perhaps this is good match for using .pmc...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p>Devel::Declare seems to be the new hotness, quickly inspiring several more modules to use it including <a href="http://search.cpan.org/perldoc?Method::Signatures">Method::Signatures</a>, <a href="http://search.cpan.org/perldoc?MooseX::Method::Signatures">MooseX::Method::Signatures</a>, <a href="http://search.cpan.org/perldoc?Sub::Curried">Sub::Curried, </a><a href="http://search.cpan.org/perldoc?Sub::Auto">Sub::Auto</a>, and <a href="http://www.erlbaum.net/pipermail/cgiapp/2008q3/000726.html">CGI::Application::Plugin::RunmodeDeclare</a>.</p><p>But whose ready to run this hairy black magic and production? Perhaps this is good match for using<nobr> <wbr></nobr><a href="http://search.cpan.org/perldoc?Module::Compile">.pmc files</a>?  If it works, it would mean that Devel::Declare is not actually used in production, but pure Perl ".pmc" file are used instead, which contains code that Devel::Declare generates.</p><p>Workable? Good idea?</p>]]>
        
    </content>
</entry>

<entry>
    <title>My favorite part of Perl 6 available now in Perl 5</title>
    <link rel="alternate" type="text/html" href="http://mark.stosberg.com/blog/2008/09/my-favorite-part-of-perl-6-available-now-in-perl-5.html" />
    <id>tag:mark.stosberg.com,2008:/blog//2.225</id>

    <published>2008-09-22T18:34:14Z</published>
    <updated>2008-09-22T15:00:04Z</updated>

    <summary>Perhaps my favorite parts of Perl 6 are subroutine signatures and getting rid of &quot;my $self = shift;&quot;.These features available now in Perl 5, without source filters, using Method::Signatures.Sure, it&apos;s labeled as &quot;ALPHA&quot; involves some dark magic to make it...</summary>
    <author>
        <name>Mark Stosberg</name>
        <uri>http://mark.stosberg.com/</uri>
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://mark.stosberg.com/blog/">
        <![CDATA[<p>Perhaps my favorite parts of Perl 6 are subroutine signatures and getting rid of "<code>my $self = shift;</code>".</p><p>These features available now in Perl 5, without source filters, using <a href="http://search.cpan.org/perldoc?Method::Signatures">Method::Signatures</a>.</p><p>Sure, it's labeled as "ALPHA" involves some dark magic to make it work, but it's there to play with. And if it can be hacked up as a module, surely it would be feasible to add to Perl 5.12....</p>]]>
        
    </content>
</entry>

</feed>
