<?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>patspam &#187; Perl</title>
	<atom:link href="http://blog.patspam.com/category/comp/perl/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.patspam.com</link>
	<description>patspam patspam patspam</description>
	<lastBuildDate>Fri, 18 Jun 2010 23:44:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=8093</generator>
		<item>
		<title>It&#8217;s official: WebGUI 8 will be Plack-powered</title>
		<link>http://blog.patspam.com/2010/its-official-webgui-8-will-be-plack-powered</link>
		<comments>http://blog.patspam.com/2010/its-official-webgui-8-will-be-plack-powered#comments</comments>
		<pubDate>Fri, 18 Jun 2010 23:44:02 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1392</guid>
		<description><![CDATA[Back in December 2009 I wrote about PlebGUI, an experimental branch of WebGUI with mod_perl replaced with Plack/PSGI. As a result, I was able to demonstrate WebGUI running on shared hosting via Plack + FastCGI. For the next few months I worked through the process of turning the proof of concept into something core-worthy. Primarily [...]]]></description>
			<content:encoded><![CDATA[<p>Back in December 2009 I wrote about <a href="http://blog.patspam.com/2009/plebgui-webgui-meets-plack">PlebGUI</a>, an experimental branch of <a href="http://webgui.org">WebGUI</a> with mod_perl replaced with <a href="http://plackperl.org">Plack/PSGI</a>. As a result, I was able to demonstrate WebGUI running on shared hosting via Plack + FastCGI.</p>
<p>For the next few months I worked through the process of turning the proof of concept into something core-worthy. Primarily that meant removing PlebGUI&#8217;s faked Apache2::Request object, completely eliminating any mod_perl dependencies from the WebGUI core and instead baking in WebGUI::Request and WebGUI::Response which are thin layers over <a href="http://search.cpan.org/perldoc?Plack::Request">Plack::Request</a> and <a href="http://search.cpan.org/perldoc?Plack::Response">Plack::Response</a>.</p>
<p>By about April most of the basic pieces were in place, performance was looking good, and I&#8217;d started the fun task of refactoring WebGUI to take advantage of the value-add features that Plack brings such as Middleware and stealing liberally from other Plack projects such as <a href="http://search.cpan.org/perldoc?Tatsumaki">Tatsumaki</a>&#8216;s streaming API. But there was still lots of work to be done getting the test suite passing again and smoothing off the rough edges. Progress was slow due to my work commitments and frequent travel.</p>
<p>Then three of the main WebGUI committers got involved, first <a href="http://github.com/haarg">haarg</a>++, then <a href="http://www.perldreamer.com/blog">perlDreamer</a>++ and <a href="http://github.com/preaction">preaction</a>++. The pace accelerated dramatically. This week we officially merged the PSGI branch into the <a href="http://github.com/plainblack/webgui/tree/WebGUI8">main development branch</a>, <strong>meaning that the next major release of WebGUI will officially be a PSGI app!</strong></p>
<p>Huge credit and thanks to haarg, perlDreamer and preaction (and anyone else who contributed too) for getting us over the hump. These guys are also the main driving force behind <a href="http://www.webgui.org/8">the other awesome features</a> that are being baked into WebGUI 8, so if you like anything you see in the next version, make sure you buy them a beer or two.</p>
<p>Here are some screenshots of WebGUI with the <a href="http://search.cpan.org/perldoc?Plack::Middleware::Debug">Plack::Middleware::Debug</a> bar turned on.</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2010/06/show-debug.png"><img class="aligncenter size-medium wp-image-1398" title="show-debug" src="http://blog.patspam.com/wp-content/uploads/2010/06/show-debug-300x108.png" alt="" width="300" height="108" /></a></p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2010/06/webgui-psgi.png"><img class="aligncenter size-medium wp-image-1399" title="webgui-psgi" src="http://blog.patspam.com/wp-content/uploads/2010/06/webgui-psgi-267x300.png" alt="" width="267" height="300" /></a></p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2010/06/asset-performance.png"><img class="aligncenter size-medium wp-image-1400" title="asset-performance" src="http://blog.patspam.com/wp-content/uploads/2010/06/asset-performance-300x62.png" alt="" width="300" height="62" /></a></p>
<p>Previously, in debug mode WebGUI would append all debug output to the bottom of the page. Now, thanks to haarg&#8217;s custom Plack::Middleware::Debug panels, debug messages are contained within the &#8220;Logger&#8221; panel. Notice also the &#8220;Asset Performance&#8221; panel, which displays WebGUI::Asset performance metrics. This is only the beginning.</p>
<p>It&#8217;s such a buzz to have the PSGI branch merged in; now the real fun starts! I&#8217;ll be speaking about the WebGUI PSGI branch at the WebGUI User Conference in Madison in September, and at the rate things are going, who knows how much fun stuff we&#8217;ll be able to show off..</p>
<p>I&#8217;m also really looking forward to attending YAPC::NA next week (my first YAPC on American soil) and meeting/hanging out with lots other people who have been doing awesome things in the Perl web app space (and beyond). Vive la renaissance Perl!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2010/its-official-webgui-8-will-be-plack-powered/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plack Apps in Javascript</title>
		<link>http://blog.patspam.com/2010/plack-apps-in-javascript</link>
		<comments>http://blog.patspam.com/2010/plack-apps-in-javascript#comments</comments>
		<pubDate>Thu, 17 Jun 2010 16:03:40 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1384</guid>
		<description><![CDATA[Love Plack web apps but feel like writing some Javascript today instead of Perl? # app.psgi use Plack::App::JSP; Plack::App::JSP-&#62;new( js =&#62; q{ [ 200, [ 'Content-type', 'text/html' ], [ 'Hello, World!' ] ] }); # displays: Hello, World! Given the similarities between Perl and JSON you can&#8217;t actually tell if I&#8217;m cheating or not from [...]]]></description>
			<content:encoded><![CDATA[<p>Love <a href="http://plackperl.org/">Plack web apps</a> but feel like writing some Javascript today instead of Perl?</p>
<pre class="brush: perl;">
# app.psgi
use Plack::App::JSP;
Plack::App::JSP-&gt;new( js =&gt; q{
[ 200, [ 'Content-type', 'text/html' ], [ 'Hello, World!' ] ]
});

# displays: Hello, World!
</pre>
<p>Given the similarities between Perl and JSON you can&#8217;t actually tell if I&#8217;m cheating or not from the above snippet. </p>
<p>Let&#8217;s try something more convincing:</p>
<pre class="brush: perl;">
Plack::App::JSP-&gt;new( js =&gt; q{
function respond(body) {
    return [ 200, [ 'Content-type', 'text/html' ], [ body ] ]
}

respond(&quot;Five factorial is &quot; +
    (function(x) {
      if ( x&lt;2 ) return 1;
      return x * arguments.callee(x - 1);
    })(5)
);
});

# displays: Five factorial is 120
</pre>
<p>I just pushed <a href="http://search.cpan.org/perldoc?Plack::App::JSP">Plack::App::JSP</a> to the CPAN.<br />
Thanks to Salvador Ortiz and Miguel Ibarra whose recently released <a href="http://search.cpan.org/perldoc?JSP">JSP</a> module makes this possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2010/plack-apps-in-javascript/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Serve up Dancer webapps for six bucks</title>
		<link>http://blog.patspam.com/2010/serve-up-dancer-webapps-for-six-bucks</link>
		<comments>http://blog.patspam.com/2010/serve-up-dancer-webapps-for-six-bucks#comments</comments>
		<pubDate>Tue, 01 Jun 2010 18:36:04 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Sys Admin]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1368</guid>
		<description><![CDATA[After a few weeks of mulling over the Perl Shared Hosting idea, a few enthusiastic messages from people and getting inspired by chromatic musing about a similar idea for a Perl Cookbook, I decided to JFDI. So, perlsharedhosting.com is now officially up and running. Rather than wasting my time building a web app for the site [...]]]></description>
			<content:encoded><![CDATA[<p>After a few weeks of <a href="http://blog.patspam.com/2010/perlsharedhosting">mulling over the Perl Shared Hosting idea</a>, a few enthusiastic messages from people and getting inspired by chromatic musing about a <a href="http://www.modernperlbooks.com/mt/2010/05/a-modern-perl-fakebook.html">similar idea for a Perl Cookbook</a>, I decided to JFDI.</p>
<p>So, <a href="http://perlsharedhosting.com/">perlsharedhosting.com</a> is now officially up and running.</p>
<p>Rather than wasting my time building a web app for the site before the idea has been proven, I decided to use a simple CMS and focus my energies on the content instead (there&#8217;s a wonderful irony in using a PHP CMS to deliver content about Perl shared hosting..).</p>
<p>I&#8217;ve added quick-start guides on how to install the following core technologies on your shared hosting account:</p>
<ul>
<li><a href="http://perlsharedhosting.com/tech/locallib">local::lib</a></li>
<li><a href="http://perlsharedhosting.com/tech/cpanminus">cpanminus</a></li>
<li><a href="http://perlsharedhosting.com/tech/taskkensho">Task::Kensho</a> (the &#8220;We support modern Perl&#8221; badge of honour for hosting providers)</li>
<li><a href="http://perlsharedhosting.com/tech/plack">Plack</a></li>
<li><a href="http://perlsharedhosting.com/tech/dancer">Dancer</a></li>
</ul>
<p>These pages are not in any way supposed to replace the official documentation sources. Ideally, they just tell you what the tool/lib  is, why you need it, and how to install it with minimum fuss. In reality, we also need to list any issues you may run into when using them in a shared hosting environment, but the idea is that we feed this information back to the upstream projects so that workarounds become unnecessary.</p>
<p>I&#8217;ve tested two different hosting providers, neither of which I&#8217;m going to mention by name here because I&#8217;m not trying to actually promote their brand.</p>
<ul>
<li>The <a href="http://perlsharedhosting.com/hosting-providers/shared/hostingzoom">first one</a> had a major limitation &#8211; no access to <strong>cc</strong> and hence the inability to compile XS modules (their tech support has offered to install CPAN modules on request, but it&#8217;s less than ideal).</li>
<li>The <a href="http://perlsharedhosting.com/hosting-providers/shared/hostmonster">second one</a> has so far passed all tests with flying colours &#8211; &#8220;cpanm Task::Kensho&#8221; works flawlessly, including all the XS modules. This is perhaps not all that surprising given that this is the same hosting provider that I used last year to get <a href="http://blog.patspam.com/2009/plebgui-webgui-meets-plack">WebGUI running under PSGI on a shared account</a>.</li>
</ul>
<p>I started playing with Dancer for the first time, and soon had live demos of Dancer running in both <a href="http://hostmonster.perlsharedhosting.com/">CGI</a> and <a href="http://hostmonster.perlsharedhosting.com/fcgi/">FastCGI</a> modes. Those URLs will change in the future but the idea is that we set up live versions of each web framework running on each hosting provider. Maybe in the future we could use a monitoring service to track the reliability and response time of each combination.</p>
<p>So already, the Perl Shared Hosting site has step-by-step instructions for how to run Dancer web apps on a shared hosting account for less than six bucks per month. That&#8217;s not half bad.</p>
<p>If you have a shared hosting account on a provider that isn&#8217;t listed (or you work for a shared hosting company and want to get yourself listed) then please <a href="http://perlsharedhosting.com/contact">contact me</a> to get involved.</p>
<p>Next up, we need to add more information about resource limits. I also plan on adding more web frameworks such as <a href="http://search.cpan.org/perldoc?Web::Simple">Web::Simple</a>, <a href="http://mojomojo.org/">MojoMojo</a>, <a href="http://www.catalystframework.org/">Catalyst</a>, <a href="http://search.cpan.org/perldoc?Tatsumaki">Tatsumaki</a>, ..</p>
<p>Once we have an idea about what features are most important, I&#8217;d like to then turn it around and start contacting the providers to ask them if they will add support for certain features to match (or beat) their competitors. I think there&#8217;s real potential for communicating back to the shared hosting providers that there&#8217;s a large market for modern Perl hosting, and ideally, what features we need/want. The site may also be useful for feeding back to the Perl toolchain/framework people what rough edges people are running into in shared environments.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2010/serve-up-dancer-webapps-for-six-bucks/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Shout-out to the translators</title>
		<link>http://blog.patspam.com/2010/shout-out-to-the-translators</link>
		<comments>http://blog.patspam.com/2010/shout-out-to-the-translators#comments</comments>
		<pubDate>Wed, 12 May 2010 19:10:10 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1362</guid>
		<description><![CDATA[This morning I had an email from someone in the ExtJS community letting me know that they&#8217;d translated my Extending Ext Components article into German. I had a look and all of my ExtJS articles have been translated into at least one other language. My record is Playing With ExtJS The Easy Way which has [...]]]></description>
			<content:encoded><![CDATA[<p>This morning I had an email from someone in the ExtJS community letting me know that they&#8217;d translated my <a href="http://www.extjs.com/learn/Manual:Component:Extending_Ext_Components">Extending Ext Components</a> article into German. I had a look and <a href="http://www.extjs.com/learn/Manual:RESTful_Web_Services">all</a> <a href="http://www.extjs.com/learn/Manual:Ext_Source_Overview">of</a> <a href="http://www.extjs.com/learn/Manual:Intro:Patterns:Flyweight">my</a> <a href="http://www.extjs.com/learn/Manual:Intro:Inheritance">ExtJS</a> <a href="http://www.extjs.com/learn/Manual:Core:Working_with_JSON">articles</a> <a href="http://www.extjs.com/learn/Tutorial:Playing_With_Ext_The_Easy_Way">have</a> been translated into at least one other language. My record is <a href="http://www.extjs.com/learn/Tutorial:Playing_With_Ext_The_Easy_Way">Playing With ExtJS The Easy Way</a> which has been translated into 10 different languages: Deutsch, Chinese,  Korean,  Japanese, French, Russian, Spanish, Turkish, Portuguese and Hungarian. Page views of the English versions of these articles are just about to tick over the 500,000 mark.</p>
<p>Recently <a href="http://search.cpan.org/perldoc?Padre::Plugin::Plack">Padre::Plugin::Plack</a>, my <a href="http://plackperl.org">Plack</a> (the Perl Web Server) plugin for <a href="http://padre.perlide.org/">Padre</a> (the Perl IDE) was translated into Dutch, Brazilian Portuguese and French.</p>
<p>I always get such a buzz when I find out that something I&#8217;ve worked on has been translated into another language. It sends a clear message that someone found your work useful enough to go to the effort of translating it so that a new community of people could use it. That&#8217;s an awesome form of positive feedback, and a great motivator for being involved in open source software.</p>
<p>Thanks translators!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2010/shout-out-to-the-translators/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Plack Middleware for your iPhone</title>
		<link>http://blog.patspam.com/2010/plack-middleware-for-your-iphone</link>
		<comments>http://blog.patspam.com/2010/plack-middleware-for-your-iphone#comments</comments>
		<pubDate>Tue, 23 Mar 2010 17:02:25 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Comp]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1341</guid>
		<description><![CDATA[I started playing with HTML5 iPhone apps this week, and as a result there is a new piece of Plack middleware sitting on CPAN called Plack::Middleware::iPhone. It&#8217;s a (borderline ACME) module that rewrites html on the fly to make it play nicer with iPhones. Here&#8217;s a silly example: # A Perl one-liner for the iPhone [...]]]></description>
			<content:encoded><![CDATA[<p>I started playing with <a href="http://www.quirksmode.org/blog/archives/2010/03/html5_apps.html">HTML5 iPhone apps</a> this week, and as a result there is a new piece of <a href="http://plackperl.org">Plack</a> middleware sitting on CPAN called <a href="http://search.cpan.org/perldoc?Plack::Middleware::iPhone">Plack::Middleware::iPhone</a>. It&#8217;s a (borderline ACME) module that rewrites html on the fly to make it play nicer with iPhones.</p>
<p>Here&#8217;s a silly example:</p>
<pre class="brush: bash;">

# A Perl one-liner for the iPhone generation
plackup -MPlack::App::Directory -e 'builder {enable iPhone; Plack::App::Directory-&gt;new}'
</pre>
<p>That makes your current directory browsable as a web app, with some special iPhone meta tags injected so that the viewport is appropriately resized &amp; fullscreen mode is enabled when you launch your &#8220;app&#8221; from your Home Screen.</p>
<p>Here&#8217;s a slightly more usable one &#8211; your own personal mobile.search.cpan.org:</p>
<pre class="brush: bash;">

plackup -MPlack::App::Proxy -e 'builder {enable iPhone; Plack::App::Proxy-&gt;new(remote =&gt; &quot;http://search.cpan.org/&quot;) }'
</pre>
<p>You can customise things too:</p>
<pre class="brush: perl;">
# app.psgi
use Plack::Builder;
use Plack::App::Proxy;
builder {
    enable &quot;iPhone&quot;,
        statusbar =&gt; 'black-translucent', # transparent status bar
        startup_image =&gt; 'loading.png', # displayed as the app loads
        icon =&gt; 'icon.png'; # cutom app shortcut icon
    Plack::App::Proxy-&gt;new(remote =&gt; &quot;http://search.cpan.org/&quot;);
};
</pre>
<p>Here&#8217;s an actual app that I have running on my phone to display the New York subway map (images courtesy of the <a href="http://www.mta.info/nyct/maps/submap.htm">MTA</a> website):</p>
<pre class="brush: xml;">
&lt;!-- index.html --&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;NYC Map&lt;/title&gt;
        &lt;style&gt;
            body, img { margin: 0; padding: 0; }
        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;script&gt;
            window.scrollTo(300, 700); // Initially zoom in on my local area
        &lt;/script&gt;
        &lt;img src=&quot;sub1a.gif&quot;&gt;
        &lt;img src=&quot;sub2a.gif&quot;&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<pre class="brush: perl;">
# app.psgi
use Plack::App::Directory;
builder {
    enable &quot;iPhone&quot;,
        icon =&gt; 'icon.png',
        manifest =&gt; 1,
        viewport =&gt; 'initial-scale = 1, maximum-scale = 1.5, width = device-width',
        statusbar =&gt; 'black-translucent',
        startup_image =&gt; 'loading.png';
    Plack::App::Directory-&gt;new;
};
</pre>
<p>Use plackup to run the site on your local network, connect via Safari on your iPhone (via wifi) and then use the &#8220;Add to Home Screen&#8221; option to add an app shortcut to it on your phone. Your 57&#215;57 icon.png image will be used as the app icon, and your 320&#215;460 loading image will appear as the app loads. The viewport string sets the initial zoom scale and limits how far in the user can zoom. Nice and shiny.</p>
<p>With the <strong>manifest </strong>option enabled, <a href="http://search.cpan.org/perldoc?Plack::Middleware::iPhone">Plack::Middleware::iPhone</a> automatically generates a manifest file and injects the appropriate html to enable <a href="http://www.w3.org/TR/offline-webapps/">HTML5 offline web app caching</a> on your iPhone. This means that your app keeps working once you Ctrl-C the plackup server and walk out your front door. And it keeps on working when you&#8217;re stuck in the New York subway system without phone reception, trying to figure out what train you&#8217;re supposed to catch to get home.</p>
<p>If you&#8217;ve just started exploring how to build iPhone apps with web technologies, I suggest you check out Jonathan Stark&#8217;s book &#8220;Building iPhone Apps with HTML, CSS, and JavaScript&#8221; (online <a href="http://building-iphone-apps.labs.oreilly.com">here</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2010/plack-middleware-for-your-iphone/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PerlSharedHosting</title>
		<link>http://blog.patspam.com/2010/perlsharedhosting</link>
		<comments>http://blog.patspam.com/2010/perlsharedhosting#comments</comments>
		<pubDate>Mon, 08 Mar 2010 01:23:45 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Comp]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1327</guid>
		<description><![CDATA[Latest Web::Simple master (git://git.shadowcat.co.uk/catagits/Web-Simple.git) is now using Plack, the perl web server directly for CGI and FastCGI and I hope do do another release shortly with notes on deploying as both on shared hosts (more specifically Dreamhost but with an invitation to bitch if they don&#8217;t work on other budget hosts). mst,  &#8221;Oh Subdispatch, Oh Subdispatch&#8220; Every [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Latest Web::Simple master (git://git.shadowcat.co.uk/catagits/Web-Simple.git) is now using <a href="http://plackperl.org/">Plack, the perl web server</a> directly for CGI and FastCGI and I hope do do another release shortly with notes on deploying as both on shared hosts (more specifically <a href="http://www.dreamhost.com/">Dreamhost</a> but with an invitation to bitch if they don&#8217;t work on other budget hosts).</p>
<p style="text-align: right;">mst,  &#8221;<a href="http://www.shadowcat.co.uk/blog/matt-s-trout/oh-subdispatch-oh-subdispatch/">Oh Subdispatch, Oh Subdispatch</a>&#8220;</p>
</blockquote>
<p style="text-align: left;">Every time someone mentions a cool new web framework like <a href="http://search.cpan.org/perldoc?Web::Simple">Web::Simple</a>, <a href="http://perldancer.org/">Dancer</a> or <a href="http://search.cpan.org/perldoc?Tatsumaki">Tatsumaki</a>, my immediate reaction is to start thinking up cool little niche web apps I could build with it. You know, the kind you imagine yourself whipping up during your lunch break, that will probably never get more than 10 curious users but just might turn into the next big thing if only you got it up and running on a public server. And that&#8217;s when the second thought immediately arrives: where am I going to run this thing? Do I really think the idea has enough legs to justify paying for a virtual server plan? Can I be bothered going through the pain of figuring out how to deploy it on a shared hosting provider? And normally that&#8217;s the point where I sigh wistfully and go back to reading my RSS feeds.</p>
<p style="text-align: left;">The thing is, with the advent of things like <a href="http://search.cpan.org/perldoc?local::lib">local::lib</a> it&#8217;s getting a lot easier to deploy Perl web apps on shared hosting. And with most web frameworks adopting <a href="http://plackperl.org/">Plack/PSGI</a>, the work required to deploy Perl web apps on budget hosts is converging into a similar sequence of steps.</p>
<p style="text-align: left;">So this time during my lunch break I started envisaging a centralised, SEO-friendly information source (hello <a href="http://perlsharedhosting.com">perlsharedhosting.com</a>) that cobbles together all of the currently available information into an easy to digest form to make it ridiculously easy to choose a shared hosting provider, deploy your web app and troubleshoot common problems.</p>
<p style="text-align: left;">A site that works like this:</p>
<ul>
<li>The front page contains a list of Perl-friendly hosting providers, with a meta-score based on how many features they support (+) and how many unresolved issues they have (-), and maybe user review scores thrown into the mix too</li>
<li>Each hosting provider has a page of its own, listing in full which features are supported (used to compute the meta-score). Users can post comments on each of these pages, to leave testimonials (&#8220;I am currently running a Web::Simple site that gets x hits per hour on this host&#8221;) and note unresolved issues (&#8220;module X::Y fails to install on this host&#8221;). As issues get solved these become tips.</li>
<li>Each technology/feature/technique also gets a page of its own, with links to the official man pages, shared-hosting specific notes and again user comments
<ul>
<li>dependency related: <a href="http://search.cpan.org/perldoc?local::lib">local::lib</a>, cpan, <a href="http://search.cpan.org/perldoc?App::cpanminus">cpanm</a>, ..</li>
<li>environment related: locating and running perl, paths, daemons, viewing error output, ..</li>
<li>web deployment related: CGI, FastCGI, ..</li>
<li>framework / web app related: <a href="http://search.cpan.org/perldoc?Web::Simple">Web::Simple</a>, <a href="http://perldancer.org/">Dancer</a>, <a href="http://mojomojo.org/">MojoMojo</a>, <a href="http://www.catalystframework.org/">Catalyst</a>, <a href="http://search.cpan.org/perldoc?Tatsumaki">Tatsumaki</a>, ..</li>
</ul>
</li>
</ul>
<p>I haven&#8217;t decided yet what engine would fit best.. <a href="http://mojomojo.org/">MojoMojo</a> is a front-runner, and in fact the <a href="http://wiki.catalystframework.org/wiki/hosting">Catalyst Friendly Hosting</a> page runs on <a href="http://mojomojo.org/">MojoMojo</a> does a large chunk of what I&#8217;ve described above.</p>
<p>The site would be very &#8220;cookbook&#8221; oriented, since we&#8217;re specifically targeting people who can&#8217;t be bothered learning the ins and outs of 10 different technologies (not to mention figuring out how to get them to play nicely together) for the sake of deploying toy web applications on cheap shared hosting. Just the essentials: this is what you need, this is how you achieve it. And if you want to learn more, go here.</p>
<p>With that in place, we&#8217;d end up with a single, visible, place to research and document the complications of running Perl web apps on shared hosting. And if the site became popular, hosting providers might even take notice and start offering more Perl-friendly shared environments. We could have live demo pages running on different hosts, possibly even donated by hosting providers if they see it as a way of showcasing their Perl-friendliness (mojomojo.dreamhost.perlsharedhosting.com, dancer.resellerzoom.perlsharedhosting.com, etc..).</p>
<p>I got as far as registering the <a href="http://perlsharedhosting.com">domain name</a>; I was planning on getting a simple <a href="http://mojomojo.org/">MojoMojo</a> prototype up and running, but I got side-tracked researching how to deploy it on my shared hosting account&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2010/perlsharedhosting/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Padre::Plugin::Plack</title>
		<link>http://blog.patspam.com/2009/padrepluginplack</link>
		<comments>http://blog.patspam.com/2009/padrepluginplack#comments</comments>
		<pubDate>Wed, 23 Dec 2009 15:22:42 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Comp]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1301</guid>
		<description><![CDATA[In conjunction with today&#8217;s Christmas release of Padre, I&#8217;d like to announce my latest Padre plugin: Padre::Plugin::Plack. As the name suggests, Padre::Plugin::Plack adds Plack awareness to Padre. With the plugin installed, opening *.psgi files causes some special things to happen. PSGI files are really just ordinary Perl files, so Padre does its normal Perl lexing/syntax highlighting [...]]]></description>
			<content:encoded><![CDATA[<p>In conjunction with today&#8217;s <a href="http://mail.perlide.org/pipermail/padre-dev/2009-December/001451.html">Christmas release</a> of <a href="http://padre.perlide.org">Padre</a>, I&#8217;d like to announce my latest Padre plugin: <a href="http://search.cpan.org/search?query=Padre::Plugin::Plack">Padre::Plugin::Plack</a>.</p>
<p>As the name suggests, Padre::Plugin::Plack adds <a href="http://plackperl.org">Plack</a> awareness to Padre. With the plugin installed, opening *.psgi files causes some special things to happen. PSGI files are really just ordinary Perl files, so Padre does its normal Perl lexing/syntax highlighting magic on them, but the real fun starts with the Plack-specific features that appear in the per-file graphical <a href="http://search.cpan.org/search?query=plackup">plackup</a> control panel that shows up. The panel lets you run your web app in a Plack server at the click of a button, view server output, configure plackup options and launch a web browser on the appropriate port.</p>
<div><a href="http://blog.patspam.com/wp-content/uploads/2009/12/1.png"><img class="aligncenter size-medium wp-image-1304" title="Padre::Plugin::Plack panel" src="http://blog.patspam.com/wp-content/uploads/2009/12/1-300x142.png" alt="" width="300" height="142" /></a></div>
<p>The great thing about Plack/<a href="http://search.cpan.org/search?query=psgi">PSGI</a> is that unlike my <a href="http://blog.patspam.com/2009/padrepluginwebgui">previous</a> plugin (<a href="http://search.cpan.org/search?query=Padre::Plugin::WebGUI">Padre::Plugin::WebGUI</a>) which was specific to a single web app (albeit a <a href="http://webgui.org">big one</a>), this plugin can be used for any web app built in a <a href="http://plackperl.org/#frameworks">web framework that supports Plack</a> (<a href="http://www.catalystframework.org/">Catalyst</a>, <a href="http://cgi-app.org/">CGI::Application</a>, <a href="http://search.cpan.org/dist/HTTP-Engine">HTTP::Engine</a>, etc..). This potential for cross-framework application is one of the motivating factors that makes developing Plack modules (<a href="http://plackperl.org/#middlewares">Middleware</a> etc..) so much fun.</p>
<p>The plugin turns on plackup&#8217;s &#8220;&#8211;reload&#8221; option by default, which conveniently causes the plack server to reload every time you modify your source files in Padre. This makes for quite a nice, if somewhat minimal &#8220;Plack IDE&#8221; experience (this is version 0.01 after all).</p>
<p>The plugin integrates all of the Plack example &#8220;dot-psgi&#8221; files as templates that can be used to create different types of Plack apps straight from the GUI menu.</p>
<div><a href="http://blog.patspam.com/wp-content/uploads/2009/12/2.png"><img class="aligncenter size-medium wp-image-1305" title="Padre::Plugin::Plack new file templates" src="http://blog.patspam.com/wp-content/uploads/2009/12/2-300x214.png" alt="" width="300" height="214" /></a></div>
<p>The pre-populated list of Plack servers and the simple start/stop button makes for a nice way of exploring the Plack server ecosystem. You can use the other panel options to enter a specific port to run on, toggle auto-start mode and pass additional options to plackup (options that start with &#8220;&#8211;&#8221; are passed through to the backend server).</p>
<div><a href="http://blog.patspam.com/wp-content/uploads/2009/12/3.png"><img class="aligncenter size-medium wp-image-1306" title="Padre::Plugin::Plack server options" src="http://blog.patspam.com/wp-content/uploads/2009/12/3-300x227.png" alt="" width="300" height="227" /></a></div>
<p>The output panel is similar to the output panel that Padre normally displays when you execute Perl files, except that you get one panel per .psgi file meaning that you can run multiple plack servers simultaneously and independently view their output. The appropriate panel is automatically selected when you click on the corresponding file tab, and running processes are stopped when you close the tab.</p>
<p>It should be really easy to turn Padre::Plugin::Plack into new plugins that involve the same basic ingredients, namely  a file extension and an external command for running those files, with a per-file panel for command options and output. So I encourage anyone who has a similar plugin in mind to steal liberally from Padre::Plugin::Plack (as I did from Padre::Plugin::Catalyst &#8211; thanks garu++). Ruby Rack support comes to mind as a trivial example.</p>
<p>Make Padre your domain-specific IDE today <img src='http://blog.patspam.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2009/padrepluginplack/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plack helps with Javascript development too</title>
		<link>http://blog.patspam.com/2009/plack-helps-with-javascript-development-too</link>
		<comments>http://blog.patspam.com/2009/plack-helps-with-javascript-development-too#comments</comments>
		<pubDate>Fri, 18 Dec 2009 19:23:36 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Comp]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1291</guid>
		<description><![CDATA[Today I was debugging a Javascript bug in ExtJS + AIR, and I wanted to check rendering in another browser. I created a static html file with the minimal javascript test case embedded in it, but then realised that I needed to load in the ExtJS files from somewhere. With other JS libraries you can [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was debugging a Javascript bug in ExtJS + AIR, and I wanted to check rendering in another browser. I created a static html file with the minimal javascript test case embedded in it, but then realised that I needed to load in the ExtJS files from somewhere. With other JS libraries you can use <a href="http://code.google.com/apis/ajaxlibs/">freely available CDNs</a> for this sort of thing, but because ExtJS has funky ideas about licensing, this isn&#8217;t an option. What I needed was a quick and easy way to serve up the ExtJS files, which were sitting in a folder on my computer, over http. This sort of thing happens frequently with custom code too, when you attempt to create a static (minimal test case) version of a live site.</p>
<p>Plack has a really neat solution to this problem.</p>
<p>Following a tip from <a href="http://advent.plackperl.org/2009/12/day-5-run-a-static-file-web-server-with-plack.html">day #5 of Miyagawa&#8217;s Plack advent calendar</a>, serving up the current directory over http is as simple as this Perl one-liner:</p>
<pre class="brush: bash;">

$ plackup -MPlack::App::Directory -e 'Plack::App::Directory-&gt;new

Plack::Server::Standalone: Accepting connections at http://0:5000/
</pre>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 91px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">$ plackup -MPlack::App::Directory -e &#8216;Plack::App::Directory-&gt;new&#8217;Plack::Server::Standalone: Accepting connections at http://0:5000/$ plackup -MPlack::App::Directory -e &#8216;Plack::App::Directory-&gt;new&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 91px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Plack::Server::Standalone: Accepting connections at http://0:5000/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 91px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"># Or if you need the files over port 80:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 91px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">$ sudo plackup -MPlack::App::Directory -e &#8216;Plack::App::Directory-&gt;new&#8217; -p 80</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 91px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Plack::Server::Standalone: Accepting connections at http://0:80/</div>
<p>Or if you need the files served over port 80:</p>
<pre class="brush: bash;">

$ sudo plackup -MPlack::App::Directory -e 'Plack::App::Directory-&gt;new' -p 80

Plack::Server::Standalone: Accepting connections at http://0:80/
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2009/plack-helps-with-javascript-development-too/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plack roundup at SF.pm</title>
		<link>http://blog.patspam.com/2009/plack-roundup-at-sf-pm</link>
		<comments>http://blog.patspam.com/2009/plack-roundup-at-sf-pm#comments</comments>
		<pubDate>Sun, 29 Nov 2009 18:50:57 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Comp]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1271</guid>
		<description><![CDATA[Miyagawa has posted up a screencast of his recent PSGI/Plack talk at SF.pm. I highly recommend it if you&#8217;re still getting your head round the whole PSGI/Plack thing or you want to watch a nice recap of recent developments. I got a kick out of seeing Miyagawa pull up my blog post on PlebGUI in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bulknews.vox.com/">Miyagawa</a> has <a href="http://bulknews.typepad.com/blog/2009/11/plack-and-psgi-screencast-and-feedbacks.html">posted up a screencast</a> of his recent <a href="http://plackperl.org/">PSGI/Plack</a> talk at <a href="http://sf.pm.org/">SF.pm</a>. I highly recommend it if you&#8217;re still getting your head round the whole PSGI/Plack thing or you want to watch a nice recap of recent developments.</p>
<p>I got a kick out of seeing Miyagawa pull up my <a href="http://blog.patspam.com/2009/plebgui-webgui-meets-plack">blog post on PlebGUI</a> in response to someone&#8217;s question about porting mod_perl applications (e.g. apps that pass around an Apache <strong>$r</strong> object) to Plack. For the sake of the guy who asked the question, the way I did it (at least for the first pass) should be equally viable for other mod_perl applications &#8211; just <a href="http://github.com/pdonelan/webgui/blob/plebgui/lib/WebGUI/Session/Plack.pm">create</a> a fake Apache $r object that delegates everything to <a href="http://github.com/miyagawa/Plack-Request/blob/master/lib/Plack/Request.pm">Plack::Request</a> and <a href="http://github.com/miyagawa/Plack-Request/blob/master/lib/Plack/Response.pm">Plack::Response</a> (your mileage will obviously vary depending on how much of the mod_perl API your app uses).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2009/plack-roundup-at-sf-pm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PlebGUI: WebGUI Meets Plack</title>
		<link>http://blog.patspam.com/2009/plebgui-webgui-meets-plack</link>
		<comments>http://blog.patspam.com/2009/plebgui-webgui-meets-plack#comments</comments>
		<pubDate>Mon, 12 Oct 2009 13:20:02 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[WebGUI]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1212</guid>
		<description><![CDATA[WebGUI is an Apache mod_perl application. Not just any mod_perl application; reputedly the most deployed mod_perl application on the planet. You&#8217;d be forgiven for thinking that we love Apache. And we do. Mostly. But you see mod_perl is an overly zealous lover. Every intimate phase of the Apache request cycle is offered up to your [...]]]></description>
			<content:encoded><![CDATA[<p>WebGUI is an Apache mod_perl application. Not just any mod_perl application; <a href="http://www.ohloh.net/p/WebGUI">reputedly</a> the most deployed mod_perl application on the planet. You&#8217;d be forgiven for thinking that we love Apache. And we do. Mostly.</p>
<p>But you see mod_perl is an overly zealous lover. Every intimate phase of the Apache request cycle is offered up to your eager Perl embrace. Sure, you have to learn a few new tricks to get decent performance (such as two-tier mod_proxy/mod_perl) but hey it&#8217;s 2001 and mod_perl is SO much better than CGI. Without hesitation you commit to a life of <strong>PerlResponseHandler</strong>s and <strong>Apache2::Const::OK</strong>s.</p>
<p>Years pass. Life is good.</p>
<p>Your user base had become very adept at deploying Apache. In fact you make life easier for them by <a href="http://sourceforge.net/projects/pbwebgui/files/WebGUI%20Runtime%20Environment/">distributing</a> the complete Perl/Apache/MySQL stack as a simple installer, pre-configured for optimum performance.</p>
<p>Every now and then someone appears on the mailing list asking questions about WebGUI 5, a throw-back to the days when it used to be possible to deploy WebGUI on cheap shared hosting cPanel servers in CGI mode. You want to help, but WebGUI has become so powerful that CGI mode isn&#8217;t feasible anymore. That&#8217;s the price that was paid for evolving into an Enterprise-grade system. Developers <a href="http://www.webgui.org/webgui/campaigns/people/patrick-donelan">lament</a> the fact that small-time users can&#8217;t take advantage of all the awesome things WebGUI can do, not to mention all the word-of-mouth promotion WebGUI is missing out on, but them&#8217;s the brakes. WebGUI continues to grow. &#8220;Carrier-grade&#8221; is the new black. And across town, the non-enterprise crowd is left to content themselves with <a href="http://wordpress.org/">WordPress</a>, <a href="http://www.joomla.org/">Joomla</a> and <a href="http://drupal.org/">Drupal</a>.</p>
<p>And then a guy called <a href="http://profile.typepad.com/miyagawa">Tatsuhiko Miyagawa</a> comes along.</p>
<p>He says, gee, look at these wonderful server abstractions that Python (<a href="http://www.python.org/dev/peps/pep-0333/">WSGI</a>) and Ruby (<a href="http://rack.rubyforge.org/">Rack</a>) have. The Perl world might have moved on from CGI to things like Catalyst::Engine::* and HTTP::Engine, but there&#8217;s still duplicated effort everywhere. We can do better.</p>
<p>So he sits down and writes <a href="http://github.com/miyagawa/psgi-specs">PSGI</a>, an absurdly simple, manifestly beautiful specification for an interface between Perl web apps and web servers (drawing heavily on WSGI and Rack for inspiration).</p>
<h3>PSGI</h3>
<p>The idea goes like this: Web applications, when all is said and done, are really just on about sending three pieces of information to web browsers: a HTTP status code, a list of HTTP headers, and some content (a file or some text, normally HTML).</p>
<p>This is the specification:</p>
<pre class="brush: perl;">
[                                           # an array ref, containing..
    200,                                    # a HTTP status code
    [ 'Content-Type' =&gt; 'text/html', .. ],  # an array of HTTP headers
    [ '&lt;html&gt;...&lt;/html&gt;' ],                 # the text content (or a $filehandle)
]
</pre>
<p>And that&#8217;s really all there is to it.</p>
<p>Some people write web apps according to the interface. Other people write server backends according to the interface. Web app developers use whatever whiz-bang technology they like, and as long as they return an array that complies with the spec their web app can run on any server. And server backend developers can do lots of clever things to get that information back to web browsers really fast, and have the results of their work benefit all PSGI/Plack consumers. No more duplicated effort. No more server-specific love lock-in.</p>
<p>And folks took notice. Not just any folks either. Really, really smart people like Yuval Kogman, Stevan Little, Shawn Moore, Matt Trout, Jesse Vincent, Chia-liang Kao, Dave Rolsky, Simon Cozens, ..  (They&#8217;re some of the well-known names that jumped out at me from the <a href="http://github.com/miyagawa/psgi-specs/blob/master/PSGI.pod">PSGI.pod</a> spec doc. The others are probably even smarter, stealth hackers. I know, it&#8217;s scary).</p>
<h3>Plack</h3>
<p>Before you could say <a href="http://plackperl.org/">Plack</a> there was a reference implementation, server backend support for <a href="http://search.cpan.org/search?query=CGI&amp;mode=all">CGI</a>, <a href="http://www.fastcgi.com">FastCGI</a>, <a href="http://perl.apache.org/">mod_perl</a> (welcome back!), <a href="http://search.cpan.org/dist/AnyEvent/lib/AnyEvent.pm">AnyEvent</a>, <a href="http://search.cpan.org/dist/Coro/Coro.pm">Coro</a>, <a href="http://www.danga.com/perlbal/">Perlbal</a>, <a href="http://nginx.net/">Nginx</a>, .. framework support for <a href="http://www.catalystframework.org/">Catalyst</a>, <a href="http://cgi-app.org/">CGI-Application</a>, <a href="http://www.masonhq.com/">Mason</a>, <a href="http://search.cpan.org/~awwaiid/Continuity/">Continuity</a>, <a href="http://maypole.perl.org/">Maypole</a>, <a href="http://mojolicious.org/">Mojo</a> .. and a whole suite of Middleware and Utilities.</p>
<p>Meaning that all of a sudden any web app written in one of those frameworks can now be deployed on any of those servers. Or on the pure-perl standalone server that runs from the command line. Or on one of the more experimental/exotic servers I haven&#8217;t listed. If you&#8217;re not excited yet, just wait until <a href="http://code.google.com/appengine/">Google AppEngine</a> appears in that list.</p>
<h3>WebGUI</h3>
<p>But where is WebGUI! The problem is that WebGUI is both a framework and a web app. A really big web app. With a mod_perl addiction. Frameworks are built with multiple servers in mind, so they generally already have an in-built server abstraction layer. Which makes adding PSGI support relatively simple. WebGUI, on the other hand, deliberately eschews an abstraction layer so that it can fully embrace mod_perl and eke out every last ounce of power and performance it can from Apache.</p>
<p>So, faced with extreme framework envy, I did what any reasonable person would do.</p>
<p>I built a PSGI/Plack layer for WebGUI.</p>
<h3>PlebGUI</h3>
<p>I&#8217;ve codenamed the project &#8220;<a href="http://github.com/pdonelan/webgui/tree/plebgui">PlebGUI</a>&#8220;, which I think aptly describes the way it makes it possible for the little people to run WebGUI on low-cost shared hosting.</p>
<p>And it actually works. Take for instance <a href="http://plebgui.patspam.com">plebgui.patspam.com</a>, a demo PlebGUI site site running in FastCGI mode on <a href="http://www.hostmonster.com/">HostMonster</a> (the prototypical low-cost shared webhost).</p>
<h3>app.psgi</h3>
<p>The second wonderously simple idea in the PSGI spec is that a web app is just a plain old perl subroutine. Here&#8217;s one I prepared earlier:</p>
<pre class="brush: perl;">

sub { [ 200, [ 'Content-Type' =&gt; 'text/html' ], [ 'Hello World' ] ] }
</pre>
<p>I know, it&#8217;s almost insulting. I&#8217;m a web developer man! I do sophisticated things! But try putting that single-line sub into a test file called <strong>app.psgi</strong>. And then after you&#8217;ve installed Plack (it&#8217;s not on CPAN yet so you have to install it from miyagawa++&#8217;s <a href="http://github.com/miyagawa/Plack">git repo</a>) try running this:</p>
<pre class="brush: bash;">

$ plackup
Accepting connections at http://0:8080/
</pre>
<p>Go on, visit that url in your web browser. Hello to you too!</p>
<h3>Middleware</h3>
<p>Ok that was a cute trick, let&#8217;s try something more exciting:</p>
<pre class="brush: perl;">

use Plack::Builder;
builder {
    add &quot;Plack::Middleware::Static&quot;, path =&gt; qr/./, root =&gt; '/var/www';
    sub { [ 404, [ &quot;Content-Type&quot; =&gt; &quot;text/plain&quot; ], [ &quot;Not Found&quot; ] ] };
};
</pre>
<p>Congratulations, you just added your first Middleware. Assuming you have some static files located at <em>/var/www</em>, you&#8217;ll get the static files returned to your browser with the correct mimetype (thanks to <em>Plack::Middleware::Static</em>). Middleware just wraps your web app (a plain old Perl sub) with another plain old Perl sub. Middleware can do logging, <a href="http://bulknews.typepad.com/blog/2009/10/develstacktraceashtml.html">pretty</a> HTML stack traces, pre/post processing, or anything else you like. Simple, but immensely powerful.</p>
<h3>Plackup</h3>
<p>Plackup is a simple utility script that launches your web app with a specified server backend. By default it runs the pure-perl standalone development server. It expects your webapp to live in a file, similar to the ones we just created. Want to run your web app on another server backend? Try one of these:</p>
<pre class="brush: bash;">

plackup                                         # dev server with StackTrace and AccessLog enabled
plackup -s CGI                                  # remember how slow web apps used to be?
plackup -s AnyEvent                             # nonblocking
plackup -s Coro --port 9090                     # coroutines
plackup -s Standalone::Prefork --max-workers 20 # blazingly fast preforking ftw!
</pre>
<h3>dev.localhost.localdomain.psgi</h3>
<p>Here&#8217;s what the current per-site .psgi file looks like for PlebGUI:</p>
<pre class="brush: perl;">

use Plack::Builder;
use lib '/data/WebGUI/lib';
use WebGUI;

builder {

 # Populate $env from site.conf
 add 'Plack::Middleware::WebGUI',
   root =&gt; '/data/WebGUI',
   config =&gt; 'dev.localhost.localdomain.conf';

 # Handle /extras via Plack::Middleware::Static
 add 'Plack::Middleware::Static',
   path =&gt; qr{^/extras/},
   root =&gt; '/data/WebGUI/www';

 # Handle /uploads via Plack::Middleware::WGAccess (including .wgaccess)
 add 'Plack::Middleware::WGAccess',
   path     =&gt; qr{^/uploads/},
   root =&gt; '/data/domains/dev.localhost.localdomain/public';

 sub { WebGUI::handle_psgi(shift) };
}
</pre>
<p>What you can see there are 3 Middleware layers <strong>add</strong>ed in, one to set up the WebGUI site-specific environment, one to handle <em>/extras</em> static content, and one to handle <em>/uploads </em>static content (taking into account <em>.wgaccess</em> file permissions).</p>
<p>All of those <strong>plackup</strong> command variations above can be used to launch WebGUI outside of mod_perl. Prefer running inside of Apache? How about one of these:</p>
<pre class="brush: xml;">

&lt;VirtualHost *:80&gt;
 PerlOptions +Parent
 PerlSwitches -I/data/WebGUI/lib

 # CGI
 #AddHandler cgi-script cgi
 #ScriptAlias / /data/WebGUI/etc/dev.localhost.localdomain.cgi/
 #&lt;Directory /data/WebGUI/etc&gt;
 #   Options +ExecCGI
 #&lt;/Directory&gt;

 # mod_perl
 #SetHandler perl-script
 #PerlHandler Plack::Server::Apache2
 #PerlSetVar psgi_app /data/WebGUI/etc/dev.localhost.localdomain.psgi

 # FastCGI
 FastCgiServer /data/WebGUI/etc/dev.localhost.localdomain.fcgi
 ScriptAlias / /data/WebGUI/etc/dev.localhost.localdomain.fcgi/

 # mod_psgi
 #&lt;Location /&gt;
 #    SetHandler psgi
 #    PSGIApp /data/WebGUI/etc/dev.localhost.localdomain.psgi
 #&lt;/Location&gt;

&lt;/VirtualHost&gt;
</pre>
<p>Using those directives you can run WebGUI in CGI, mod_perl, FastCGI mode, or even the in-development <a href="http://github.com/spiritloose/mod_psgi/">mod_psgi Apache module</a>.</p>
<h3>Benchmarks</h3>
<p>Ok so how fast are these different backends? Let&#8217;s use ApacheBench to do some simple, unscientific tests of how many requests per second we can squeeze out of WebGUI.</p>
<p>First we&#8217;ll start with WebGUI in its original, un-plebified form, running on the WRE (more is better):</p>
<p>$ ab -n 1000 -c 10 -k http://dev.localhost.localdomain:8081/ | grep &#8216;Requests per&#8217;<br />
Requests per second:    <strong>122.77</strong> [#/sec] (mean)</p>
<p>The result is of course completely dependent on your Apache configuration &#8211; in this case I have (StartServers, MinSpareServers, MaxSpareServers, MaxClients) = (5,5,10,20).</p>
<p>Ok, now have a look at these numbers:</p>
<p>$ ./ab.pl &#8211;app /data/WebGUI/etc/dev.localhost.localdomain.psgi<br />
<em>Testing implementations: AnyEvent, Standalone, Standalone::Prefork, ServerSimple, Coro<br />
app: /data/WebGUI/etc/dev.localhost.localdomain.psgi<br />
ab:  ab -n 1000 -c 10 -k<br />
URL: http://127.0.0.1/<br />
</em><br />
<strong>&#8211; server: AnyEvent</strong><br />
Accepting requests at http://0.0.0.0:10001/<br />
Requests per second:    <strong>68.06</strong> [#/sec] (mean)</p>
<p><strong>&#8211; server: Standalone</strong><br />
Accepting connections at http://0:10001/<br />
Requests per second:    <strong>64.92</strong> [#/sec] (mean)</p>
<p><strong>&#8211; server: Standalone::Prefork</strong><br />
Accepting connections at http://0:10001/<br />
Requests per second:    <strong>214.54</strong> [#/sec] (mean)</p>
<p><strong>&#8211; server: ServerSimple</strong><br />
Plack::Server::ServerSimple: You can connect to your server at http://localhost:10001/<br />
Requests per second:    <strong>66.43</strong> [#/sec] (mean)</p>
<p><strong>&#8211; server: Coro</strong><br />
2009/10/11-23:17:32 Plack::Server::Coro::Server (type Net::Server::Coro) starting! pid(1581)<br />
Requests per second:    <strong>67.55</strong> [#/sec] (mean)</p>
<p>Did you see that? Standalone::Prefork is almost twice as fast as WebGUI in the WRE! The pre-forking server&#8217;s <em>max-workers</em> setting defaults to 10, so the comparison might actually be fair too.</p>
<h3>Holy Shit</h3>
<p>I think that&#8217;s worth repeating. PlebGUI, which is currently less than one week old and running on a compatibility layer optimised for &#8220;let&#8217;s just get this thing working and worry about performance later&#8221; is already capable of out-performing the WRE in terms of raw speed by 200%. (If you believe the benchmarks).</p>
<p>But Plack/PSGI is not just about speed. It&#8217;s about <strong>flexibility</strong>. Think Koen de Jonge, WebGUI hosting extraordinaire at Procolix, deploying a high availability &#8220;follow the sun&#8221; WebGUI cluster on Nginx servers. Think Colin Kuskie, WebGUI test suite overlord, probing the dark corners of the WebGUI API using standard HTTP::Request and HTTP::Response pairs through mocked HTTP and live HTTP servers. Think web developers working on WebGUI client code, with a web server fully integrated into Padre. Think WebGUI entirely deployable from the CPAN.</p>
<p>Think of every new project added to the PSGI/Plack ecosystem as a potential new PlebGUI feature.</p>
<h3>Where to Now</h3>
<p>The approach I took in turning WebGUI into PlebGUI was to create a fake Apache2::Request object, since that&#8217;s the closest thing WebGUI has to a server abstraction layer. Plack contains two helper classes <em>Plack::Request</em> and <em>Plack::Response</em> that make this really easy. Currently though, that leaves us in the curious situation where WebGUI does all of its work thinking it&#8217;s talking to mod_perl, only to have its real output re-routed through the PSGI-compatibility layer, to be subsequently processed by a specific server backend. If you don&#8217;t get the joke yet, just think about what happens when the PSGI server backend happens to be mod_perl.</p>
<p>The benchmarks would clearly improve if we ripped out mod_perl altogether. Lots of code would simplify too. Certain parts of WebGUI could disappear altogether, such as URL Handlers which could be entirely replaced with Middleware.</p>
<p>The only feature that PlebGUI currently lacks is content streaming. I deliberately left that out since it will be a lot easier to achieve once mod_perl disappears. In Plack land the way to drip-feed browsers with &#8220;chunked&#8221; content is to return an <a href="http://search.cpan.org/~gbarr/IO-1.25/lib/IO/Handle.pm">IO::Handle</a>-like object that responds to getline() and close(). The Plack folks are planning a fancy new module called IO::Writer that will Do The Right Thing under both blocking and non-blocking servers. Expect awesome things.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2009/plebgui-webgui-meets-plack/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
