<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>hoelzro</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/hoelzro/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/hoelzro/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/hoelzro//850</id>
    <updated>2012-04-16T13:02:45Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Still alive, Inline::Lua?</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/hoelzro/2012/04/still-alive-inlinelua.html" />
    <id>tag:blogs.perl.org,2012:/users/hoelzro//850.2997</id>

    <published>2012-04-16T14:00:00Z</published>
    <updated>2012-04-16T13:02:45Z</updated>

    <summary>I was reading about the Inline module the other day, so naturally I looked to see if there was a binding for one of my other favorite languages, Lua. Sure enough, Inline::Lua exists; however, it has not seen a new...</summary>
    <author>
        <name>Rob Hoelz</name>
        <uri>http://hoelz.ro</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/hoelzro/">
        <![CDATA[<p>I was reading about the <a href='https://metacpan.org/module/Inline'>Inline</a> module the other day, so naturally I looked to see if there was a binding for one of my <i>other</i> favorite languages, Lua.  Sure enough, <a href='https://metacpan.org/module/Inline::Lua'>Inline::Lua</a> exists; however, it has not seen a new release in nearly five years, and it doesn't even build on perls newer than 5.10.  I like this idea enough that I'd like to put some time into it and cut a new release; however, I haven't been able to reach the author.  So, in accordance with the guidelines I read in the <a href='http://www.cpan.org/misc/cpan-faq.html#How_adopt_module'>CPAN FAQ</a>, I'm making a post asking if the original author, Tassilo von Parseval, is still in the Perl community and interested in updating this module.</p>

<p>-Rob</p>]]>
        
    </content>
</entry>

<entry>
    <title>Perl Podcasts</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/hoelzro/2012/02/perl-podcasts.html" />
    <id>tag:blogs.perl.org,2012:/users/hoelzro//850.2806</id>

    <published>2012-02-13T15:13:59Z</published>
    <updated>2012-02-13T15:15:19Z</updated>

    <summary>I had to make a last-minute drive to Chicago last Friday, which is about a two-and-a-half hour trip from Madison. So naturally, to pass the time, I loaded up my phone with podcasts. When I was about halfway home, it...</summary>
    <author>
        <name>Rob Hoelz</name>
        <uri>http://hoelz.ro</uri>
    </author>
    
    <category term="podcast" label="podcast" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/hoelzro/">
        <![CDATA[<p>I had to make a last-minute drive to Chicago last Friday, which is about a two-and-a-half hour trip from Madison. So naturally, to pass the time, I loaded up my phone with podcasts. When I was about halfway home, it hit me: I didn't have any Perl podcasts on my phone! Unfortunately, I don't know of Perl podcasts; I've seen <a href="http://perlcast.com/">Perlcast</a>, but it looks like it hasn't been updated in a year and a half. So, this is a call to the Perl community: are there any Perl podcasts out there?</p>]]>
        
    </content>
</entry>

<entry>
    <title>Asynchronous MySQL Queries in Perl Using DBD::mysql and AnyEvent</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/hoelzro/2011/10/asynchronous-mysql-queries-in-perl-using-dbdmysql-and-anyevent.html" />
    <id>tag:blogs.perl.org,2011:/users/hoelzro//850.2313</id>

    <published>2011-10-19T16:40:46Z</published>
    <updated>2011-10-19T16:46:30Z</updated>

    <summary>A lot of people use MySQL, and these days, asynchronous-style programming has really taken off. If you&apos;re involved in both of these camps, you may be wondering how to send a query to MySQL and have it inform your event...</summary>
    <author>
        <name>Rob Hoelz</name>
        <uri>http://hoelz.ro</uri>
    </author>
    
    <category term="anyevent" label="anyevent" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mysql" label="mysql" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/hoelzro/">
        <![CDATA[<p>A lot of people use MySQL, and these days, asynchronous-style programming has really taken off.  If you're involved in both of these camps, you may be wondering<br />
how to send a query to MySQL and have it inform your event loop when it's ready with the results of that query.  A common solution is to use a thread or child process<br />
for each connection, and exchange data using IPC.  However, if you're using Perl and <a href="https://metacpan.org/release/DBD-mysql">DBD-mysql</a> 4.019 or better, you have an alternative: the new asynchronous interface.</p>

<p>Using the new <code>async</code> flag that you can provide to the <code>prepare</code> method, along with the new <code>mysql_fd</code> method, it's fairly easy to have MySQL play nice with <a href="https://metacpan.org/release/AnyEvent">AnyEvent</a>.<br />
Here's a simple example:</p>

<pre>
#!/usr/bin/env perl

<p>use strict;<br />
use warnings;<br />
use feature 'say';</p>

<p>use AnyEvent;<br />
use DBI;</p>

<p>my $dbh = DBI->connect('dbi:mysql:', undef, undef, {<br />
    PrintError => 0,<br />
    RaiseError => 1,<br />
});</p>

<p>my $cond = AnyEvent->condvar;</p>

<p>my $sth = $dbh->prepare('SELECT SLEEP(10), 3', { async => 1 });<br />
$sth->execute;</p>

<p>my $timer = AnyEvent->timer(<br />
    interval => 1,<br />
    cb       => sub {<br />
        say 'timer fired!';<br />
    },<br />
);</p>

<p>my $mysql_watcher = AnyEvent->io(<br />
    fh   => $dbh->mysql_fd,<br />
    poll => 'r',<br />
    cb   => sub {<br />
        say 'got data from MySQL';<br />
        say join(' ', $sth->fetchrow_array);<br />
        $cond->send;<br />
    },<br />
);</p>

<p>$cond->recv;</p>

<p>undef $sth;<br />
$dbh->disconnect;<br />
</pre></p>

<p>This script will print "timer fired!" about once a seconds for ten seconds, then "got data from MySQL", and finally "0 3", which is the data from our SELECT statement.  Obviously, this example is pretty trivial, but you could easily do this with multiple MySQL connections.</p>

<p>(cross-posted from <a href="http://hoelz.ro/blog/asynchronous-mysql-queries-in-perl-using-dbdmysql-and-anyevent">my blog</a>)</p>]]>
        
    </content>
