<?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.com &#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>patspampatspampatspampatspam</description>
	<lastBuildDate>Mon, 08 Mar 2010 01:23:45 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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 time someone [...]]]></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>0</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 magic [...]]]></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 response [...]]]></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 eager [...]]]></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>12</slash:comments>
		</item>
		<item>
		<title>Padre::Plugin::WebGUI Tab Icons</title>
		<link>http://blog.patspam.com/2009/padrepluginwebgui-tab-icons</link>
		<comments>http://blog.patspam.com/2009/padrepluginwebgui-tab-icons#comments</comments>
		<pubDate>Thu, 01 Oct 2009 09:49:25 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[WebGUI]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1208</guid>
		<description><![CDATA[Version 0.03 of Padre::Plugin::WebGUI (my WebGUI plugin for the Padre Perl IDE) is on its way to the CPAN, with one small but rather nice feature: tab icons. Just as the plugin uses WebGUI&#8217;s native icons to display the Asset Tree for your site, you now get the same attractive icon in the tab that [...]]]></description>
			<content:encoded><![CDATA[<p>Version 0.03 of <a href="http://search.cpan.org/dist/Padre-Plugin-WebGUI/">Padre::Plugin::WebGUI</a> (my WebGUI plugin for the Padre Perl IDE) is on its way to the CPAN, with one small but rather nice feature: tab icons. Just as the plugin uses WebGUI&#8217;s native icons to display the Asset Tree for your site, you now get the same attractive icon in the tab that opens up when you double-click to edit something. Apart from the aesthetics, it&#8217;s handy to know at a glance what sort of asset you&#8217;re editing (WebGUI uses the same trick for the edit icons on your site when you turn admin mode on). I was hoping to be able to add hover-text too (in case you don&#8217;t recognise the Asset type from its icon) but thus far I haven&#8217;t figured out if wxPerl and/or Padre supports it.</p>
<p>The following screenshot shows a nice example of several tabs open at once with different WebGUI Asset types displaying their own icons.</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/10/Tab_Icons.png"><img class="alignnone size-medium wp-image-1209" title="Tab_Icons" src="http://blog.patspam.com/wp-content/uploads/2009/10/Tab_Icons-300x121.png" alt="Tab_Icons" width="300" height="121" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2009/padrepluginwebgui-tab-icons/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Padre::Plugin::WebGUI now with remote editing</title>
		<link>http://blog.patspam.com/2009/padrepluginwebgui-now-with-remote-editing</link>
		<comments>http://blog.patspam.com/2009/padrepluginwebgui-now-with-remote-editing#comments</comments>
		<pubDate>Sat, 26 Sep 2009 14:26:20 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[WebGUI]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1191</guid>
		<description><![CDATA[Up until now the WebGUI Padre plugin I&#8217;ve been working on has been more or less a proof-of-concept / toy / test-bed for experimental ideas. Whilst that has been fun (and made for good conference slides), the reality is that I haven&#8217;t actually been using the plugin for my daily WebGUI development, so how could [...]]]></description>
			<content:encoded><![CDATA[<p>Up until now the <a href="http://webgui.org">WebGUI</a> <a href="http://padre.perlide.org">Padre</a> plugin I&#8217;ve been <a href="../2009/padrepluginwebgui">working on</a> has been more or less a proof-of-concept / toy / test-bed for experimental ideas. Whilst that has been fun (and made for good conference slides), the reality is that I haven&#8217;t actually been using the plugin for my daily WebGUI development, so how could I expect other WebGUI developers to do so?</p>
<p>I&#8217;m hoping to change that. As of today I&#8217;ve stripped out all the experimental features and concentrated on the single feature that seems to have the widest possible appeal, namely, <strong>remote editing</strong>.</p>
<p>Version 0.02 of <a href="http://search.cpan.org/search?query=Padre%3A%3APlugin%3A%3AWebGUI&amp;mode=all">Padre::Plugin::WebGUI</a>, which is on its way to the CPAN, allows you to connect over HTTP to your webgui site, view you asset tree and edit your assets from inside the Padre text editor. That hopefully makes it as useful for designers and content managers as it is for developers.</p>
<p>Previously the plugin got most of its power from the WGDev library. However this meant that you had to install WebGUI and WGDev as a prerequisite. Given that the WRE ships with non-threaded perl, this meant either installing these prereqs into your system perl or building another perl specifically to run them.  Not an overly arduous task, but enough of a hurdle to dissuade most WebGUI developers from playing with the plugin. That obstacle has now been removed. You do not need to have WebGUI or WGDev installed to run the plugin.</p>
<p>Using WGDev also meant that you could only connect locally to your site. That restriction is now gone.</p>
<p><strong>Installation</strong></p>
<p>Firstly, <a href="http://padre.perlide.org/download.html">install Padre</a>.<strong><br />
</strong></p>
<p>To allow your WebGUI site to talk to the plugin, add <a href="http://github.com/pdonelan/webgui/blob/padre/lib/WebGUI/Content/Padre.pm">this content handler</a> (WebGUI::Content::Padre) to your site and restart modperl  (the easiest way to do this is to drop the module into your <em>/data/WebGUI/lib/WebGUI/Content</em> dir and add the new content handler to your site config file. There is also an <a href="http://github.com/pdonelan/webgui/blob/padre/sbin/installPadre.pl">install script</a> that will do the site config editing for you).</p>
<p>Next install the plugin from the CPAN</p>
<pre class="brush: bash;">

cpan Padre::Plugin::WebGUI
</pre>
<p><strong>Usage</strong></p>
<p>Inside Padre, go to the Plugin Manager and enable the WebGUI plugin. You should then see a WebGUI item appear in your Plugins menu.</p>
<p>From the WebGUI menu, tick &#8220;Show Asset Tree&#8221; and double-click on &#8220;Connect&#8221; in the new panel that appears.</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/09/connect.png"><img class="alignnone size-medium wp-image-1193" title="connect" src="http://blog.patspam.com/wp-content/uploads/2009/09/connect-300x186.png" alt="connect" width="300" height="186" /></a></p>
<p>You will be prompted for the URL of the site you want to connect to. Currently you need to enter you the site in the form: <em>http://username:password@site.com</em> (later we will add a site manager to make this nicer). Remember that this can be any webgui site that you have access to, not just a local site.</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/09/connect2.png"><img class="alignnone size-medium wp-image-1194" title="connect2" src="http://blog.patspam.com/wp-content/uploads/2009/09/connect2-300x67.png" alt="connect2" width="300" height="67" /></a></p>
<p>You will then see the Asset Tree dynamically populated with information from your site.</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/09/asset_tree.png"><img class="alignnone size-medium wp-image-1192" title="asset_tree" src="http://blog.patspam.com/wp-content/uploads/2009/09/asset_tree-300x186.png" alt="asset_tree" width="300" height="186" /></a></p>
<p>Try double-clicking on an article.</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/09/getting_started.png"><img class="alignnone size-medium wp-image-1196" title="getting_started" src="http://blog.patspam.com/wp-content/uploads/2009/09/getting_started-300x186.png" alt="getting_started" width="300" height="186" /></a></p>
<p>A new file tab should open with the name set to the name of your article (with [wg] prepended). The article content will be loaded into to tab, with Padre&#8217;s HTML syntax highlighting in effect. If you have Padre::Plugin::HTML installed, you can use the Tidy/Lint/Validate the HTML to your heart&#8217;s content. And every time you hit Save, your changes will be pushed up to the site as a new Version Tag.</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/09/look_ma.png"><img class="alignnone size-medium wp-image-1198" title="look_ma" src="http://blog.patspam.com/wp-content/uploads/2009/09/look_ma-300x191.png" alt="look_ma" width="300" height="191" /></a></p>
<p>Try double-clicking on another sort of asset, for instance a Template. Once again, the template html will be loaded into a new tab with nice syntax highlighting.</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/09/template.png"><img class="alignnone size-medium wp-image-1199" title="template" src="http://blog.patspam.com/wp-content/uploads/2009/09/template-300x186.png" alt="template" width="300" height="186" /></a></p>
<p>And for fun, try opening up a CSS Snippet. The plugin will detect that your snippet is set to the &#8216;text/css&#8217; mime type and use CSS code highlighting instead of HTML.</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/09/css.png"><img class="alignnone size-medium wp-image-1195" title="css" src="http://blog.patspam.com/wp-content/uploads/2009/09/css-300x186.png" alt="css" width="300" height="186" /></a></p>
<p>And similarly for JavaScript Snippets.</p>
<p><a href="../wp-content/uploads/2009/09/javascript.png"><img title="javascript" src="../wp-content/uploads/2009/09/javascript-300x164.png" alt="javascript" width="300" height="164" /></a></p>
<p><strong>Design and Extensions</strong></p>
<p>As far as Padre is concerned the file you are editing is just a regular file on your file system. For example when you edit the text, an asterisk (*) appears next to the name of the file indicating that you haven&#8217;t save it yet.  The integration between the webgui content handler and the plugin is minimal, meaning that you could conceivably use this plugin to do remote editing on non-webgui sites too.</p>
<p>Padre has a nice architectural design, which makes it really easy for us to associate different WebGUI::Asset types with Padre::Document types. Currently most assets delegate to the default <em>Padre::Document::WebGUI::Asset</em> module which does HTML syntax highlighting and expects only generic content from the content handler running on your site. <em>Padre::Document::WebGUI::Snippet</em> has a slightly higher IQ level in that it asks the server to tell it what mimetype the asset is set to, so that it can use the appropriate syntax highlighter.</p>
<p>We could do some really interesting things by building asset-specific Padre::Document modules. For instance you could build a document type that uses fancy wxWidgets controls to do things that aren&#8217;t possible on the web (desktop integration etc..) And it&#8217;s just as easy to build these for your own custom asset types as it is for core ones. Given that Padre is cross-platform, you&#8217;re basically looking at a way of extending WebGUI interactions out into desktop-land.</p>
<p>If you&#8217;re a WebGUI designer/developer/content manager and you want to start playing with Padre::Plugin::WebGUI as a novel way of editing content, come find me on #webgui or #padre.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2009/padrepluginwebgui-now-with-remote-editing/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Finding missing WebGUI Templates</title>
		<link>http://blog.patspam.com/2009/finding-missing-webgui-templates</link>
		<comments>http://blog.patspam.com/2009/finding-missing-webgui-templates#comments</comments>
		<pubDate>Thu, 30 Jul 2009 09:06:59 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Comp]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[WebGUI]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1181</guid>
		<description><![CDATA[Following on from my previous WGDev post, here&#8217;s another example of wgd ls that lets you find missing Templates on a WebGUI site.
One problem that content managers run into is that after deleting a template in WebGUI, any assets that still refer to the template will die a horrible death when users try to view [...]]]></description>
			<content:encoded><![CDATA[<p>Following on from my <a href="http://blog.patspam.com/2009/ode-to-wgd-and-the-command-line">previous WGDev post</a>, here&#8217;s another example of <strong>wgd ls</strong> that lets you find missing Templates on a WebGUI site.</p>
<p>One problem that content managers run into is that after deleting a template in WebGUI, any assets that still refer to the template will die a horrible death when users try to view them. What would be nice is an automated way of finding all such assets that refer to missing template, so that you can update them to refer to a different template.</p>
<p>For starters, WGDev can give you a list of all available templates on your site via:</p>
<pre class="brush: bash;">

wgd ls root -r --format %assetId% --includeOnlyClass WebGUI::Asset::Template | sort | uniq &gt; available
</pre>
<p>You can also ask for a list of all in-use templateIds, via:</p>
<pre class="brush: bash;">

wgd ls root -r --format %templateId% --filter '%templateId% ~~ /.+/' | sort | uniq &gt; in_use
</pre>
<p>All you need to do then is ask the <a href="http://www.gnu.org/software/coreutils/manual/html_node/comm-invocation.html">comm</a> command to tell you which templateIds are <em>in_use</em> but not <em>available</em>:</p>
<pre class="brush: bash;">

comm -23 in_use available
</pre>
<p>Putting it all together on one line (without the temporary files), that becomes:</p>
<pre class="brush: bash;">

comm -23 &lt;(wgd ls root -rf %templateId% --filter '%templateId% ~~ /.+/' | sort | uniq) &lt;(wgd ls root -rf %assetId% --includeOnlyClass WebGUI::Asset::Template | sort | uniq)
</pre>
<p>The output of this command is a nice list of missing templateIds.</p>
<p>Of course, what you probably then want to do is ask WGDev to give you a list of asset urls that are trying to use these missing Templates, for example, if one item in your list is <em>eHMsLCMqoXYpYrsZ7CWUtg</em>, you would do:</p>
<pre class="brush: bash;">

wgd ls root -rf %url% --filter '%templateId% ~~ eHMsLCMqoXYpYrsZ7CWUtg'
</pre>
<p>Which would print something like</p>
<pre class="brush: bash;">

/my/broken/asset/url
</pre>
<p>Combining this with the previous command to do it all on one line is left as an exercise for the reader <img src='http://blog.patspam.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Now, <strong>templateId</strong> isn&#8217;t the only Asset field that templates can be referenced under, for example, if you want to also find missing Style and Printable Style templates, you&#8217;d want to do something like:</p>
<pre class="brush: bash;">

for tmpl in templateId styleTemplateId printableStyleTemplateId
do
comm -23 &lt;(wgd ls root -rf %${tmpl}% --filter &quot;%${tmpl}% ~~ /.+/&quot; | sort | uniq) &lt;(wgd ls root -rf %assetId% --includeOnlyClass WebGUI::Asset::Template | sort | uniq)
done
</pre>
<p>It&#8217;s not optimised for speed, but it sure is handy. And you could apply the same approach to search for invalid group permissions, etc.. Of course if you found yourself doing this often you&#8217;re probably better off writing a dedicated WGDev plugin to wrap up the functionality.</p>
<p>There&#8217;s a <a href="http://github.com/pdonelan/webgui/tree/template_usage">WebGUI branch on GitHub</a> containing some extra <a href="http://www.webgui.org/rfe/request-for-enhancement/10659">Template Usage-related functions</a> &#8211; the plan is to add the ability to find all the different ways that templates are referenced (in Asset definitions, Account module definitions, &#8230;) so perhaps we will end up adding a &#8220;find missing Templates&#8221; button to the Edit Template page.</p>
<p>[ perl ironman ]</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2009/finding-missing-webgui-templates/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ode to wgd and the command line</title>
		<link>http://blog.patspam.com/2009/ode-to-wgd-and-the-command-line</link>
		<comments>http://blog.patspam.com/2009/ode-to-wgd-and-the-command-line#comments</comments>
		<pubDate>Tue, 14 Jul 2009 08:45:41 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[WebGUI]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1171</guid>
		<description><![CDATA[Doug just posted an ode to the Linux command line over at the Plain Black staff blog.
I&#8217;ve been getting a lot of joy out of the command line today too thanks to Graham&#8217;s ridiculously useful WGDev. One wgd command that I only started using in earnest today is the ls command. In its most basic [...]]]></description>
			<content:encoded><![CDATA[<p>Doug just <a href="http://www.plainblack.com/pr/staff/blog/useful-shell-stuff">posted</a> an ode to the Linux command line over at the Plain Black staff blog.</p>
<p>I&#8217;ve been getting a lot of joy out of the command line today too thanks to Graham&#8217;s ridiculously useful <a href="http://github.com/haarg/wgdev/tree/master">WGDev</a>. One wgd command that I only started using in earnest today is the <strong>ls</strong> command. In its most basic form, it lets you print out a list of assets on your site:</p>
<pre class="brush: bash;">

$ wgd ls /home

getting_started
your_next_step
the_latest_news
tell_a_friend
documentation
site_map
</pre>
<p>I <a href="http://github.com/pdonelan/wgdev/tree/master">added</a> a bunch of extensions to <strong>ls</strong> today, the first one being a <strong>-r</strong> option that tells <strong>ls</strong> to recursively list assets. Given that this prints to STDOUT, you can pipe this into any other command line tool to manipulate the output. For example, to list all assets that have the word &#8220;you&#8221; in their menu title:</p>
<pre class="brush: bash;">

$ wgd ls /root -f &quot;%menuTitle%&quot; -r | grep -i you
Profile Account Layout
Inbox Account Layout
Friends Layout Template
Account Layout
Shop Account Layout
Contributions Layout
Default Account Layout
Layout
Your Next Step
</pre>
<p>(the<em> -f &#8220;%menuTitle%</em>&#8221; option above tells the command to output only the <em>menuTitle</em> property of each asset).</p>
<p>Under the hood <strong>ls</strong> is calling <em>asset-&gt;getLineage()</em>, so I exposed a few of the getLineage API options to <strong>ls</strong>.</p>
<p>For example, this is one way of getting a sorted list of Survey templates on your site:</p>
<pre class="brush: bash;">

$ wgd ls root -r --includeOnlyClass WebGUI::Asset::Template -f &quot;%url% %namespace%&quot; | perl -ane 'print &quot;$F[0] ($F[1])\n&quot; if $F[1] =~ m/survey/i' | sort
root/import/expireincompletesurveyresponses/expireincompletesurveyresponses (ExpireIncompleteSurveyResponses)
root/import/survey/default-answer-edit (Survey/Edit)
root/import/survey/default-feedback (Survey/Feedback)
root/import/survey/default-gradebook-report (Survey/Gradebook)
root/import/survey/default-overview-report (Survey/Overview)
root/import/survey/default-question-edit (Survey/Edit)
root/import/survey/default-questions (Survey/Take)
root/import/survey/default-section-edit (Survey/Edit)
root/import/survey/default-survey-edit (Survey/Edit)
root/import/survey/default-survey-summary (Survey/Summary)
root/import/survey/default-survey (Survey)
root/import/survey/default-survey-take (Survey/Take)
root/import/survey/default-test-results (Survey/TestResults)
</pre>
<p>While I was writing this post, Andy asked me to provide him with a list of all Carousel wobjects on a site we&#8217;re working on. That&#8217;s as easy as:</p>
<pre class="brush: bash;">

$ wgd ls -r root --includeOnlyClass WebGUI::Asset::Wobject::Carousel
</pre>
<p>The most useful option I added to <strong>ls</strong> is the <strong>&#8211;filter</strong> smartmatch filter option. This option filters the results using an asset property of your choosing. Format looks like &#8220;%url% ~~ smartmatch&#8221;, where &#8220;url&#8221; is the field to filter against, and &#8220;smartmatch&#8221; is either a Perl regular expression such as &#8220;/(?i:partial_match)/&#8221; or a string such as &#8220;my_exact_match&#8221;.</p>
<p>For example, the following command lists all templates that include absolute urls. We generate the output to an html file so that someone can easily open all the links and manually review/remove the absolute urls:</p>
<pre class="brush: bash;">

$ wgd ls -r /root --filter &quot;%template% ~~ /http:///&quot; --includeOnlyClass WebGUI::Asset::Template --format &quot;&lt;a href=http://dev.localhost.localdomain/%url%?func=edit&gt;%url%&lt;/a&gt;&lt;br&gt;&quot; &gt; links.html
</pre>
<p>links.html then contains:</p>
<pre class="brush: xml;">
&lt;a href=http://dev.localhost.localdomain/style_01?func=edit&gt;style_01&lt;/a&gt;&lt;br&gt;
&lt;a href=http://dev.localhost.localdomain/style_02?func=edit&gt;style_02&lt;/a&gt;&lt;br&gt;
&lt;a href=http://dev.localhost.localdomain/style_03?func=edit&gt;style_03&lt;/a&gt;&lt;br&gt;

...
</pre>
<p>One type of command that I can see myself using a lot in the future is the following, which displays all assets that are viewable to a specific group (in this case the &#8220;Turn Admin On&#8221; group, which has an id of &#8220;12&#8243;):</p>
<pre class="brush: bash;">

$ wgd ls -r root --format &quot;%groupIdView% %url%&quot; --filter &quot;%groupIdView% ~~ 12&quot;
12 root/import/newsletter
12 root/import/projectmanager/resource
12 root/import/wiki
</pre>
<p>Alternatively, you can use a variation of the above to list all assets that are NOT viewable to a certain group (or groups). This is great for finding assets that have accidentally been set to say, Admins, when you want them viewable by Registered Users. For example, the following command lists assets that are not viewable to the default &#8220;Visitors&#8221;, &#8220;Everyone&#8221;, or &#8220;Registered Users&#8221; groups:</p>
<pre class="brush: bash;">

$ wgd ls -r root --format &quot;%groupIdView% %url%&quot; | perl -ane 'print &quot;$F[0] $F[1]\n&quot; if !grep {$F[0] eq $_} qw(1 2 7)'
12 root/import/newsletter
12 root/import/projectmanager/resource
12 root/import/wiki
</pre>
<p>All of these commands take in the order of 1 second to run, which is a lot less time consuming than manually reviewing your site asset-by-asset. And if you incorporate them into your test suite, you can re-verify their output against your site policy/expectations whenever you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2009/ode-to-wgd-and-the-command-line/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Padre::Plugin::WebGUI</title>
		<link>http://blog.patspam.com/2009/padrepluginwebgui</link>
		<comments>http://blog.patspam.com/2009/padrepluginwebgui#comments</comments>
		<pubDate>Fri, 03 Jul 2009 08:42:06 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[WebGUI]]></category>

		<guid isPermaLink="false">http://blog.patspam.com/?p=1155</guid>
		<description><![CDATA[For a little while now I&#8217;ve been working on a WebGUI plugin for Padre (the Perl Application Development and Refactoring Environment). Progress has been pretty slow, partly due to lack of time but also because often the things I want to do are at the edge of what Padre currently supports (or just that there&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>For a little while now I&#8217;ve been working on a <a href="http://webgui.org">WebGUI</a> plugin for <a href="http://padre.perlide.org">Padre</a> (the Perl Application Development and Refactoring Environment). Progress has been pretty slow, partly due to lack of time but also because often the things I want to do are at the edge of what Padre currently supports (or just that there&#8217;s no existing examples of how to do something easily).</p>
<p>I&#8217;ve released the code onto <a href="http://search.cpan.org/search?query=Padre%3A%3APlugin%3A%3AWebGUI&amp;mode=all">CPAN</a>, and the current dev version is available via <a href="http://github.com/pdonelan/Padre-Plugin-WebGU">github</a>, but since it&#8217;s all a bit hacky and alpha at the moment I thought it worthwhile doing a little tour of what currently works (on my dev box at least).</p>
<h2>Installation</h2>
<p>Installation is the same as any other Padre plugin, either install via cpan</p>
<pre class="brush: bash;">

cpan install Padre::Plugin::WebGUI
</pre>
<p>or from git:</p>
<pre class="brush: bash;">

git clone git://github.com/pdonelan/Padre-Plugin-WebGUI.git

perl Makefile.PL

make &amp;&amp; make test &amp;&amp; make install
</pre>
<p>Since this is a WebGUI plugin, you need to first install <a href="http://webgui.org">WebGUI</a>, and also <a href="http://github.com/haarg/wgdev">WGDev</a>.</p>
<p>Once you&#8217;ve done that, you will see the WebGUI plugin listed in the Padre Plugin Manager:</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/07/Screenshot-Plugin-Manager.png"><img class="alignnone size-medium wp-image-1160" title="Padre Plugin Manager" src="http://blog.patspam.com/wp-content/uploads/2009/07/Screenshot-Plugin-Manager-300x225.png" alt="Padre Plugin Manager" width="300" height="225" /></a></p>
<p>Click the enable button, and you&#8217;ll see a WebGUI item appear in the Plugin menu.</p>
<h2>Controlling WRE Services</h2>
<p>The first thing you can do with the plugin is control your WRE services (mysql, modperl, modproxy and spectre).</p>
<p>Click on: <strong>WebGUI &gt; WRE Services &gt; Modperl &gt; Restart</strong> and you&#8217;ll see a restart status message appear in the Padre output panel.</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/07/restart-modperl.png"><img class="alignnone size-medium wp-image-1162" title="restart-modperl" src="http://blog.patspam.com/wp-content/uploads/2009/07/restart-modperl-300x261.png" alt="restart-modperl" width="300" height="261" /></a></p>
<p>Currently this is just a simple wrapper around the wreservice.pl script that ships with WebGUI. A nice enhancement would be to turn the menu item into a services dashboard with lights telling you which services are currently running, and buttons to start/stop/restart.</p>
<h2>Online Resources</h2>
<p>Another item in the menu called <strong>Online Resources</strong> gives you access to a bunch of handy WebGUI links that open in your browser &#8211; including one that takes you straight to a web-based IRC client connected to #webgui.</p>
<h2>WebGUI Log</h2>
<p>If you click the &#8220;Logview&#8221; checkbox on the WebGUI menu, a <strong>WebGUI Log</strong> panel will open. This panel will start monitoring all of your WRE log files (webgui.log, modperl.log, modproxy.log, etc..) and display changes in real-time. WebGUI uses Log4perl as its logging engine, but it <a href="http://www.plainblack.com/webgui/dev/discuss/log4perl-webgui-custom-filter">uses the sitename as the Log4perl category</a>, which means that you can&#8217;t easily e.g. turn on DEBUG output and filter out everything except the module you&#8217;re working on (unless you use my <a href="http://github.com/pdonelan/log4perl-filter-callermatch">Log4perl::Filter::CallerMatch</a> module). Once we add in the ability to easily customise what files are being logged and apply filters to what gets displayed, this will make the above scenario a breeze.</p>
<p>The logview panel uses a long-running Padre task and <a href="http://search.cpan.org/~mgrabnar/File-Tail-0.99.3/Tail.pm#select">File::Tail::select</a> to continuous monitor a bunch of files in realtime. The main thread writes commands to a temp file to send commands to the monitoring thread (the most important command being &#8220;exit&#8221; which tells the thread to break out of its monitoring loop!). Later I plan on adding support for other commands such as &#8220;add/remove this file from the list of files you&#8217;re watching&#8221;, &#8220;add/remove filter&#8221;, etc.. Since this seems like a generic sort of feature I&#8217;m hoping to bundle  Padre::Plugin::WebGUI::Logview and Padre::Plugin::WebGUI::Task::Logview as a stand-alone module for other Padre plugin developers to use (and improve).</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/07/logview.png"><img class="alignnone size-medium wp-image-1164" title="logview" src="http://blog.patspam.com/wp-content/uploads/2009/07/logview-300x230.png" alt="logview" width="300" height="230" /></a></p>
<h2>Asset Tree</h2>
<p>And finally, the coolect feature the WebGUI plugin has is the Asset Tree.</p>
<p>If you turn on the Asset Tree from the plugin menu, a new panel appears with a &#8220;Connect&#8221; button on it. Currently this is hardwired to the default WebGUI dev site at dev.localhost.localdomain but later I plan on adding a Site Manager to allow you to define sites here.</p>
<p>Double-clicking on the Connect button connects to the site, and pulls down the asset tree:</p>
<p><a href="http://blog.patspam.com/wp-content/uploads/2009/07/asset-tree.png"><img class="alignnone size-medium wp-image-1165" title="asset-tree" src="http://blog.patspam.com/wp-content/uploads/2009/07/asset-tree-300x184.png" alt="asset-tree" width="300" height="184" /></a></p>
<p>This is the same Asset Tree you see when you log in to your WebGUI site and turn admin mode on. As you can see from the screenshot, right-clicking on a node brings up a context menu, from which you can do asset-specific actions. The plugin already gives you access to all of the WGDev commands from the main plugin menu (with a dialog box asking you what arguments you want to pass to the command), but it becomes a lot more useful once you hook these WGDev commands to the Asset Tree context menu. Then instead of having to remember what url or assetId your asset has, you can just click through the tree to find the node you want, right-click and off you go.</p>
<p>For example, WGDev has a <strong>package</strong> command that lets you package up node and all of its children into a tarball that can be imported into other sites, used in upgrade scripts, etc.. By integrating this command into the context menu, you can have Padre prompt you you for the folder that you want to save the WebGUI package in (via your native Save File dialog box).</p>
<p>Similarly, WGDev has an <strong>edit</strong> command that lets you edit an asset (for example a template file) via your favourite editor and then have the changes pushed back into the database after you save and close the file. By integrating this command into Padre, you could leave the file open, and push the changes up every time you hit save(allowing for more convenient continuous editing).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.patspam.com/2009/padrepluginwebgui/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
