<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:posterous="http://posterous.com/help/rss/1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
  <channel>
    <title>Sebastian Riedel about Perl and the Web</title>
    <link>http://blog.kraih.com</link>
    <description>Most recent posts at Sebastian Riedel about Perl and the Web</description>
    <generator>posterous.com</generator>
    <link xmlns="http://www.w3.org/2005/Atom" href="http://posterous.com/api/sup_update#d1891094f" type="application/json" rel="http://api.friendfeed.com/2008/03#sup" />
    
    
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/kraih" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="kraih" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://posterous.superfeedr.com/" /><item>
      <pubDate>Mon, 20 Feb 2012 03:30:00 -0800</pubDate>
      <title>Mojolicious hack of the day: More AnyEvent, oh my</title>
      <link>http://blog.kraih.com/mojolicious-hack-of-the-day-more-anyevent-oh</link>
      <guid>http://blog.kraih.com/mojolicious-hack-of-the-day-more-anyevent-oh</guid>
      <description>
        <![CDATA[<p>
	<p>Ever since we <a href="http://blog.kraih.com/mojolicious-hack-of-the-day-anyevent">added AnyEvent support</a>&nbsp;to <a href="http://mojolicio.us">Mojolicious</a>&nbsp;through <a href="https://metacpan.org/module/EV">EV</a>, it has been a very popular feature. But so far it required Mojolicious&nbsp;to be in control of the event loop, which limited its usefulness quite a bit. That has changed now, both our web server and user agent have become pretty much indistiguishable from normal <a href="https://metacpan.org/module/AnyEvent">AnyEvent</a> components. Today i'm going to demonstrate how you can non-blockingly search Twitter for Perl with the <a href="http://mojolicio.us/perldoc/Mojo/UserAgent">user agent</a>, from a <a href="https://metacpan.org/module/PSGI">PSGI</a> application running inside the AnyEvent based <a href="https://metacpan.org/module/Twiggy">Twiggy</a> web server. In fact, it should work with any non-blocking capable web framework, such as <a href="http://catalystframework.org">Catalyst</a>.</p>
<p><div class="data type-perl">
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
<span rel="#L17" id="L17">17</span>
<span rel="#L18" id="L18">18</span>
<span rel="#L19" id="L19">19</span>
<span rel="#L20" id="L20">20</span>
<span rel="#L21" id="L21">21</span>
<span rel="#L22" id="L22">22</span>
<span rel="#L23" id="L23">23</span>
<span rel="#L24" id="L24">24</span>
<span rel="#L25" id="L25">25</span>
</pre>
          </td>
          <td width="100%">
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="k">use</span> <span class="mf">5.14.0</span><span class="p">;</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">Mojo::</span><span class="n">UserAgent</span><span class="p">;</span></div><div class="line" id="LC3"><span class="k">use</span> <span class="nn">Mojo::</span><span class="n">ByteStream</span> <span class="s">&#39;b&#39;</span><span class="p">;</span></div><div class="line" id="LC4"><span class="k">use</span> <span class="n">EV</span><span class="p">;</span></div><div class="line" id="LC5"><br /></div><div class="line" id="LC6"><span class="c1"># Normal PSGI application</span></div><div class="line" id="LC7"><span class="k">my</span> <span class="nv">$ua</span>  <span class="o">=</span> <span class="nn">Mojo::</span><span class="n">UserAgent</span><span class="o">-&gt;</span><span class="k">new</span><span class="p">;</span></div><div class="line" id="LC8"><span class="k">my</span> <span class="nv">$app</span> <span class="o">=</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC9">&nbsp;&nbsp;<span class="k">return</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC10">&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$respond</span> <span class="o">=</span> <span class="nb">shift</span><span class="p">;</span></div><div class="line" id="LC11"><br /></div><div class="line" id="LC12">&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1"># Search Twitter for &quot;perl&quot;</span></div><div class="line" id="LC13">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$ua</span><span class="o">-&gt;</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;http://search.twitter.com/search.json?q=perl&#39;</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC14">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">my</span> <span class="p">(</span><span class="nv">$ua</span><span class="p">,</span> <span class="nv">$tx</span><span class="p">)</span> <span class="o">=</span> <span class="nv">@_</span><span class="p">;</span></div><div class="line" id="LC15"><br /></div><div class="line" id="LC16">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1"># Respond with first result</span></div><div class="line" id="LC17">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$respond</span><span class="o">-&gt;</span><span class="p">(</span></div><div class="line" id="LC18">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">[</span> <span class="mi">200</span><span class="p">,</span></div><div class="line" id="LC19">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">[</span><span class="s">&#39;Content-Type&#39;</span> <span class="o">=&gt;</span> <span class="s">&#39;text/plain&#39;</span><span class="p">],</span></div><div class="line" id="LC20">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">[</span><span class="n">b</span><span class="p">(</span><span class="nv">$tx</span><span class="o">-&gt;</span><span class="n">res</span><span class="o">-&gt;</span><span class="n">json</span><span class="o">-&gt;</span><span class="p">{</span><span class="n">results</span><span class="p">}</span><span class="o">-&gt;</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-&gt;</span><span class="p">{</span><span class="n">text</span><span class="p">})</span><span class="o">-&gt;</span><span class="n">encode</span><span class="p">]</span></div><div class="line" id="LC21">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">]</span></div><div class="line" id="LC22">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">);</span></div><div class="line" id="LC23">&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">});</span></div><div class="line" id="LC24">&nbsp;&nbsp;<span class="p">};</span></div><div class="line" id="LC25"><span class="p">};</span></div></pre></div>
          </td>
        </tr>
      </table>
  </div></p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-hack-of-the-day-more-anyevent-oh">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-hack-of-the-day-more-anyevent-oh#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Wed, 08 Feb 2012 00:22:00 -0800</pubDate>
      <title>Mojolicious and DBIx::Class</title>
      <link>http://blog.kraih.com/mojolicious-and-dbixclass</link>
      <guid>http://blog.kraih.com/mojolicious-and-dbixclass</guid>
      <description>
        <![CDATA[<p>
	<p>If you've ever been wondering how a well designed DBIx::Class model for Mojolicious and Mojolicious::Lite applications would look like, Glen Hinkle got you covered with <a href="http://blogs.perl.org/users/tempire/2012/02/mojolicious-full-and-lite-apps---understanding-the-difference.html">his latest release</a>.</p>
<blockquote class="posterous_medium_quote">
<p>The example application demonstrates DBIx::Class integration, how to test your web app with Test::Mojo, as well as how to use EP templates with and without tag helpers. For those unfamiliar with testing in general, there are even examples of DBIC schema tests.</p>
</blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px;">Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-and-dbixclass">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-and-dbixclass#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Tue, 03 Jan 2012 09:01:00 -0800</pubDate>
      <title>A logo for MetaCPAN</title>
      <link>http://blog.kraih.com/a-logo-for-metacpan</link>
      <guid>http://blog.kraih.com/a-logo-for-metacpan</guid>
      <description>
        <![CDATA[<p>
	<p>In case you've missed it, there is currently a <a href="http://contest.metacpan.org/">logo contest for MetaCPAN</a> in progress. I'm generally not a big fan of contests, but since it's for the Perl community, i'm participating as well. Here's what i came up with. (the official entry should later show up&nbsp;<a href="http://entries.contest.metacpan.org/2012/01/sebastian-riedel-retro.html">here</a>)</p>
<p><div class='p_embed p_image_embed'>
<img alt="Sri_cpan_org-retro-rendered-1-120103" height="260" src="http://getfile2.posterous.com/getfile/files.posterous.com/temp-2012-01-03/ubqAeJuinBJjllclzyEFGDBzryqCheBvnvAIhmqutkpBBtfAjtrxpIfhavcz/sri_cpan_org-retro-rendered-1-120103.png.scaled500.png" width="500" />
</div>
</p>
<p><span style="font-family: Helvetica;">No fonts were harmed in the making of this logo, every character is custom made. I tried to combine a retro and futuristic feel, to highlight the long history of Perl and the fact that the CPAN is still science fiction for many programming languages. The three flying pixels are a metaphor for modules, small building blocks that can be combined to form something new. Hope you like it.</span></p>
<p><span style="font-family: Helvetica;"><div class='p_embed p_image_embed'>
<img alt="Sri_cpan_org-retro-rendered-2-120103" height="260" src="http://getfile3.posterous.com/getfile/files.posterous.com/temp-2012-01-03/EHcxgDEJcxtCuoIDsysuhxaulDheIbjeshmjqHFDleuqynBArmfvnxqaCnEI/sri_cpan_org-retro-rendered-2-120103.png" width="500" />
</div>
<br /></span></p>
<p><span style="font-family: Helvetica;">Have fun!</span></p>
	
</p>

<p><a href="http://blog.kraih.com/a-logo-for-metacpan">Permalink</a> 

	| <a href="http://blog.kraih.com/a-logo-for-metacpan#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="260" width="500" url="http://getfile0.posterous.com/getfile/files.posterous.com/temp-2012-01-03/ubqAeJuinBJjllclzyEFGDBzryqCheBvnvAIhmqutkpBBtfAjtrxpIfhavcz/sri_cpan_org-retro-rendered-1-120103.png">
        <media:thumbnail height="260" width="500" url="http://getfile2.posterous.com/getfile/files.posterous.com/temp-2012-01-03/ubqAeJuinBJjllclzyEFGDBzryqCheBvnvAIhmqutkpBBtfAjtrxpIfhavcz/sri_cpan_org-retro-rendered-1-120103.png.scaled500.png" />
      </media:content>
      <media:content type="image/png" height="260" width="500" url="http://getfile3.posterous.com/getfile/files.posterous.com/temp-2012-01-03/EHcxgDEJcxtCuoIDsysuhxaulDheIbjeshmjqHFDleuqynBArmfvnxqaCnEI/sri_cpan_org-retro-rendered-2-120103.png">
        <media:thumbnail height="260" width="500" url="http://getfile3.posterous.com/getfile/files.posterous.com/temp-2012-01-03/EHcxgDEJcxtCuoIDsysuhxaulDheIbjeshmjqHFDleuqynBArmfvnxqaCnEI/sri_cpan_org-retro-rendered-2-120103.png" />
      </media:content>
    </item>
    <item>
      <pubDate>Sat, 31 Dec 2011 15:30:00 -0800</pubDate>
      <title>A Mojolicious 2011</title>
      <link>http://blog.kraih.com/a-mojolicious-2011</link>
      <guid>http://blog.kraih.com/a-mojolicious-2011</guid>
      <description>
        <![CDATA[<p>
	<p>Happy new year everyone, it's amazing how much <a href="http://mojolicio.us">Mojolicious</a> has progressed and grown in 2011, Marcus Ramberg has prepared <a href="http://marcus.nordaaker.com/2011/12/a-mojolicious-2011/">a little retrospection for us</a>.</p>
<blockquote class="posterous_medium_quote">
<p>A new year is upon us, and I figured this would be good time to take a look at the improvements in the Mojolicious framework in the last year. There has been a dazzling number of releases, 122 in fact, including the current release, 2.42.</p>
</blockquote>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/a-mojolicious-2011">Permalink</a> 

	| <a href="http://blog.kraih.com/a-mojolicious-2011#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Mon, 26 Dec 2011 02:42:00 -0800</pubDate>
      <title>Mojocast #5 Mojo::UserAgent</title>
      <link>http://blog.kraih.com/mojocast-5-user-agent</link>
      <guid>http://blog.kraih.com/mojocast-5-user-agent</guid>
      <description>
        <![CDATA[<p>
	<p><div class='p_embed p_image_embed'>
<a href="http://getfile7.posterous.com/getfile/files.posterous.com/temp-2011-12-26/lkEngauBHhpvAfiFeJAoEHJHwimHiudepaACrDitIFhkckturGixrucrpkCz/mojocast_5_splash.png.scaled1000.png"><img alt="Mojocast_5_splash" height="375" src="http://getfile6.posterous.com/getfile/files.posterous.com/temp-2011-12-26/lkEngauBHhpvAfiFeJAoEHJHwimHiudepaACrDitIFhkckturGixrucrpkCz/mojocast_5_splash.png.scaled500.png" width="500" /></a>
</div>
</p>
<p>Merry christmas everyone, today Glen "tempire" Hinkle has a special treat for us. In this Mojocast he demonstrates why interacting with the web from Perl has never been this much fun before, <a href="http://mojocasts.com/e5">you should take a look</a>!</p>
<blockquote class="posterous_medium_quote">
<p>Mojocast Monday brings you a high-level overview of Mojo::UserAgent, the client side of Mojolicious. DOM Walking, CSS selectors, and watching live requests are just a couple of the things you'll see.</p>
</blockquote>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojocast-5-user-agent">Permalink</a> 

	| <a href="http://blog.kraih.com/mojocast-5-user-agent#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="601" width="801" url="http://getfile3.posterous.com/getfile/files.posterous.com/temp-2011-12-26/lkEngauBHhpvAfiFeJAoEHJHwimHiudepaACrDitIFhkckturGixrucrpkCz/mojocast_5_splash.png">
        <media:thumbnail height="375" width="500" url="http://getfile6.posterous.com/getfile/files.posterous.com/temp-2011-12-26/lkEngauBHhpvAfiFeJAoEHJHwimHiudepaACrDitIFhkckturGixrucrpkCz/mojocast_5_splash.png.scaled500.png" />
      </media:content>
    </item>
    <item>
      <pubDate>Mon, 14 Nov 2011 06:56:00 -0800</pubDate>
      <title>Mojocast #4 Stash, Flash, and Sessions</title>
      <link>http://blog.kraih.com/mojocast-4-stash-flash-and-sessions</link>
      <guid>http://blog.kraih.com/mojocast-4-stash-flash-and-sessions</guid>
      <description>
        <![CDATA[<p>
	<p>Happy <a href="http://mojocasts.com">Mojocast</a> monday everyone. This time Glen "tempire" Hinkle will explain to you the very important task of sharing data between the various parts of a&nbsp;<a href="http://mojolicio.us">Mojolicious</a> application. So, what are you waiting for? Get <a href="http://mojocasts.com/e4">over there</a> and learn web development with Perl in no time!</p>
<p><div class='p_embed p_image_embed'>
<img alt="Mojocast4" height="300" src="http://getfile6.posterous.com/getfile/files.posterous.com/temp-2011-11-14/qznbmGoABzAzJxCvzbDjAtnpnHsGogvgickunoBwnrlnGgayxnbAnkHytjJs/mojocast4.png.scaled500.png" width="500" />
</div>
</p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojocast-4-stash-flash-and-sessions">Permalink</a> 

	| <a href="http://blog.kraih.com/mojocast-4-stash-flash-and-sessions#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="300" width="500" url="http://getfile3.posterous.com/getfile/files.posterous.com/temp-2011-11-14/qznbmGoABzAzJxCvzbDjAtnpnHsGogvgickunoBwnrlnGgayxnbAnkHytjJs/mojocast4.png">
        <media:thumbnail height="300" width="500" url="http://getfile6.posterous.com/getfile/files.posterous.com/temp-2011-11-14/qznbmGoABzAzJxCvzbDjAtnpnHsGogvgickunoBwnrlnGgayxnbAnkHytjJs/mojocast4.png.scaled500.png" />
      </media:content>
    </item>
    <item>
      <pubDate>Mon, 31 Oct 2011 23:36:00 -0700</pubDate>
      <title>Mojolicious hack of the day: WebSockets</title>
      <link>http://blog.kraih.com/mojolicious-hack-of-the-day-websockets</link>
      <guid>http://blog.kraih.com/mojolicious-hack-of-the-day-websockets</guid>
      <description>
        <![CDATA[<p>
	<p>By now you've probably heard about <a href="http://en.wikipedia.org/wiki/WebSocket">WebSockets</a>, and that they are the future of web development, but so far there are very little examples that really show how easy to use they actually are. So today we are going to explore the wonderful world of events in <a href="http://mojolicio.us/">Mojolicious</a>&nbsp;a bit and build a little application that forwards all framework log messages to a browser window. (works best in <a href="http://www.google.com/chrome">Chrome</a>)</p>
<p><div class="data type-perl">
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
<span rel="#L17" id="L17">17</span>
<span rel="#L18" id="L18">18</span>
<span rel="#L19" id="L19">19</span>
<span rel="#L20" id="L20">20</span>
<span rel="#L21" id="L21">21</span>
<span rel="#L22" id="L22">22</span>
<span rel="#L23" id="L23">23</span>
<span rel="#L24" id="L24">24</span>
<span rel="#L25" id="L25">25</span>
<span rel="#L26" id="L26">26</span>
<span rel="#L27" id="L27">27</span>
<span rel="#L28" id="L28">28</span>
<span rel="#L29" id="L29">29</span>
<span rel="#L30" id="L30">30</span>
<span rel="#L31" id="L31">31</span>
<span rel="#L32" id="L32">32</span>
<span rel="#L33" id="L33">33</span>
<span rel="#L34" id="L34">34</span>
<span rel="#L35" id="L35">35</span>
<span rel="#L36" id="L36">36</span>
<span rel="#L37" id="L37">37</span>
<span rel="#L38" id="L38">38</span>
<span rel="#L39" id="L39">39</span>
<span rel="#L40" id="L40">40</span>
<span rel="#L41" id="L41">41</span>
<span rel="#L42" id="L42">42</span>
<span rel="#L43" id="L43">43</span>
<span rel="#L44" id="L44">44</span>
<span rel="#L45" id="L45">45</span>
<span rel="#L46" id="L46">46</span>
<span rel="#L47" id="L47">47</span>
<span rel="#L48" id="L48">48</span>
<span rel="#L49" id="L49">49</span>
</pre>
          </td>
          <td width="100%">
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="c1">#!/usr/bin/env perl</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">Mojolicious::</span><span class="n">Lite</span><span class="p">;</span></div><div class="line" id="LC3"><br /></div><div class="line" id="LC4"><span class="c1"># Documentation under &quot;/perldoc&quot;</span></div><div class="line" id="LC5"><span class="n">plugin</span> <span class="s">&#39;PODRenderer&#39;</span><span class="p">;</span></div><div class="line" id="LC6"><br /></div><div class="line" id="LC7"><span class="c1"># Template with browser-side code</span></div><div class="line" id="LC8"><span class="n">get</span> <span class="s">&#39;/&#39;</span> <span class="o">=&gt;</span> <span class="s">&#39;index&#39;</span><span class="p">;</span></div><div class="line" id="LC9"><br /></div><div class="line" id="LC10"><span class="c1"># WebSocket log service</span></div><div class="line" id="LC11"><span class="n">websocket</span> <span class="s">&#39;/log&#39;</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC12">&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$self</span> <span class="o">=</span> <span class="nb">shift</span><span class="p">;</span></div><div class="line" id="LC13"><br /></div><div class="line" id="LC14">&nbsp;&nbsp;<span class="c1"># Subscribe to &quot;message&quot; event of Mojo::Log</span></div><div class="line" id="LC15">&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$cb</span> <span class="o">=</span> <span class="nv">$self</span><span class="o">-&gt;</span><span class="n">app</span><span class="o">-&gt;</span><span class="nb">log</span><span class="o">-&gt;</span><span class="n">on</span><span class="p">(</span><span class="n">message</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC16">&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">my</span> <span class="p">(</span><span class="nv">$log</span><span class="p">,</span> <span class="nv">$level</span><span class="p">,</span> <span class="nv">@message</span><span class="p">)</span> <span class="o">=</span> <span class="nv">@_</span><span class="p">;</span></div><div class="line" id="LC17"><br /></div><div class="line" id="LC18">&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1"># Send message via WebSocket</span></div><div class="line" id="LC19">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">send_message</span><span class="p">(</span><span class="s">&quot;[$level] @message&quot;</span><span class="p">);</span></div><div class="line" id="LC20">&nbsp;&nbsp;<span class="p">});</span></div><div class="line" id="LC21"><br /></div><div class="line" id="LC22">&nbsp;&nbsp;<span class="c1"># Unsubscribe again from &quot;message&quot; event of Mojo::Log</span></div><div class="line" id="LC23">&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">on</span><span class="p">(</span><span class="n">finish</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC24">&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$self</span> <span class="o">=</span> <span class="nb">shift</span><span class="p">;</span></div><div class="line" id="LC25">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">app</span><span class="o">-&gt;</span><span class="nb">log</span><span class="o">-&gt;</span><span class="n">unsubscribe</span><span class="p">(</span><span class="n">message</span> <span class="o">=&gt;</span> <span class="nv">$cb</span><span class="p">);</span></div><div class="line" id="LC26">&nbsp;&nbsp;<span class="p">});</span></div><div class="line" id="LC27"><span class="p">};</span></div><div class="line" id="LC28"><br /></div><div class="line" id="LC29"><span class="n">app</span><span class="o">-&gt;</span><span class="n">start</span><span class="p">;</span></div><div class="line" id="LC30"><span class="bp">__DATA__</span></div><div class="line" id="LC31"><br /></div><div class="line" id="LC32"><span class="nv">@@</span> <span class="nv">index</span><span class="o">.</span><span class="n">html</span><span class="o">.</span><span class="n">ep</span></div><div class="line" id="LC33"><span class="o">&lt;!</span><span class="n">doctype</span> <span class="n">html</span><span class="o">&gt;</span><span class="sr">&lt;html&gt;</span></div><div class="line" id="LC34">&nbsp;&nbsp;<span class="sr">&lt;head&gt;&lt;title&gt;</span><span class="n">Mojolicious</span> <span class="n">Log</span><span class="sr">&lt;/title&gt;&lt;/head&gt;</span></div><div class="line" id="LC35">&nbsp;&nbsp;<span class="sr">&lt;body&gt;</span></div><div class="line" id="LC36">&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">&lt;</span><span class="nv">%</span><span class="err">=</span> <span class="nv">link_to</span> <span class="s">&#39;New window&#39;</span> <span class="o">=&gt;</span> <span class="s">&#39;/perldoc&#39;</span><span class="p">,</span> <span class="n">target</span> <span class="o">=&gt;</span> <span class="s">&#39;_blank&#39;</span> <span class="nv">%</span><span class="err">&gt;</span></div><div class="line" id="LC37">&nbsp;&nbsp;&nbsp;&nbsp;<span class="err">&lt;</span><span class="nv">br</span><span class="o">/&gt;</span></div><div class="line" id="LC38">&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">&lt;script&gt;</span></div><div class="line" id="LC39"><br /></div><div class="line" id="LC40">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">//</span> <span class="n">This</span> <span class="n">needs</span> <span class="n">a</span> <span class="s">&quot;Moz&quot;</span> <span class="n">prefix</span> <span class="n">to</span> <span class="n">work</span> <span class="n">in</span> <span class="n">Firefox</span></div><div class="line" id="LC41">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">var</span> <span class="n">ws</span> <span class="o">=</span> <span class="k">new</span> <span class="n">WebSocket</span><span class="p">(</span><span class="s">&#39;&lt;%= url_for(&#39;</span><span class="nb">log</span><span class="s">&#39;)-&gt;to_abs %&gt;&#39;</span><span class="p">);</span></div><div class="line" id="LC42"><br /></div><div class="line" id="LC43">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">//</span> <span class="n">Incoming</span> <span class="n">WebSocket</span> <span class="n">messages</span></div><div class="line" id="LC44">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">ws</span><span class="o">.</span><span class="n">onmessage</span> <span class="o">=</span> <span class="n">function</span><span class="p">(</span><span class="n">event</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="LC45">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">document</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">innerHTML</span> <span class="o">+=</span> <span class="n">event</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="s">&#39;&lt;br/&gt;&#39;</span><span class="p">;</span></div><div class="line" id="LC46">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">};</span></div><div class="line" id="LC47">&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">&lt;/script&gt;</span></div><div class="line" id="LC48">&nbsp;&nbsp;<span class="sr">&lt;/body&gt;</span></div><div class="line" id="LC49"><span class="sr">&lt;/html&gt;</span></div></pre></div>
          </td>
        </tr>
      </table>
  </div></p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-hack-of-the-day-websockets">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-hack-of-the-day-websockets#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Mon, 17 Oct 2011 08:24:00 -0700</pubDate>
      <title>Mojolicious 2.0 released: Perl real-time web framework</title>
      <link>http://blog.kraih.com/mojolicious-20-released-perl-real-time-web-fr</link>
      <guid>http://blog.kraih.com/mojolicious-20-released-perl-real-time-web-fr</guid>
      <description>
        <![CDATA[<p>
	<p><div class='p_embed p_image_embed'>
<img alt="Autumn" height="289" src="http://posterous.com/getfile/files.posterous.com/temp-2011-10-17/fFrHvugwIyGFxvwfzccvcIycruhbxCvziiziFcBrJbutAlgvmqykrcwmzvHA/autumn.png.scaled500.png" width="438" />
</div>
I'm very happy to announce the release of <a href="http://mojolicio.us">Mojolicious</a> 2.0 (Leaf Fluttering In Wind).</p>
<p>It is now almost a year since our <a href="http://blog.kraih.com/mojolicious-10-released">first stable release</a>, and what a great year it has been. The community really exploded, with now over 100 regulars on the IRC channel and <a href="https://github.com/kraih/mojo">450 watchers on GitHub</a>, making us by far the most successful CPAN module there. Thanks everyone!</p>
<p>Of course we also have many new features for you, here are the highlights:</p>
<ul>
<li><strong>Perl 5.10.1:</strong>&nbsp;We have finally increased the Perl version requirement and are already using all new features extensively. The performance increase is substantial, especially if you're coming from Perl 5.8.</li>
<li><strong>Morbo:&nbsp;</strong>A brand new self-restarting development web server that <a href="http://mojolicio.us/perldoc/Mojolicious/Lite#Reloading">just works</a>, even on Windows.</li>
<li><strong>libev:</strong>&nbsp;Native support for the <a href="https://metacpan.org/module/EV">EV</a> event loop and in turn <a href="https://metacpan.org/module/AnyEvent">AnyEvent</a>. (<a href="http://blog.kraih.com/mojolicious-hack-of-the-day-anyevent">example</a>)</li>
<li><strong>Events:</strong>&nbsp;Many objects now <a href="http://mojolicio.us/perldoc/Mojo/EventEmitter#SYNOPSIS">emit events</a>, which can be used to extend Mojolicious. (you'll hear much more about this soon, it's very cool)</li>
<li><strong>Mount plugin:</strong>&nbsp;Whole Mojolicious applications can now be <a href="http://mojolicio.us/perldoc/Mojolicious/Plugin/Mount#SYNOPSIS">embedded easily</a>.</li>
<li><strong>Groups:</strong>&nbsp;Mojolicious::Lite applications became a lot more powerful. (<a href="http://blog.kraih.com/mojolicious-hack-of-the-day-groups">example</a>)</li>
<li><strong>Hypnotoad:</strong>&nbsp;Our primary production web server got a lot more <a href="http://mojolicio.us/perldoc/Mojolicious/Guides/Cookbook#Hypnotoad">user friendly</a>.</li>
<li><strong>Collections:</strong>&nbsp;Making web scraping a hell of a lot of fun. (<a href="http://blog.kraih.com/mojolicious-hack-of-the-day-web-scraping-with">example</a>)</li>
<li><strong>WebSocket testing:</strong>&nbsp;You won't believe how easy it can be. (<a href="http://blog.kraih.com/mojolicious-hack-of-the-day-testing-websocket">example</a>)</li>
</ul>
<p>And as usual there is a lot more to discover, see <a href="https://github.com/kraih/mojo/blob/7321e4c7b83a19286b3309df53fc6d4d2e7460f0/Changes">Changes</a> on GitHub for the full list of improvements.</p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-20-released-perl-real-time-web-fr">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-20-released-perl-real-time-web-fr#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="289" width="438" url="http://getfile2.posterous.com/getfile/files.posterous.com/temp-2011-10-17/fFrHvugwIyGFxvwfzccvcIycruhbxCvziiziFcBrJbutAlgvmqykrcwmzvHA/autumn.png">
        <media:thumbnail height="289" width="438" url="http://getfile0.posterous.com/getfile/files.posterous.com/temp-2011-10-17/fFrHvugwIyGFxvwfzccvcIycruhbxCvziiziFcBrJbutAlgvmqykrcwmzvHA/autumn.png.scaled500.png" />
      </media:content>
    </item>
    <item>
      <pubDate>Wed, 12 Oct 2011 04:26:00 -0700</pubDate>
      <title>Mojolicious hack of the day: Web scraping with collections</title>
      <link>http://blog.kraih.com/mojolicious-hack-of-the-day-web-scraping-with</link>
      <guid>http://blog.kraih.com/mojolicious-hack-of-the-day-web-scraping-with</guid>
      <description>
        <![CDATA[<p>
	<p>Today we are going to use the <a href="http://mojolicio.us">Mojolicious</a> <a href="http://mojolicio.us/perldoc/Mojo/UserAgent">user agent</a> to scrape Perl headlines from <a href="http://www.reddit.com/r/perl/">Reddit</a>, and then transform them further with <a href="http://mojolicio.us/perldoc/Mojo/Collection">collections</a>, another one of our latest experimental features.</p>
<p><div class="data type-perl">
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
<span rel="#L17" id="L17">17</span>
<span rel="#L18" id="L18">18</span>
<span rel="#L19" id="L19">19</span>
<span rel="#L20" id="L20">20</span>
<span rel="#L21" id="L21">21</span>
<span rel="#L22" id="L22">22</span>
<span rel="#L23" id="L23">23</span>
<span rel="#L24" id="L24">24</span>
<span rel="#L25" id="L25">25</span>
<span rel="#L26" id="L26">26</span>
<span rel="#L27" id="L27">27</span>
<span rel="#L28" id="L28">28</span>
<span rel="#L29" id="L29">29</span>
<span rel="#L30" id="L30">30</span>
</pre>
          </td>
          <td width="100%">
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="c1">#!/usr/bin/env perl</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">Mojo::</span><span class="n">Base</span> <span class="o">-</span><span class="n">strict</span><span class="p">;</span></div><div class="line" id="LC3"><span class="k">use</span> <span class="nn">Mojo::</span><span class="n">UserAgent</span><span class="p">;</span></div><div class="line" id="LC4"><br /></div><div class="line" id="LC5"><span class="c1"># Lets start by fetching the current top Perl stories from Reddit</span></div><div class="line" id="LC6"><span class="k">my</span> <span class="nv">$reddit</span> <span class="o">=</span></div><div class="line" id="LC7">&nbsp;&nbsp;<span class="nn">Mojo::</span><span class="n">UserAgent</span><span class="o">-&gt;</span><span class="k">new</span><span class="o">-&gt;</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;www.reddit.com/r/perl&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="n">res</span><span class="o">-&gt;</span><span class="n">dom</span><span class="p">;</span></div><div class="line" id="LC8"><br /></div><div class="line" id="LC9"><span class="c1"># And extract all titles from the HTML</span></div><div class="line" id="LC10"><span class="k">my</span> <span class="nv">$titles</span> <span class="o">=</span></div><div class="line" id="LC11">&nbsp;&nbsp;<span class="nv">$reddit</span><span class="o">-&gt;</span><span class="n">find</span><span class="p">(</span><span class="s">&#39;p.title &gt; a.title&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="nb">map</span><span class="p">(</span><span class="k">sub </span><span class="p">{</span> <span class="nv">$_</span><span class="o">-&gt;</span><span class="n">text</span> <span class="p">});</span></div><div class="line" id="LC12"><br /></div><div class="line" id="LC13"><span class="c1"># How many do we got?</span></div><div class="line" id="LC14"><span class="n">say</span> <span class="s">&#39;Found &#39;</span><span class="p">,</span> <span class="nv">$titles</span><span class="o">-&gt;</span><span class="n">size</span><span class="p">,</span> <span class="s">&#39; stories.&#39;</span><span class="p">;</span></div><div class="line" id="LC15"><br /></div><div class="line" id="LC16"><span class="c1"># Wonder how many actually contain the word &quot;Perl&quot;</span></div><div class="line" id="LC17"><span class="n">say</span> <span class="nv">$titles</span><span class="o">-&gt;</span><span class="nb">grep</span><span class="p">(</span><span class="k">sub </span><span class="p">{</span><span class="sr">/perl/i</span><span class="p">})</span><span class="o">-&gt;</span><span class="n">size</span><span class="p">,</span> <span class="s">&#39; contain the word Perl.&#39;</span><span class="p">;</span></div><div class="line" id="LC18"><br /></div><div class="line" id="LC19"><span class="c1"># Top story</span></div><div class="line" id="LC20"><span class="n">say</span> <span class="s">&#39;Current top story is: &#39;</span><span class="p">,</span> <span class="nv">$titles</span><span class="o">-&gt;</span><span class="n">first</span><span class="p">;</span></div><div class="line" id="LC21"><br /></div><div class="line" id="LC22"><span class="c1"># Third story</span></div><div class="line" id="LC23"><span class="n">say</span> <span class="s">&#39;Third story is: &#39;</span><span class="p">,</span> <span class="nv">$titles</span><span class="o">-&gt;</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span></div><div class="line" id="LC24"><br /></div><div class="line" id="LC25"><span class="c1"># Random story that contains the word &quot;Perl&quot;</span></div><div class="line" id="LC26"><span class="n">say</span> <span class="s">&#39;Random Perl story: &#39;</span><span class="p">,</span> <span class="nv">$titles</span><span class="o">-&gt;</span><span class="n">shuffle</span><span class="o">-&gt;</span><span class="n">first</span><span class="p">(</span><span class="k">sub </span><span class="p">{</span><span class="sr">/perl/i</span><span class="p">});</span></div><div class="line" id="LC27"><br /></div><div class="line" id="LC28"><span class="c1"># And now we go a little crazy :)</span></div><div class="line" id="LC29"><span class="n">say</span> <span class="s">&quot;Stories 2-5 in Base64:\n&quot;</span><span class="p">,</span></div><div class="line" id="LC30">&nbsp;&nbsp;<span class="nv">$titles</span><span class="o">-&gt;</span><span class="n">slice</span><span class="p">(</span><span class="mi">1</span> <span class="o">..</span> <span class="mi">4</span><span class="p">)</span><span class="o">-&gt;</span><span class="nb">join</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="n">b64_encode</span><span class="p">;</span></div></pre></div>
          </td>
        </tr>
      </table>
  </div></p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-hack-of-the-day-web-scraping-with">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-hack-of-the-day-web-scraping-with#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Wed, 05 Oct 2011 07:24:00 -0700</pubDate>
      <title>Mojolicious hack of the day: Groups</title>
      <link>http://blog.kraih.com/mojolicious-hack-of-the-day-groups</link>
      <guid>http://blog.kraih.com/mojolicious-hack-of-the-day-groups</guid>
      <description>
        <![CDATA[<p>
	<p>Today i'm going to show you one of our latest experimental features. In the past we've mostly encouraged just to use&nbsp;<a href="http://mojolicio.us">Mojolicious</a> instead of <a href="http://mojolicio.us/perldoc/Mojolicious/Lite">Mojolicious::Lite</a> for all non-trivial applications, but over time it has become clear that even for single file prototypes you sometimes need a little more power. We've addressed this recently with the addition of <em>group</em> blocks, which allow&nbsp;<em>under</em> statements to be nested.</p>
<p><div class="data type-perl">
    
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
<span rel="#L17" id="L17">17</span>
<span rel="#L18" id="L18">18</span>
<span rel="#L19" id="L19">19</span>
<span rel="#L20" id="L20">20</span>
<span rel="#L21" id="L21">21</span>
<span rel="#L22" id="L22">22</span>
<span rel="#L23" id="L23">23</span>
<span rel="#L24" id="L24">24</span>
<span rel="#L25" id="L25">25</span>
<span rel="#L26" id="L26">26</span>
<span rel="#L27" id="L27">27</span>
<span rel="#L28" id="L28">28</span>
<span rel="#L29" id="L29">29</span>
<span rel="#L30" id="L30">30</span>
</pre>
          </td>
          <td width="100%">
            
              
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="c1">#!/usr/bin/env perl</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">Mojolicious::</span><span class="n">Lite</span><span class="p">;</span></div><div class="line" id="LC3"><br /></div><div class="line" id="LC4"><span class="c1"># Global logic shared by all routes</span></div><div class="line" id="LC5"><span class="n">under</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC6">&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$self</span> <span class="o">=</span> <span class="nb">shift</span><span class="p">;</span></div><div class="line" id="LC7">&nbsp;&nbsp;<span class="k">return</span> <span class="mi">1</span> <span class="k">if</span> <span class="nv">$self</span><span class="o">-&gt;</span><span class="n">req</span><span class="o">-&gt;</span><span class="n">headers</span><span class="o">-&gt;</span><span class="n">header</span><span class="p">(</span><span class="s">&#39;X-Bender&#39;</span><span class="p">);</span></div><div class="line" id="LC8">&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">render</span><span class="p">(</span><span class="n">text</span> <span class="o">=&gt;</span> <span class="s">&quot;You&#39;re not Bender!&quot;</span><span class="p">);</span></div><div class="line" id="LC9">&nbsp;&nbsp;<span class="k">return</span><span class="p">;</span></div><div class="line" id="LC10"><span class="p">};</span></div><div class="line" id="LC11"><br /></div><div class="line" id="LC12"><span class="c1"># Admin section</span></div><div class="line" id="LC13"><span class="n">group</span> <span class="p">{</span></div><div class="line" id="LC14"><br /></div><div class="line" id="LC15">&nbsp;&nbsp;<span class="c1"># Local logic shared only by routes in this group</span></div><div class="line" id="LC16">&nbsp;&nbsp;<span class="n">under</span> <span class="s">&#39;/admin&#39;</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC17">&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$self</span> <span class="o">=</span> <span class="nb">shift</span><span class="p">;</span></div><div class="line" id="LC18">&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="mi">1</span> <span class="k">if</span> <span class="nv">$self</span><span class="o">-&gt;</span><span class="n">req</span><span class="o">-&gt;</span><span class="n">headers</span><span class="o">-&gt;</span><span class="n">header</span><span class="p">(</span><span class="s">&#39;X-Awesome&#39;</span><span class="p">);</span></div><div class="line" id="LC19">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">render</span><span class="p">(</span><span class="n">text</span> <span class="o">=&gt;</span> <span class="s">&quot;You&#39;re not awesome enough!&quot;</span><span class="p">);</span></div><div class="line" id="LC20">&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span><span class="p">;</span></div><div class="line" id="LC21">&nbsp;&nbsp;<span class="p">};</span></div><div class="line" id="LC22"><br /></div><div class="line" id="LC23">&nbsp;&nbsp;<span class="c1"># GET /admin/dashboard</span></div><div class="line" id="LC24">&nbsp;&nbsp;<span class="n">get</span> <span class="s">&#39;/dashboard&#39;</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="n">text</span> <span class="o">=&gt;</span> <span class="s">&#39;Nothing to see here yet!&#39;</span><span class="p">};</span></div><div class="line" id="LC25"><span class="p">};</span></div><div class="line" id="LC26"><br /></div><div class="line" id="LC27"><span class="c1"># GET /welcome</span></div><div class="line" id="LC28"><span class="n">get</span> <span class="s">&#39;/welcome&#39;</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="n">text</span> <span class="o">=&gt;</span> <span class="s">&#39;Hi Bender!&#39;</span><span class="p">};</span></div><div class="line" id="LC29"><br /></div><div class="line" id="LC30"><span class="n">app</span><span class="o">-&gt;</span><span class="n">start</span><span class="p">;</span></div></pre></div>
              
            
          </td>
        </tr>
      </table>
    
  </div></p>
<p>And don't forget to give feedback if you like one of our experimental features, or they might never leave the experimental stage. ;)</p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-hack-of-the-day-groups">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-hack-of-the-day-groups#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Tue, 27 Sep 2011 08:24:00 -0700</pubDate>
      <title>Mojolicious hack of the day: AnyEvent</title>
      <link>http://blog.kraih.com/mojolicious-hack-of-the-day-anyevent</link>
      <guid>http://blog.kraih.com/mojolicious-hack-of-the-day-anyevent</guid>
      <description>
        <![CDATA[<p>
	<p>When we recently added the <a href="https://metacpan.org/module/EV">EV</a> backend to <a href="http://mojolicio.us">Mojolicious</a>,&nbsp;we not only got better performance and scalability, but also native support for <a href="https://metacpan.org/module/AnyEvent">AnyEvent</a>. And to demonstrate how easy to use it actually is, we are going to extend the <a href="http://blog.kraih.com/mojolicious-hack-of-the-day-html5-eventsource">HTML5 EventSource example</a> from last month with some non-blocking IRC goodness today. :)</p>
<p><div class="data type-perl">
    
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
<span rel="#L17" id="L17">17</span>
<span rel="#L18" id="L18">18</span>
<span rel="#L19" id="L19">19</span>
<span rel="#L20" id="L20">20</span>
<span rel="#L21" id="L21">21</span>
<span rel="#L22" id="L22">22</span>
<span rel="#L23" id="L23">23</span>
<span rel="#L24" id="L24">24</span>
<span rel="#L25" id="L25">25</span>
<span rel="#L26" id="L26">26</span>
<span rel="#L27" id="L27">27</span>
<span rel="#L28" id="L28">28</span>
<span rel="#L29" id="L29">29</span>
<span rel="#L30" id="L30">30</span>
<span rel="#L31" id="L31">31</span>
<span rel="#L32" id="L32">32</span>
<span rel="#L33" id="L33">33</span>
<span rel="#L34" id="L34">34</span>
<span rel="#L35" id="L35">35</span>
<span rel="#L36" id="L36">36</span>
<span rel="#L37" id="L37">37</span>
<span rel="#L38" id="L38">38</span>
<span rel="#L39" id="L39">39</span>
<span rel="#L40" id="L40">40</span>
<span rel="#L41" id="L41">41</span>
</pre>
          </td>
          <td width="100%">
            
              
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="c1">#!/usr/bin/env perl</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">Mojolicious::</span><span class="n">Lite</span><span class="p">;</span></div><div class="line" id="LC3"><span class="k">use</span> <span class="n">EV</span><span class="p">;</span></div><div class="line" id="LC4"><span class="k">use</span> <span class="nn">AnyEvent::IRC::</span><span class="n">Client</span><span class="p">;</span></div><div class="line" id="LC5"><br /></div><div class="line" id="LC6"><span class="c1"># Join #mojo on irc.perl.org</span></div><div class="line" id="LC7"><span class="k">my</span> <span class="nv">$irc</span> <span class="o">=</span> <span class="nn">AnyEvent::IRC::</span><span class="n">Client</span><span class="o">-&gt;</span><span class="k">new</span><span class="p">;</span></div><div class="line" id="LC8"><span class="nv">$irc</span><span class="o">-&gt;</span><span class="nb">connect</span><span class="p">(</span><span class="s">&#39;irc.perl.org&#39;</span><span class="p">,</span> <span class="mi">6667</span><span class="p">,</span> <span class="p">{</span><span class="n">nick</span> <span class="o">=&gt;</span> <span class="s">&quot;mojobot$$&quot;</span><span class="p">});</span></div><div class="line" id="LC9"><span class="nv">$irc</span><span class="o">-&gt;</span><span class="n">send_srv</span><span class="p">(</span><span class="n">JOIN</span> <span class="o">=&gt;</span> <span class="s">&#39;#mojo&#39;</span><span class="p">);</span></div><div class="line" id="LC10"><br /></div><div class="line" id="LC11"><span class="n">get</span> <span class="s">&#39;/&#39;</span> <span class="o">=&gt;</span> <span class="s">&#39;index&#39;</span><span class="p">;</span></div><div class="line" id="LC12"><br /></div><div class="line" id="LC13"><span class="n">get</span> <span class="s">&#39;/events&#39;</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC14">&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$self</span> <span class="o">=</span> <span class="nb">shift</span><span class="p">;</span></div><div class="line" id="LC15"><br /></div><div class="line" id="LC16">&nbsp;&nbsp;<span class="c1"># Emit &quot;msg&quot; event for every new IRC message</span></div><div class="line" id="LC17">&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">res</span><span class="o">-&gt;</span><span class="n">headers</span><span class="o">-&gt;</span><span class="n">content_type</span><span class="p">(</span><span class="s">&#39;text/event-stream&#39;</span><span class="p">);</span></div><div class="line" id="LC18">&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$g</span> <span class="o">=</span> <span class="nv">$irc</span><span class="o">-&gt;</span><span class="n">reg_cb</span><span class="p">(</span><span class="n">publicmsg</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC19">&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$message</span> <span class="o">=</span> <span class="nb">pop</span><span class="o">-&gt;</span><span class="p">{</span><span class="n">params</span><span class="p">}</span><span class="o">-&gt;</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span></div><div class="line" id="LC20">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="nb">write</span><span class="p">(</span><span class="s">&quot;event:msg\ndata: $message\n\n&quot;</span><span class="p">);</span></div><div class="line" id="LC21">&nbsp;&nbsp;<span class="p">});</span></div><div class="line" id="LC22">&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">on_finish</span><span class="p">(</span><span class="k">sub </span><span class="p">{</span> <span class="nb">undef</span> <span class="nv">$g</span> <span class="p">});</span></div><div class="line" id="LC23"><span class="p">};</span></div><div class="line" id="LC24"><br /></div><div class="line" id="LC25"><span class="n">app</span><span class="o">-&gt;</span><span class="n">start</span><span class="p">;</span></div><div class="line" id="LC26"><span class="bp">__DATA__</span></div><div class="line" id="LC27"><br /></div><div class="line" id="LC28"><span class="nv">@@</span> <span class="nv">index</span><span class="o">.</span><span class="n">html</span><span class="o">.</span><span class="n">ep</span></div><div class="line" id="LC29"><span class="o">&lt;!</span><span class="n">doctype</span> <span class="n">html</span><span class="o">&gt;</span><span class="sr">&lt;html&gt;</span></div><div class="line" id="LC30">&nbsp;&nbsp;<span class="sr">&lt;head&gt;&lt;title&gt;</span><span class="n">The</span> <span class="n">Mojolicious</span> <span class="n">IRC</span> <span class="n">channel</span><span class="sr">&lt;/title&gt;&lt;/head&gt;</span></div><div class="line" id="LC31">&nbsp;&nbsp;<span class="sr">&lt;body&gt;</span></div><div class="line" id="LC32">&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">&lt;script&gt;</span></div><div class="line" id="LC33">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">var</span> <span class="n">events</span> <span class="o">=</span> <span class="k">new</span> <span class="n">EventSource</span><span class="p">(</span><span class="s">&#39;&lt;%= url_for &#39;</span><span class="n">events</span><span class="s">&#39; %&gt;&#39;</span><span class="p">);</span></div><div class="line" id="LC34"><br /></div><div class="line" id="LC35">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">//</span> <span class="n">Subscribe</span> <span class="n">to</span> <span class="s">&quot;msg&quot;</span> <span class="n">event</span></div><div class="line" id="LC36">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">events</span><span class="o">.</span><span class="n">addEventListener</span><span class="p">(</span><span class="s">&#39;msg&#39;</span><span class="p">,</span> <span class="n">function</span><span class="p">(</span><span class="n">event</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="LC37">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">document</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">innerHTML</span> <span class="o">+=</span> <span class="n">event</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="s">&#39;&lt;br/&gt;&#39;</span><span class="p">;</span></div><div class="line" id="LC38">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">},</span> <span class="n">false</span><span class="p">);</span></div><div class="line" id="LC39">&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">&lt;/script&gt;</span></div><div class="line" id="LC40">&nbsp;&nbsp;<span class="sr">&lt;/body&gt;</span></div><div class="line" id="LC41"><span class="sr">&lt;/html&gt;</span></div></pre></div>
              
            
          </td>
        </tr>
      </table>
    
  </div></p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-hack-of-the-day-anyevent">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-hack-of-the-day-anyevent#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Mon, 19 Sep 2011 16:31:00 -0700</pubDate>
      <title>Mojolicious hack of the day: Testing WebSockets</title>
      <link>http://blog.kraih.com/mojolicious-hack-of-the-day-testing-websocket</link>
      <guid>http://blog.kraih.com/mojolicious-hack-of-the-day-testing-websocket</guid>
      <description>
        <![CDATA[<p>
	<p>In <a href="http://mojolicio.us">Mojolicious</a> we care a great deal about testing, after all most of Mojolicious itself was developed using <a href="http://en.wikipedia.org/wiki/Test-driven_development">test driven development</a>. Recently <a href="http://en.wikipedia.org/wiki/WebSocket">WebSockets</a> have turned out to be a real challenge in this regard, their extremely dynamic nature makes it pretty much impossible to design a simple Perl test API that would cover all possible use cases. Luckily we've been supporting WebSockets for quite some time and know by now that the exact message flow is known in advance for the most common ones, which led to this rather pleasant to use API. ;)</p>
<p><div class="data type-perl">
    
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
<span rel="#L17" id="L17">17</span>
<span rel="#L18" id="L18">18</span>
<span rel="#L19" id="L19">19</span>
<span rel="#L20" id="L20">20</span>
<span rel="#L21" id="L21">21</span>
<span rel="#L22" id="L22">22</span>
</pre>
          </td>
          <td width="100%">
            
              
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="c1">#!/usr/bin/env perl</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">Mojo::</span><span class="n">Base</span> <span class="o">-</span><span class="n">strict</span><span class="p">;</span></div><div class="line" id="LC3"><br /></div><div class="line" id="LC4"><span class="k">use</span> <span class="n">utf8</span><span class="p">;</span></div><div class="line" id="LC5"><br /></div><div class="line" id="LC6"><span class="k">use</span> <span class="nn">Test::</span><span class="n">More</span> <span class="n">tests</span> <span class="o">=&gt;</span> <span class="mi">4</span><span class="p">;</span></div><div class="line" id="LC7"><span class="k">use</span> <span class="nn">Mojolicious::</span><span class="n">Lite</span><span class="p">;</span></div><div class="line" id="LC8"><span class="k">use</span> <span class="nn">Test::</span><span class="n">Mojo</span><span class="p">;</span></div><div class="line" id="LC9"><br /></div><div class="line" id="LC10"><span class="c1"># Tiny echo web service</span></div><div class="line" id="LC11"><span class="n">websocket</span> <span class="s">&#39;/echo&#39;</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC12">&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$self</span> <span class="o">=</span> <span class="nb">shift</span><span class="p">;</span></div><div class="line" id="LC13">&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">on_message</span><span class="p">(</span><span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC14">&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">my</span> <span class="p">(</span><span class="nv">$self</span><span class="p">,</span> <span class="nv">$message</span><span class="p">)</span> <span class="o">=</span> <span class="nv">@_</span><span class="p">;</span></div><div class="line" id="LC15">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">send_message</span><span class="p">(</span><span class="s">&quot;echo: $message&quot;</span><span class="p">);</span></div><div class="line" id="LC16">&nbsp;&nbsp;<span class="p">});</span></div><div class="line" id="LC17"><span class="p">};</span></div><div class="line" id="LC18"><br /></div><div class="line" id="LC19"><span class="c1"># Send message and receive echo</span></div><div class="line" id="LC20"><span class="k">my</span> <span class="nv">$t</span> <span class="o">=</span> <span class="nn">Test::</span><span class="n">Mojo</span><span class="o">-&gt;</span><span class="k">new</span><span class="p">;</span></div><div class="line" id="LC21"><span class="nv">$t</span><span class="o">-&gt;</span><span class="n">websocket_ok</span><span class="p">(</span><span class="s">&#39;/echo&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="n">send_message_ok</span><span class="p">(</span><span class="s">&#39;I ♥ Mojolicious&#39;</span><span class="p">)</span></div><div class="line" id="LC22">&nbsp;&nbsp;<span class="o">-&gt;</span><span class="n">message_is</span><span class="p">(</span><span class="s">&#39;echo: I ♥ Mojolicious&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="n">finish_ok</span><span class="p">;</span></div></pre></div>
              
            
          </td>
        </tr>
      </table>
    
  </div></p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-hack-of-the-day-testing-websocket">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-hack-of-the-day-testing-websocket#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Mon, 12 Sep 2011 09:53:00 -0700</pubDate>
      <title>Mojocast #3 Authentication, Helpers, and Plugins</title>
      <link>http://blog.kraih.com/mojocast-3-authentication-helpers-and-plugins</link>
      <guid>http://blog.kraih.com/mojocast-3-authentication-helpers-and-plugins</guid>
      <description>
        <![CDATA[<p>
	<p>Yes, it's finally <a href="http://mojocasts.com/e3">Mojocasts</a> Monday again! And this time Glen "tempire" Hinkle makes some rather advanced topics like "under" and plugins look trivial. But what's maybe even more impressive than the actual screencast itself is the new HTML5 video player, not only does it provide us with even better video quality, but also the ability to link directly to <a href="http://mojocasts.com/e3#Under%20directive">individual chapters</a>.</p>
<p><iframe src="http://player.vimeo.com/video/28848359?portrait=0" frameborder="0" height="283" width="500"></iframe></p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojocast-3-authentication-helpers-and-plugins">Permalink</a> 

	| <a href="http://blog.kraih.com/mojocast-3-authentication-helpers-and-plugins#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Wed, 31 Aug 2011 03:16:00 -0700</pubDate>
      <title>Mojolicious hack of the day: CSS4</title>
      <link>http://blog.kraih.com/mojolicious-hack-of-the-day-css4</link>
      <guid>http://blog.kraih.com/mojolicious-hack-of-the-day-css4</guid>
      <description>
        <![CDATA[<p>
	<p>Sooner or later most web developers stumble over one not so insignificant weakness of&nbsp;<a href="http://www.w3.org/TR/css3-selectors/">CSS3 Selectors</a>, you can't select parent elements. So while you can select <strong><em>img</em></strong> elements with an <strong><em>a</em></strong> parent, you can't select <strong><em>a</em></strong>&nbsp;elements with an <em><strong>img</strong></em>&nbsp;child.</p>
<p>But this has recently been solved in a very clever way with the latest <a href="http://dev.w3.org/csswg/selectors4/#subject">CSS4 Selectors working draft</a>, where you can just change the subject of a selector by prepending a dollar sign to one of the compound selectors. And you might have guessed it, <a href="http://mojolicio.us/perldoc/Mojo/DOM/CSS#E_24F_G">Mojolicious</a>&nbsp;already brings this neat little feature to Perl. :)</p>
<p><div class="data type-perl">
    
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
<span rel="#L17" id="L17">17</span>
<span rel="#L18" id="L18">18</span>
<span rel="#L19" id="L19">19</span>
<span rel="#L20" id="L20">20</span>
<span rel="#L21" id="L21">21</span>
<span rel="#L22" id="L22">22</span>
</pre>
          </td>
          <td width="100%">
            
              
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="k">use</span> <span class="nn">Mojo::</span><span class="n">DOM</span><span class="p">;</span></div><div class="line" id="LC2"><br /></div><div class="line" id="LC3"><span class="c1"># Parse HTML5 snippet</span></div><div class="line" id="LC4"><span class="k">my</span> <span class="nv">$dom</span> <span class="o">=</span> <span class="nn">Mojo::</span><span class="n">DOM</span><span class="o">-&gt;</span><span class="k">new</span><span class="p">(</span><span class="o">&lt;&lt;</span><span class="n">EOF</span><span class="p">);</span></div><div class="line" id="LC5"><span class="sr">&lt;div&gt;</span></div><div class="line" id="LC6">&nbsp;&nbsp;<span class="o">&lt;</span><span class="n">a</span> <span class="n">href</span><span class="o">=</span><span class="s">&quot;http://search.cpan.org&quot;</span><span class="o">&gt;</span></div><div class="line" id="LC7">&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">&lt;</span><span class="n">img</span> <span class="n">src</span><span class="o">=</span><span class="s">&quot;/images/search.png&quot;</span><span class="o">&gt;</span></div><div class="line" id="LC8">&nbsp;&nbsp;<span class="sr">&lt;/a&gt;</span></div><div class="line" id="LC9">&nbsp;&nbsp;<span class="o">&lt;</span><span class="n">a</span> <span class="n">href</span><span class="o">=</span><span class="s">&quot;http://mojolicio.us&quot;</span><span class="o">&gt;</span></div><div class="line" id="LC10">&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">&lt;p&gt;</span><span class="n">Mojolicious</span><span class="sr">&lt;/p&gt;</span></div><div class="line" id="LC11">&nbsp;&nbsp;<span class="sr">&lt;/a&gt;</span></div><div class="line" id="LC12">&nbsp;&nbsp;<span class="o">&lt;</span><span class="n">a</span> <span class="n">href</span><span class="o">=</span><span class="s">&quot;http://metacpan.org&quot;</span><span class="o">&gt;</span></div><div class="line" id="LC13">&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">&lt;p&gt;</span><span class="o">&lt;</span><span class="n">img</span> <span class="n">src</span><span class="o">=</span><span class="s">&quot;/images/metacpan.png&quot;</span><span class="o">&gt;</span><span class="sr">&lt;/p&gt;</span></div><div class="line" id="LC14">&nbsp;&nbsp;<span class="sr">&lt;/a&gt;</span></div><div class="line" id="LC15"><span class="sr">&lt;/div&gt;</span></div><div class="line" id="LC16"><span class="n">EOF</span></div><div class="line" id="LC17"><br /></div><div class="line" id="LC18"><span class="c1"># Add class attribute to all image links</span></div><div class="line" id="LC19"><span class="nv">$dom</span><span class="o">-&gt;</span><span class="n">find</span><span class="p">(</span><span class="s">&#39;$a img&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="nb">each</span><span class="p">(</span><span class="k">sub </span><span class="p">{</span> <span class="nb">shift</span><span class="o">-&gt;</span><span class="p">{</span><span class="n">class</span><span class="p">}</span> <span class="o">=</span> <span class="s">&#39;logo&#39;</span> <span class="p">});</span></div><div class="line" id="LC20"><br /></div><div class="line" id="LC21"><span class="c1"># Render HTML5 snippet</span></div><div class="line" id="LC22"><span class="k">print</span> <span class="s">&quot;$dom&quot;</span><span class="p">;</span></div></pre></div>
              
            
          </td>
        </tr>
      </table>
    
  </div></p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-hack-of-the-day-css4">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-hack-of-the-day-css4#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Fri, 26 Aug 2011 00:48:00 -0700</pubDate>
      <title>Mojolicious hack of the day: HTML5 EventSource</title>
      <link>http://blog.kraih.com/mojolicious-hack-of-the-day-html5-eventsource</link>
      <guid>http://blog.kraih.com/mojolicious-hack-of-the-day-html5-eventsource</guid>
      <description>
        <![CDATA[<p>
	<p>For those not following me on <a href="http://twitter.com/kraih">Twitter</a>, "Mojolicious hack of the day" is a little series of fun Perl oneliners i've been posting every now and then over there to demonstrate new <a href="http://mojolicio.us">Mojolicious</a> features and web technologies. It has been rather popular, but there are many topics that require more than 140 characters, so i'm going to try something new with the blog and post more articles that are heavy on examples, hope you won't mind the lack of walls of text. :)</p>
<p>Today we are going to start with <a href="http://en.wikipedia.org/wiki/Server-sent_events">HTML5 EventSource</a>, which is a dead simple technology for streaming DOM events from the server to a browser. Unlike <a href="http://en.wikipedia.org/wiki/WebSocket">WebSockets</a>, it uses plain old HTTP for transport and is already supported by most common browsers.</p>
<p><div class="data type-perl">
    
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
<span rel="#L17" id="L17">17</span>
<span rel="#L18" id="L18">18</span>
<span rel="#L19" id="L19">19</span>
<span rel="#L20" id="L20">20</span>
<span rel="#L21" id="L21">21</span>
<span rel="#L22" id="L22">22</span>
<span rel="#L23" id="L23">23</span>
<span rel="#L24" id="L24">24</span>
<span rel="#L25" id="L25">25</span>
<span rel="#L26" id="L26">26</span>
<span rel="#L27" id="L27">27</span>
<span rel="#L28" id="L28">28</span>
<span rel="#L29" id="L29">29</span>
<span rel="#L30" id="L30">30</span>
<span rel="#L31" id="L31">31</span>
<span rel="#L32" id="L32">32</span>
<span rel="#L33" id="L33">33</span>
<span rel="#L34" id="L34">34</span>
<span rel="#L35" id="L35">35</span>
</pre>
          </td>
          <td width="100%">
            
              
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="c1">#!/usr/bin/env perl</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">Mojolicious::</span><span class="n">Lite</span><span class="p">;</span></div><div class="line" id="LC3"><br /></div><div class="line" id="LC4"><span class="n">get</span> <span class="s">&#39;/&#39;</span> <span class="o">=&gt;</span> <span class="s">&#39;index&#39;</span><span class="p">;</span></div><div class="line" id="LC5"><br /></div><div class="line" id="LC6"><span class="n">get</span> <span class="s">&#39;/events&#39;</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC7">&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$self</span> <span class="o">=</span> <span class="nb">shift</span><span class="p">;</span></div><div class="line" id="LC8"><br /></div><div class="line" id="LC9">&nbsp;&nbsp;<span class="c1"># Emit &quot;dice&quot; event every second</span></div><div class="line" id="LC10">&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">res</span><span class="o">-&gt;</span><span class="n">headers</span><span class="o">-&gt;</span><span class="n">content_type</span><span class="p">(</span><span class="s">&#39;text/event-stream&#39;</span><span class="p">);</span></div><div class="line" id="LC11">&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$id</span> <span class="o">=</span> <span class="nn">Mojo::</span><span class="n">IOLoop</span><span class="o">-&gt;</span><span class="n">recurring</span><span class="p">(</span><span class="mi">1</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC12">&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$pips</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">rand</span> <span class="mi">6</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span></div><div class="line" id="LC13">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="nb">write</span><span class="p">(</span><span class="s">&quot;event:dice\ndata: $pips\n\n&quot;</span><span class="p">);</span></div><div class="line" id="LC14">&nbsp;&nbsp;<span class="p">});</span></div><div class="line" id="LC15">&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">on_finish</span><span class="p">(</span><span class="k">sub </span><span class="p">{</span> <span class="nn">Mojo::</span><span class="n">IOLoop</span><span class="o">-&gt;</span><span class="n">drop</span><span class="p">(</span><span class="nv">$id</span><span class="p">)</span> <span class="p">});</span></div><div class="line" id="LC16"><span class="p">};</span></div><div class="line" id="LC17"><br /></div><div class="line" id="LC18"><span class="n">app</span><span class="o">-&gt;</span><span class="n">start</span><span class="p">;</span></div><div class="line" id="LC19"><span class="bp">__DATA__</span></div><div class="line" id="LC20"><br /></div><div class="line" id="LC21"><span class="nv">@@</span> <span class="nv">index</span><span class="o">.</span><span class="n">html</span><span class="o">.</span><span class="n">ep</span></div><div class="line" id="LC22"><span class="o">&lt;!</span><span class="n">doctype</span> <span class="n">html</span><span class="o">&gt;</span><span class="sr">&lt;html&gt;</span></div><div class="line" id="LC23">&nbsp;&nbsp;<span class="sr">&lt;head&gt;&lt;title&gt;</span><span class="n">Roll</span> <span class="n">The</span> <span class="n">Dice</span><span class="sr">&lt;/title&gt;&lt;/head&gt;</span></div><div class="line" id="LC24">&nbsp;&nbsp;<span class="sr">&lt;body&gt;</span></div><div class="line" id="LC25">&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">&lt;script&gt;</span></div><div class="line" id="LC26">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">var</span> <span class="n">events</span> <span class="o">=</span> <span class="k">new</span> <span class="n">EventSource</span><span class="p">(</span><span class="s">&#39;&lt;%= url_for &#39;</span><span class="n">events</span><span class="s">&#39; %&gt;&#39;</span><span class="p">);</span></div><div class="line" id="LC27"><br /></div><div class="line" id="LC28">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">//</span> <span class="n">Subscribe</span> <span class="n">to</span> <span class="s">&quot;dice&quot;</span> <span class="n">event</span></div><div class="line" id="LC29">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">events</span><span class="o">.</span><span class="n">addEventListener</span><span class="p">(</span><span class="s">&#39;dice&#39;</span><span class="p">,</span> <span class="n">function</span><span class="p">(</span><span class="n">event</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="LC30">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">document</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">innerHTML</span> <span class="o">+=</span> <span class="n">event</span><span class="o">.</span><span class="n">data</span> <span class="o">+</span> <span class="s">&#39;&lt;br/&gt;&#39;</span><span class="p">;</span></div><div class="line" id="LC31">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">},</span> <span class="n">false</span><span class="p">);</span></div><div class="line" id="LC32">&nbsp;&nbsp;&nbsp;&nbsp;<span class="sr">&lt;/script&gt;</span></div><div class="line" id="LC33">&nbsp;&nbsp;<span class="sr">&lt;/body&gt;</span></div><div class="line" id="LC34"><span class="sr">&lt;/html&gt;</span></div><div class="line" id="LC35"><br /></div></pre></div>
              
            
          </td>
        </tr>
      </table>
    
  </div></p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-hack-of-the-day-html5-eventsource">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-hack-of-the-day-html5-eventsource#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Mon, 08 Aug 2011 09:41:00 -0700</pubDate>
      <title>Mojocast #2 More cloudy goodness</title>
      <link>http://blog.kraih.com/mojocast-2-more-cloudy-goodness</link>
      <guid>http://blog.kraih.com/mojocast-2-more-cloudy-goodness</guid>
      <description>
        <![CDATA[<p>
	<p>Glen "tempire" Hinkle has done it again, and this <a href="http://mojocasts.com/e2">Mojocast</a> looks even better than the last one!</p>
<p><iframe src="http://player.vimeo.com/video/27425243?portrait=0" frameborder="0" height="283" width="500"></iframe></p>
<p>This time you will learn a bit about placeholders, methods and formats in <a href="http://mojolicio.us">Mojolicious</a>, as well as have some fun with Perl and CSS3 selectors on the command line, hooray!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojocast-2-more-cloudy-goodness">Permalink</a> 

	| <a href="http://blog.kraih.com/mojocast-2-more-cloudy-goodness#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Mon, 04 Jul 2011 10:01:00 -0700</pubDate>
      <title>Mojocast #1 Fun with clouds</title>
      <link>http://blog.kraih.com/mojocast-1-fun-with-clouds</link>
      <guid>http://blog.kraih.com/mojocast-1-fun-with-clouds</guid>
      <description>
        <![CDATA[<p>
	<p>I'm happy to tell you that Glen "tempire" Hinkle has just released the first <a href="http://mojocasts.com">Mojocast</a>! In this episode you will learn how to install <a href="http://mojolicio.us">Mojolicious</a> and build your very first web application with it.</p>
<p><iframe src="http://player.vimeo.com/video/25921577?portrait=0" frameborder="0" height="283" width="500"></iframe></p>
<p>Future installments of the series and inclusion of more Perl topics will depend entirely on your feedback, so make sure to leave a comment over on the&nbsp;<a href="http://mojocasts.com">Mojocasts website</a>.</p>
<p>P.S.: I also hear he's not uninterested in a sponsor.</p>
	
</p>

<p><a href="http://blog.kraih.com/mojocast-1-fun-with-clouds">Permalink</a> 

	| <a href="http://blog.kraih.com/mojocast-1-fun-with-clouds#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
    </item>
    <item>
      <pubDate>Mon, 27 Jun 2011 08:40:00 -0700</pubDate>
      <title>Lets just drop the 5 from Perl 5</title>
      <link>http://blog.kraih.com/lets-just-drop-the-5-from-perl-5</link>
      <guid>http://blog.kraih.com/lets-just-drop-the-5-from-perl-5</guid>
      <description>
        <![CDATA[<p>
	<p><div class='p_embed p_image_embed'>
<a href="http://posterous.com/getfile/files.posterous.com/temp-2011-06-27/wFgsIJunbHolquEcwGyfcabBuvIueovkbeDfklEwGHtdGDcpeAgkznlcbmJq/perl16.png.scaled1000.png"><img alt="Perl16" height="160" src="http://posterous.com/getfile/files.posterous.com/temp-2011-06-27/wFgsIJunbHolquEcwGyfcabBuvIueovkbeDfklEwGHtdGDcpeAgkznlcbmJq/perl16.png.scaled500.png" width="500" /></a>
</div>
</p>
<p><a href="http://perl6.org/">Perl 6</a> is a great research project and it has been inspiration for many new Perl 5 features over the past 10 years. But its name has also been the cause for a lot of frustration, since it implies that it will be the successor to Perl 5, while in reality there are currently two communities developing two languages.</p>
<p>In response to this there has <a href="http://blogs.perl.org/users/alberto_simoes/2011/06/perl-perl-5-perl-6-and-names.html">recently</a> <a href="http://www.modernperlbooks.com/mt/2011/06/perl-perl-5-perl-6-and-names.html">been</a> <a href="http://blogs.perl.org/users/mithaldu/2011/06/why-are-people-asking-for-a-perl-name-change-again.html">a lot of</a> <a href="http://jjnapiorkowski.typepad.com/modern-perl/2011/06/perl-5-perl-6-perl-x.html">discussion</a> about renaming one of the two, but i think there is a much simpler solution to solve this quickly and with little consequences for developers. Why not follow <a href="https://lkml.org/lkml/2011/5/29/204">the Linux kernel</a> and drop one part of our three part version numbers?</p>
<p>The next stable release could have the very marketing friendly name&nbsp;<strong>Perl 16.0</strong>, and should the Perl 6 language ever mature into a worthy successor it can pick a higher version number again, or change the numbering scheme.</p>
<p>So lets just drop the 5 and put Perl 5 back in its rightful place.</p>
	
</p>

<p><a href="http://blog.kraih.com/lets-just-drop-the-5-from-perl-5">Permalink</a> 

	| <a href="http://blog.kraih.com/lets-just-drop-the-5-from-perl-5#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="199" width="620" url="http://getfile7.posterous.com/getfile/files.posterous.com/temp-2011-06-27/wFgsIJunbHolquEcwGyfcabBuvIueovkbeDfklEwGHtdGDcpeAgkznlcbmJq/perl16.png">
        <media:thumbnail height="160" width="500" url="http://getfile1.posterous.com/getfile/files.posterous.com/temp-2011-06-27/wFgsIJunbHolquEcwGyfcabBuvIueovkbeDfklEwGHtdGDcpeAgkznlcbmJq/perl16.png.scaled500.png" />
      </media:content>
    </item>
    <item>
      <pubDate>Wed, 01 Jun 2011 23:15:00 -0700</pubDate>
      <title>Mojolicious 1.4: Smiling Face With Sunglasses</title>
      <link>http://blog.kraih.com/mojolicious-14-smiling-face-with-sunglasses</link>
      <guid>http://blog.kraih.com/mojolicious-14-smiling-face-with-sunglasses</guid>
      <description>
        <![CDATA[<p>
	<p><div class='p_embed p_image_embed'>
<img alt="Sunglasses" height="268" src="http://posterous.com/getfile/files.posterous.com/temp-2011-06-02/FvfAJwHuhuaGBwgGsimaAitHqFkCmsGmyIHCmlGEgIcexCziCeDHJvvkiesw/sunglasses.png.scaled500.png" width="480" />
</div>
</p>
<p>It fills me with great joy to announce the release of <a href="http://mojolicio.us">Mojolicious</a> 1.4 (Smiling Face With Sunglasses).</p>
<p>It has been a great 5 months since our first stable release, the community keeps growing rapidly and on <a href="https://github.com/kraih/mojo">GitHub</a> we have now passed Rakudo and are approaching 400 watchers, more than any CPAN module before. Thanks everyone for making it happen!</p>
<p>But lets not get carried away and talk a bit about what amazing new features we have for you this time. :)</p>
<p><strong>HTML manipulation</strong></p>
<p>We've had a great HTML5 parser for some time now, in this release we are going to take it to the next level and turn <a href="http://mojolicio.us/perldoc/Mojo/DOM">Mojo::DOM</a> into a real swiss army knife for HTML and XML manipulation.</p>
<p><div class="data type-perl">
    
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
<span rel="#L17" id="L17">17</span>
<span rel="#L18" id="L18">18</span>
<span rel="#L19" id="L19">19</span>
<span rel="#L20" id="L20">20</span>
<span rel="#L21" id="L21">21</span>
<span rel="#L22" id="L22">22</span>
<span rel="#L23" id="L23">23</span>
<span rel="#L24" id="L24">24</span>
<span rel="#L25" id="L25">25</span>
</pre>
          </td>
          <td width="100%">
            
              
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="k">use</span> <span class="mf">5.14.0</span><span class="p">;</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">Mojo::</span><span class="n">DOM</span><span class="p">;</span></div><div class="line" id="LC3"><br /></div><div class="line" id="LC4"><span class="c1"># Let&#39;s start with something simple</span></div><div class="line" id="LC5"><span class="k">my</span> <span class="nv">$dom</span> <span class="o">=</span> <span class="nn">Mojo::</span><span class="n">DOM</span><span class="o">-&gt;</span><span class="k">new</span><span class="p">(</span><span class="s">&#39;&lt;div id=&quot;a&quot;&gt;A&lt;/div&gt;&#39;</span><span class="p">);</span></div><div class="line" id="LC6"><br /></div><div class="line" id="LC7"><span class="c1"># All child elements now have accessors you can use instead of CSS3 selectors</span></div><div class="line" id="LC8"><span class="n">say</span> <span class="nv">$dom</span><span class="o">-&gt;</span><span class="n">div</span><span class="o">-&gt;</span><span class="n">text</span><span class="p">;</span></div><div class="line" id="LC9"><br /></div><div class="line" id="LC10"><span class="c1"># You also get direct hash access to element attributes</span></div><div class="line" id="LC11"><span class="n">say</span> <span class="nv">$dom</span><span class="o">-&gt;</span><span class="n">div</span><span class="o">-&gt;</span><span class="p">{</span><span class="n">id</span><span class="p">};</span></div><div class="line" id="LC12"><br /></div><div class="line" id="LC13"><span class="c1"># How about prepending another element</span></div><div class="line" id="LC14"><span class="nv">$dom</span><span class="o">-&gt;</span><span class="n">div</span><span class="o">-&gt;</span><span class="n">prepend</span><span class="p">(</span><span class="s">&#39;&lt;div id=&quot;a&quot;&gt;A&lt;/div&gt;&#39;</span><span class="p">);</span></div><div class="line" id="LC15"><span class="n">say</span> <span class="s">&quot;$dom&quot;</span><span class="p">;</span></div><div class="line" id="LC16"><br /></div><div class="line" id="LC17"><span class="c1"># And modify the now-second one to fit in better</span></div><div class="line" id="LC18"><span class="nv">$dom</span><span class="o">-&gt;</span><span class="n">div</span><span class="o">-&gt;</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-&gt;</span><span class="n">replace_content</span><span class="p">(</span><span class="s">&#39;B&#39;</span><span class="p">);</span></div><div class="line" id="LC19"><span class="nv">$dom</span><span class="o">-&gt;</span><span class="n">div</span><span class="o">-&gt;</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-&gt;</span><span class="p">{</span><span class="n">id</span><span class="p">}</span> <span class="o">=</span> <span class="s">&#39;b&#39;</span><span class="p">;</span></div><div class="line" id="LC20"><span class="n">say</span> <span class="s">&quot;$dom&quot;</span><span class="p">;</span></div><div class="line" id="LC21"><br /></div><div class="line" id="LC22"><span class="c1"># Maybe add another nested element to the content of the first one</span></div><div class="line" id="LC23"><span class="nv">$dom</span><span class="o">-&gt;</span><span class="n">div</span><span class="o">-&gt;</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-&gt;</span><span class="n">append_content</span><span class="p">(</span><span class="s">&#39;&lt;p&gt;C&lt;/p&gt;&#39;</span><span class="p">);</span></div><div class="line" id="LC24"><span class="n">say</span> <span class="nv">$dom</span><span class="o">-&gt;</span><span class="n">div</span><span class="o">-&gt;</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-&gt;</span><span class="n">p</span><span class="o">-&gt;</span><span class="n">text</span><span class="p">;</span></div><div class="line" id="LC25"><span class="n">say</span> <span class="s">&quot;$dom&quot;</span><span class="p">;</span></div></pre></div>
              
            
          </td>
        </tr>
      </table>
    
  </div></p>
<p>Working with XML in Perl has never been this much fun before.</p>
<p><strong>Running oneliners against applications</strong></p>
<p>Perl is one of the most expressive languages out there, why not take advantage of that and allow oneliners to be run right against Mojolicious applications.</p>
<p><div class="data type-text">
    
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
<span rel="#L17" id="L17">17</span>
<span rel="#L18" id="L18">18</span>
<span rel="#L19" id="L19">19</span>
<span rel="#L20" id="L20">20</span>
<span rel="#L21" id="L21">21</span>
<span rel="#L22" id="L22">22</span>
<span rel="#L23" id="L23">23</span>
<span rel="#L24" id="L24">24</span>
<span rel="#L25" id="L25">25</span>
<span rel="#L26" id="L26">26</span>
<span rel="#L27" id="L27">27</span>
<span rel="#L28" id="L28">28</span>
<span rel="#L29" id="L29">29</span>
<span rel="#L30" id="L30">30</span>
<span rel="#L31" id="L31">31</span>
<span rel="#L32" id="L32">32</span>
</pre>
          </td>
          <td width="100%">
            
              
                <div class="highlight"><pre /><div class="line" id="LC1">% ./myapp.pl eval -v &#39;join &quot;\n&quot;, sort keys %{app-&gt;renderer-&gt;helpers}&#39;</div><div class="line" id="LC2">app</div><div class="line" id="LC3">base_tag</div><div class="line" id="LC4">check_box</div><div class="line" id="LC5">content</div><div class="line" id="LC6">content_for</div><div class="line" id="LC7">dumper</div><div class="line" id="LC8">extends</div><div class="line" id="LC9">file_field</div><div class="line" id="LC10">flash</div><div class="line" id="LC11">form_for</div><div class="line" id="LC12">hidden_field</div><div class="line" id="LC13">image</div><div class="line" id="LC14">include</div><div class="line" id="LC15">input_tag</div><div class="line" id="LC16">javascript</div><div class="line" id="LC17">layout</div><div class="line" id="LC18">link_to</div><div class="line" id="LC19">memorize</div><div class="line" id="LC20">param</div><div class="line" id="LC21">password_field</div><div class="line" id="LC22">radio_button</div><div class="line" id="LC23">select_field</div><div class="line" id="LC24">session</div><div class="line" id="LC25">stash</div><div class="line" id="LC26">stylesheet</div><div class="line" id="LC27">submit_button</div><div class="line" id="LC28">tag</div><div class="line" id="LC29">text_area</div><div class="line" id="LC30">text_field</div><div class="line" id="LC31">title</div><div class="line" id="LC32">url_for</div></pre></div>
              
            
          </td>
        </tr>
      </table>
    
  </div></p>
<p>The possibilities are infinite. :)</p>
<p><strong>Easier long polling</strong></p>
<p>So far we've mostly used the chunked transfer encoding for dynamic long poll streams, this has the huge advantage of allowing connections to be kept alive. But to support <a href="http://dev.w3.org/html5/eventsource/">Server-Sent Events</a> better we are now also providing raw streams that get terminated with a connection close.</p>
<p><div class="data type-perl">
    
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
<span rel="#L10" id="L10">10</span>
<span rel="#L11" id="L11">11</span>
<span rel="#L12" id="L12">12</span>
<span rel="#L13" id="L13">13</span>
<span rel="#L14" id="L14">14</span>
<span rel="#L15" id="L15">15</span>
<span rel="#L16" id="L16">16</span>
</pre>
          </td>
          <td width="100%">
            
              
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="k">use</span> <span class="nn">Mojolicious::</span><span class="n">Lite</span><span class="p">;</span></div><div class="line" id="LC2"><br /></div><div class="line" id="LC3"><span class="n">get</span> <span class="s">&#39;/&#39;</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC4">&nbsp;&nbsp;<span class="k">my</span> <span class="nv">$self</span> <span class="o">=</span> <span class="nb">shift</span><span class="p">;</span></div><div class="line" id="LC5"><br /></div><div class="line" id="LC6">&nbsp;&nbsp;<span class="c1"># Write two chunks right away</span></div><div class="line" id="LC7">&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="nb">write</span><span class="p">(</span><span class="s">&quot;first\n&quot;</span><span class="p">);</span></div><div class="line" id="LC8">&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="nb">write</span><span class="p">(</span><span class="s">&quot;second\n&quot;</span><span class="p">);</span></div><div class="line" id="LC9"><br /></div><div class="line" id="LC10">&nbsp;&nbsp;<span class="c1"># Wait 3 seconds and write last chunk</span></div><div class="line" id="LC11">&nbsp;&nbsp;<span class="nn">Mojo::</span><span class="n">IOLoop</span><span class="o">-&gt;</span><span class="n">timer</span><span class="p">(</span><span class="mi">3</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC12">&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$self</span><span class="o">-&gt;</span><span class="n">finish</span><span class="p">(</span><span class="s">&quot;third\n&quot;</span><span class="p">);</span></div><div class="line" id="LC13">&nbsp;&nbsp;<span class="p">});</span></div><div class="line" id="LC14"><span class="p">};</span></div><div class="line" id="LC15"><br /></div><div class="line" id="LC16"><span class="n">app</span><span class="o">-&gt;</span><span class="n">start</span><span class="p">;</span></div></pre></div>
              
            
          </td>
        </tr>
      </table>
    
  </div></p>
<p><strong>Embedding applications in scripts</strong></p>
<p>From time to time you might want to reuse parts of Mojolicious applications like configuration files, database connection or helpers for other scripts, now you can just use this little mock server to embed them.</p>
<p><div class="data type-perl">
    
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
<span rel="#L9" id="L9">9</span>
</pre>
          </td>
          <td width="100%">
            
              
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="k">use</span> <span class="mf">5.14.0</span><span class="p">;</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">Mojo::</span><span class="n">Server</span><span class="p">;</span></div><div class="line" id="LC3"><br /></div><div class="line" id="LC4"><span class="c1"># Load application with mock server</span></div><div class="line" id="LC5"><span class="k">my</span> <span class="nv">$server</span> <span class="o">=</span> <span class="nn">Mojo::</span><span class="n">Server</span><span class="o">-&gt;</span><span class="k">new</span><span class="p">;</span></div><div class="line" id="LC6"><span class="k">my</span> <span class="nv">$app</span> <span class="o">=</span> <span class="nv">$server</span><span class="o">-&gt;</span><span class="n">load_app</span><span class="p">(</span><span class="s">&#39;./myapp.pl&#39;</span><span class="p">);</span></div><div class="line" id="LC7"><br /></div><div class="line" id="LC8"><span class="c1"># Access fully initialized application</span></div><div class="line" id="LC9"><span class="n">say</span> <span class="nv">$app</span><span class="o">-&gt;</span><span class="n">static</span><span class="o">-&gt;</span><span class="n">root</span><span class="p">;</span></div></pre></div>
              
            
          </td>
        </tr>
      </table>
    
  </div></p>
<p>And as usual there is a lot more to discover, see <a href="https://github.com/kraih/mojo/blob/v1.4/Changes">Changes</a> on GitHub for the full list of improvements.</p>
<p>Have fun!</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-14-smiling-face-with-sunglasses">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-14-smiling-face-with-sunglasses#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="281" width="501" url="http://getfile1.posterous.com/getfile/files.posterous.com/temp-2011-06-01/zhBpsGBnBBhjddEzIgAbGEikxAsBoBFzkqpHekwsqdioGaJHuyByeEyxcpJr/sunglasses.png">
        <media:thumbnail height="280" width="500" url="http://getfile6.posterous.com/getfile/files.posterous.com/temp-2011-06-01/zhBpsGBnBBhjddEzIgAbGEikxAsBoBFzkqpHekwsqdioGaJHuyByeEyxcpJr/sunglasses.png.scaled500.png" />
      </media:content>
      <media:content type="image/png" height="268" width="478" url="http://getfile8.posterous.com/getfile/files.posterous.com/temp-2011-06-02/prGIjdfpJCpdkdIAxGuseBgnxcjHdgogiADvmzChfgwIBvEFbewrkmvgvJhx/sunglasses.png">
        <media:thumbnail height="268" width="478" url="http://getfile5.posterous.com/getfile/files.posterous.com/temp-2011-06-02/prGIjdfpJCpdkdIAxGuseBgnxcjHdgogiADvmzChfgwIBvEFbewrkmvgvJhx/sunglasses.png.scaled500.png" />
      </media:content>
      <media:content type="image/png" height="268" width="480" url="http://getfile7.posterous.com/getfile/files.posterous.com/temp-2011-06-02/FvfAJwHuhuaGBwgGsimaAitHqFkCmsGmyIHCmlGEgIcexCziCeDHJvvkiesw/sunglasses.png">
        <media:thumbnail height="268" width="480" url="http://getfile5.posterous.com/getfile/files.posterous.com/temp-2011-06-02/FvfAJwHuhuaGBwgGsimaAitHqFkCmsGmyIHCmlGEgIcexCziCeDHJvvkiesw/sunglasses.png.scaled500.png" />
      </media:content>
    </item>
    <item>
      <pubDate>Wed, 27 Apr 2011 22:54:00 -0700</pubDate>
      <title>Mojolicious in the cloud: Hello DotCloud!</title>
      <link>http://blog.kraih.com/mojolicious-in-the-cloud-hello-dotcloud</link>
      <guid>http://blog.kraih.com/mojolicious-in-the-cloud-hello-dotcloud</guid>
      <description>
        <![CDATA[<p>
	<p>Today is a great day for Perl web development, with <a href="http://blog.dotcloud.com/dotcloud-introduces-camel-as-a-service-with-i">DotCloud</a>&nbsp;finally adding Perl support we now have two cloud hosting providers to choose from. Even though&nbsp;<a href="http://www.phenona.com/">Phenona</a> started their beta about two weeks ago, it seems very limited and there is not much known about it yet, maybe i'll get to write about them next time.</p>
<p>My first impressions of DotCloud have been quite pleasant so far, it basically allows you to completely ignore infrastructure questions and to concentrate on what's really important, your application. All you have to do to get started is claim your API key on the website and install the Python command line client via "easy_install".</p>
<p><div class="data type-text">
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
</pre>
          </td>
          <td width="100%">
                <div class="highlight"><pre /><div class="line" id="LC1">% sudo easy_install dotcloud</div><div class="line" id="LC2">...</div></pre></div>
          </td>
        </tr>
      </table>
  </div></p>
<p>Every DotCloud Perl application requires two essential files, a "Makefile.PL" containing a list of CPAN dependencies and a "app.psgi" file used to start the application with a PSGI compliant web server. (Nginx + uWSGI)</p>
<p><div class="data type-text">
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
</pre>
          </td>
          <td width="100%">
                <div class="highlight"><pre /><div class="line" id="LC1">% mkdir hellomojo</div><div class="line" id="LC2">% cd hellomojo</div><div class="line" id="LC3">% touch myapp.pl</div><div class="line" id="LC4">% touch Makefile.PL</div><div class="line" id="LC5">% touch app.psgi</div></pre></div>
          </td>
        </tr>
      </table>
  </div></p>
<p>For our little Hello World example we will use a separate "myapp.pl" file, this is not necessary but will simplify the use of <a href="http://mojolicio.us">Mojolicious</a> debugging tools later on.</p>
<p><div class="data type-perl">
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
</pre>
          </td>
          <td width="100%">
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="c1">#!/usr/bin/env perl</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">Mojolicious::</span><span class="n">Lite</span><span class="p">;</span></div><div class="line" id="LC3"><br /></div><div class="line" id="LC4"><span class="n">get</span> <span class="s">&#39;/&#39;</span> <span class="o">=&gt;</span> <span class="k">sub </span><span class="p">{</span></div><div class="line" id="LC5">&nbsp;&nbsp;<span class="nb">shift</span><span class="o">-&gt;</span><span class="n">render_text</span><span class="p">(</span><span class="s">&#39;Hello Mojo!&#39;</span><span class="p">);</span></div><div class="line" id="LC6"><span class="p">};</span></div><div class="line" id="LC7"><br /></div><div class="line" id="LC8"><span class="n">app</span><span class="o">-&gt;</span><span class="n">start</span><span class="p">;</span></div></pre></div>
          </td>
        </tr>
      </table>
  </div></p>
<p>The separate PSGI file also makes switching modes very easy.</p>
<p><div class="data type-perl">
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
</pre>
          </td>
          <td width="100%">
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="nv">$ENV</span><span class="p">{</span><span class="n">MOJO_MODE</span><span class="p">}</span> <span class="o">=</span> <span class="s">&#39;production&#39;</span><span class="p">;</span></div><div class="line" id="LC2"><span class="nb">require</span> <span class="s">&#39;myapp.pl&#39;</span><span class="p">;</span></div></pre></div>
          </td>
        </tr>
      </table>
  </div></p>
<p>Our only dependency for this experiment will be Mojolicious, but DotCloud can automatically install any CPAN module you specify.</p>
<p><div class="data type-perl">
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
</pre>
          </td>
          <td width="100%">
                <div class="highlight"><pre /><div class="line" id="LC1"><span class="c1">#!/usr/bin/env perl</span></div><div class="line" id="LC2"><span class="k">use</span> <span class="nn">ExtUtils::</span><span class="n">MakeMaker</span><span class="p">;</span></div><div class="line" id="LC3"><br /></div><div class="line" id="LC4"><span class="n">WriteMakefile</span><span class="p">(</span></div><div class="line" id="LC5">&nbsp;&nbsp;<span class="n">PREREQ_PM</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="s">&#39;Mojolicious&#39;</span> <span class="o">=&gt;</span> <span class="s">&#39;1.21&#39;</span><span class="p">}</span></div><div class="line" id="LC6"><span class="p">);</span></div></pre></div>
          </td>
        </tr>
      </table>
  </div></p>
<p>It only takes a few simple commands to deploy our application and make it publicly available at <a href="http://www.hellomojo.dotcloud.com">http://www.hellomojo.dotcloud.com</a>.</p>
<p><div class="data type-text">
      <table class="lines" cellspacing="0" cellpadding="0">
        <tr>
          <td>
            <pre class="line_numbers"><span rel="#L1" id="L1">1</span>
<span rel="#L2" id="L2">2</span>
<span rel="#L3" id="L3">3</span>
<span rel="#L4" id="L4">4</span>
<span rel="#L5" id="L5">5</span>
<span rel="#L6" id="L6">6</span>
<span rel="#L7" id="L7">7</span>
<span rel="#L8" id="L8">8</span>
</pre>
          </td>
          <td width="100%">
                <div class="highlight"><pre /><div class="line" id="LC1">% dotcloud create hellomojo</div><div class="line" id="LC2">...</div><div class="line" id="LC3">% dotcloud deploy --type perl hellomojo.www</div><div class="line" id="LC4">...</div><div class="line" id="LC5">% dotcloud push hellomojo.www .</div><div class="line" id="LC6">...</div><div class="line" id="LC7">% dotcloud run hellomojo.www</div><div class="line" id="LC8">...</div></pre></div>
          </td>
        </tr>
      </table>
  </div></p>
<p>I have not yet tried the huge selection of <a href="http://docs.dotcloud.com/components/">databases available</a>, but am very much looking forward to it.</p>
<p><div class='p_embed p_image_embed'>
<a href="http://posterous.com/getfile/files.posterous.com/temp-2011-04-28/vDresqgBupbosxzDygfxGDjflonGpmzgnzkqEwkglvwdpmwBIoCdhGGzggkG/hellomojo.png.scaled1000.png"><img alt="Hellomojo" height="250" src="http://posterous.com/getfile/files.posterous.com/temp-2011-04-28/vDresqgBupbosxzDygfxGDjflonGpmzgnzkqEwkglvwdpmwBIoCdhGGzggkG/hellomojo.png.scaled500.png" width="500" /></a>
</div>
</p>
<p>Have fun! :)</p>
	
</p>

<p><a href="http://blog.kraih.com/mojolicious-in-the-cloud-hello-dotcloud">Permalink</a> 

	| <a href="http://blog.kraih.com/mojolicious-in-the-cloud-hello-dotcloud#comment">Leave a comment&nbsp;&nbsp;&raquo;</a>

</p>]]>
      </description>
      <posterous:author>
        <posterous:userImage>http://files.posterous.com/user_profile_pics/634320/bfa97d786f12ee3381f97bc909b88e11.jpeg</posterous:userImage>
        <posterous:profileUrl>http://posterous.com/users/5BceKDO6LdLz</posterous:profileUrl>
        <posterous:firstName>Sebastian</posterous:firstName>
        <posterous:lastName>Riedel</posterous:lastName>
        <posterous:nickName>kraih</posterous:nickName>
        <posterous:displayName>Sebastian Riedel</posterous:displayName>
      </posterous:author>
      <media:content type="image/png" height="478" width="955" url="http://getfile2.posterous.com/getfile/files.posterous.com/temp-2011-04-28/vDresqgBupbosxzDygfxGDjflonGpmzgnzkqEwkglvwdpmwBIoCdhGGzggkG/hellomojo.png">
        <media:thumbnail height="250" width="500" url="http://getfile7.posterous.com/getfile/files.posterous.com/temp-2011-04-28/vDresqgBupbosxzDygfxGDjflonGpmzgnzkqEwkglvwdpmwBIoCdhGGzggkG/hellomojo.png.scaled500.png" />
      </media:content>
    </item>
  </channel>
</rss>