</entry>

<entry>
    <title>Edit-Plackup-Test-Rinse-Repeat</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/hoelzro/2011/10/edit-plackup-test-rinse-repeat.html" />
    <id>tag:blogs.perl.org,2011:/users/hoelzro//850.2303</id>

    <published>2011-10-17T13:49:54Z</published>
    <updated>2011-10-17T14:05:55Z</updated>

    <summary>At INOC, my place of work, I work on a lot of web applications with the backend written in Perl using Catalyst, and the frontend written in Javascript using ExtJS. With a UI written completely in Javascript, I often encounter...</summary>
    <author>
        <name>Rob Hoelz</name>
        <uri>http://hoelz.ro</uri>
    </author>
    
    <category term="catalystplackpsgi" label="catalyst plack psgi" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/hoelzro/">
        <![CDATA[<p>At INOC, my place of work, I work on a lot of web applications with the backend written in Perl using <a href="http://www.catalystframework.org/">Catalyst</a>, and the frontend written in Javascript using <a href="http://www.sencha.com/">ExtJS</a>. With a UI written completely in Javascript, I often encounter bugs of the following form:</p>

<ol>
<li>Fire up Catalyst.</li>
<li>Login.</li>
<li>Click through half a dozen controls in the UI.</li>
<li>Enter some data.</li>
<li>Click “submit”.</li>
<li>Watch the web application give you an angry error.</li>
</ol>

<p>As you can imagine, the time for a single iteration of this cycle is fairly long, and the process is quite tedious. Obviously, if the error lies within the Javascript side, there's not much I can do about it, short of writing a Greasemonkey script to do some of the automation for me. However, half of the time, the server is returning some strange output given a certain set of inputs for a particular RPC call. Wouldn't it be nice if you could go through the application and have it record the requests you make to be submitted over and over again at a later time?</p>

<p>That's why I wrote <a href="https://metacpan.org/release/Plack-Middleware-Recorder">Plack-Middleware-Recorder.</a></p>

<p>Plack-Middleware-Recorder is a distribution that comes with several modules:</p>

<dl>
<dt>Plack::Middleware::Recorder</dt>
<dd>A PSGI middleware that knows how to serialize requests to a stream.</dd>

<p><dt>Plack::Middleware::Debug::Recorder</dt><br />
<dd>A debugging panel that allows you to manipulate the recorder middleware from a browser.</dd></p>

<p><dt>Plack::VCR</dt><br />
<dd>A utility module that allows you to read a recorded request stream.</dd><br />
</dl></p>

<p>These modules allow you to build PSGI applications and scripts that record and replay requests to a web application. However, Plack-Middleware-Recorder also contains two scripts, plack-record and plack-replay, that do exactly what they sound like. So my workflow for handling a server-side bug goes from this:</p>

<ol>
<li>Steps 1 - 6 above</li>
<li>Add some debugging log output</li>
<li>Repeat, and observe the new output</li>
</ol>

<p>to this:</p>

<ol>
<li>plack-record > requests.out</li>
<li>Steps 1 - 6</li>
<li>Add some debugging log output</li>
<li>plack-replay requests.out app.psgi</li>
<li>GOTO 3</li>
</ol>

<p>Plack-Middleware-Recorder is still very young; I plan on adding better session support, dumping request streams to test files, and other features in the future. In the week since I've written it, I've already gotten a lot of mileage out of it; I hope other people find it just as useful!</p>

<p>-Rob</p>

<p>(cross-posted from <a href="http://hoelz.ro/blog/edit-plackup-test-rinse-repeat">my blog</a>)</p>]]>
        
    </content>
</entry>

</feed>
