<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Leon Timmermans</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/leon_timmermans/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/leon_timmermans//150</id>
    <updated>2013-05-15T07:49:33Z</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>Why you don&apos;t need File::Slurp&#x2026;</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2013/05/why-you-dont-need-fileslurp.html" />
    <id>tag:blogs.perl.org,2013:/users/leon_timmermans//150.4664</id>

    <published>2013-05-10T14:27:34Z</published>
    <updated>2013-05-15T07:49:33Z</updated>

    <summary><![CDATA[#! /usr/bin/env perl use strict; use warnings; use Benchmark 'cmpthese'; use File::Slurp 'read_file'; my $filename = shift or die "No argument given"; my $count = shift || 10; cmpthese($count, { 'Unix' =&gt; sub { open my $fh, '&lt;:unix', $filename or...]]></summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="perlperliobenchmark" label="perl PerlIO benchmark" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<pre><code>#! /usr/bin/env perl

use strict;
use warnings;
use Benchmark 'cmpthese';
use File::Slurp 'read_file';

my $filename = shift or die "No argument given";
my $count = shift || 10;

cmpthese($count, {
    'Unix'  =&gt; sub { open my $fh, '&lt;:unix', $filename or die "Couldn't open $filename: $!"; read $fh, my $buffer, -s $fh or die "Couldn't read $filename: $!" },
    'Slurp' =&gt; sub { read_file($filename, buffer_ref =&gt; \my $buffer, binmode =&gt; ':raw') },
});
</code></pre>

<p>For large files, it's just as fast as File::Slurp is:</p>

<pre><code>        Rate Slurp  Unix
Slurp 2.28/s    --   -0%
Unix  2.29/s    0%    --
</code></pre>

<p>For small files, it's actually significantly faster:</p>

<pre><code>          Rate Slurp  Unix
Slurp  51020/s    --  -66%
Unix  151515/s  197%    --
</code></pre>

<p>So why use File::Slurp, when a two-liner will actually perform better?</p>
]]>
        

    </content>
</entry>

<entry>
    <title>2 weeks of perl</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2012/08/2-weeks-of-perl.html" />
    <id>tag:blogs.perl.org,2012:/users/leon_timmermans//150.3752</id>

    <published>2012-08-27T22:08:13Z</published>
    <updated>2012-08-27T22:08:51Z</updated>

    <summary>It all started with the Cluj.pm summer meeting on the 9th of August. I happened to be around there, so popped in. Cluj.pm is a refreshingly young perl monger group (I might even have been older than the average age...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="perlprsp6p5clujmdkyapc" label="perl prs p6p5 cluj mdk yapc" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>It all started with the <a href="http://cluj.pm/events/2012/07/clujpm-summer-meeting-9-august-2012.html">Cluj.pm summer meeting</a> on the 9th of August. I happened to be around there, so popped in. Cluj.pm is a refreshingly young perl monger group (I might even have been older than the average age there, that's a first for me). At first I didn't know anyone, other than the guest speaker Mark Keating, but after my presentation I had lots of people approaching me and I had a brilliant evening.</p>

<p>A short week later I flew to Germany, for the <a href="http://blogs.perl.org/users/liz/2012/08/as-some-of-you-may.html">Perl Reunification Summit</a> in Perl. Like Schwern I arrived a day earlier than most, so I had a calm start of the meetup. It was mostly a gathering of familiar to me faces, though a significant number I hadn't really spoken to before, specially the Perl 6 guys, -Ofun attracts awesome people. I spent most of the PRS talking to people, and doing a little coding (both related and unrelated). It was a very enlightening meetup.</p>

<p>Lastly, there was <a href="http://act.yapc.eu/ye2012/">YAPC::EU</a>. Despite the sometimes unbearable heat, it was awesome. At some points it seemed a bit less organized than my previous YAPCs, but that may also be me noticing more of what's going on. I spent most of my time in the hallway track, which extended into the pub track, and I spent enough time discussing (and occasionally ranting) that it's a miracle that I still have voice left. In between I found enough time to attend some talks, interestingly I attended most of them on the day I gave one myself. After doing threads last year I could only top it with signals this year. I'll have a challenge to come up with a crazier, I think I'll have to look in a vastly different direction (I have ideas already). After a full week of conferencing, I was relieved to be going home though.</p>

<p>So in all I met Mark Keating in 3 different places in 2 weeks time, I'd almost accuse him of stalking me!</p>
]]>
        

    </content>
</entry>

<entry>
    <title>What you should know about signal based timeouts</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2012/01/what-you-should-know-about-signal-based-timeouts.html" />
    <id>tag:blogs.perl.org,2012:/users/leon_timmermans//150.2632</id>

    <published>2012-01-02T14:15:41Z</published>
    <updated>2012-01-02T14:22:17Z</updated>

    <summary>The problem I think we&apos;ve all seen code like this example from perlipc: my $ALARM_EXCEPTION = &quot;alarm clock restart&quot;; eval { local $SIG{ALRM} = sub { die $ALARM_EXCEPTION }; alarm 10; flock(FH, 2) || die &quot;cannot flock: $!&quot;; alarm 0;...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl5" label="perl5" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="segfault" label="segfault" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="signals" label="signals" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<h2>The problem</h2>

<p>I think we've all seen code like this example from <a href="http://perldoc.perl.org/perlipc.html">perlipc</a>:</p>

<pre><code>my $ALARM_EXCEPTION = "alarm clock restart";
eval {
    local $SIG{ALRM} = sub { die $ALARM_EXCEPTION };
    alarm 10;
    flock(FH, 2)  || die "cannot flock: $!";
    alarm 0;
};
alarm 0;
if ($@ &amp;&amp; $@ !~ quotemeta($ALARM_EXCEPTION)) { die }
</code></pre>

<p>Here, signals are used to put a time limit on some action. However sometimes this doesn't work as wanted. In particular, some C libraries used in XS modules don't honor the <a href="http://perldoc.perl.org/perlipc.html#Deferred-Signals-(Safe-Signals%29">deferred signaling</a> resulting in it being ignored until the C function has finished, which is unlikely to be what you want.</p>

<p>Therefore, people resort to unsafe signals</p>

<pre><code>use Sys::SigAction qw( set_sig_handler );
my $ALARM_EXCEPTION = "alarm clock restart";
my $h;
eval {
    $h = set_sig_handler('ALRM', sub { die $ALARM_EXCEPTION }, { });
    alarm 10;
    flock $fh, 2 or die "cannot flock: $!";
    alarm 0;
};
alarm 0;
$SIG{ALRM} = $h;
if ($@ &amp;&amp; $@ !~ quotemeta($ALARM_EXCEPTION)) { die }
</code></pre>

<p>This works as expected, mostly, but there is a serious problem with doing this; serious enough to have an explicit and specific <a href="https://www.securecoding.cert.org/confluence/display/seccode/SIG32-C.+Do+not+call+longjmp%28%29+from+inside+a+signal+handler">high severity advise</a> against it in CERT's secure coding guide (and it also happens to violate most other secure coding advises regarding signaling).</p>

<p>Signal handlers (or at least the real, <em>unsafe</em> ones) have a highly restricted set of operations they can safely to perform, doing anything that's not allowed means risking segfaults and data loss. This is why we needed "safe" signaling in the first place. By longjumping out of the unsafe/real signal hander (which is what <code>die</code> does), those restrictions are continued into the rest of the program. That means that <strong>anything</strong> from that point on can (and at some point probably will) cause segfaults and other bugs.</p>

<p>Ouch!</p>

<h2>The way out?</h2>

<p>That's the harsh part, sometimes there isn't any easy way out. If a piece of C code doesn't have it's own timeout support, there may be no alternative. The real solution is to write blocking/computationally intensive software in such a way that it can handle this more graciously, for example by using an event loop, but often one has to deal with the tools one has.</p>

<p>So, I'm not saying everyone is wrong for using unsafe signal timeouts, but you should be aware of and accept the risks that come with it.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Looking for Ilja Tabachnik</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2011/11/looking-for-ilja-tabachnik.html" />
    <id>tag:blogs.perl.org,2011:/users/leon_timmermans//150.2502</id>

    <published>2011-11-28T20:59:04Z</published>
    <updated>2011-11-28T21:03:36Z</updated>

    <summary>I&apos;m looking for Ilja Tabachnik. I want to fix his only module on CPAN (POSIX::RT::MQ), but his public email address no longer exists. If I can not reach him I will ask the PAUSE admins for permission to take over...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="perlperl5" label="perl perl5" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>I'm looking for Ilja Tabachnik.</p>

<p>I want to fix his only module on CPAN (<a href="https://metacpan.org/module/POSIX::RT::MQ">POSIX::RT::MQ</a>), but his public email address no longer exists. If I can not reach him I will ask the PAUSE admins for permission to take over this module.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Why do you want new major features in core?</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2011/10/why-do-you-want-new-major-features-in-core.html" />
    <id>tag:blogs.perl.org,2011:/users/leon_timmermans//150.2304</id>

    <published>2011-10-17T18:50:51Z</published>
    <updated>2011-10-17T19:05:18Z</updated>

    <summary>I&apos;ve heard some people complain about 5.12 and 5.14 not adding many new major features. Compared to 5.10 that&apos;s certainly true, but is that a bad thing? Let&apos;s be honest, many (most) prominent new features of 5.10 are failures: Smartmatching?...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="perlcorefeatures" label="perl core features" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>I've heard some people complain about 5.12 and 5.14 not adding many new major features. Compared to 5.10 that's certainly true, but is that a bad thing?</p>

<p>Let's be honest, many (most) prominent new features of 5.10 are failures:</p>

<ul>
<li>Smartmatching? I think everyone agrees it is broken.</li>
<li><code>given</code>/<code>when</code> is even worse as it's almost impossible to predict if it will use smartmatching or not.</li>
<li>Lexical <code>$_</code>? Mostly a new source of bugs, and the <code>_</code> prototype is merely a hack to work around lexical <code>$_</code> issues.</li>
<li>MAD? It never reached any usable form.</li>
<li>etcetera&#133; </li>
</ul>

<p>A lot of others are not flawed, but are so uncommon that I haven't seen them being used in any code. <code>UNITCHECK</code>, stacked filetests, <code>no VERSION</code>, the list goes on&#133;</p>

<p>In the end, there are only two new features of 5.10 that I end up using all the time: <code>say</code> and defined-or. These two features have one thing in common: they are small and simple features that make daily programming easier. Likewise my favorite new feature in 5.14 is the <code>/r</code> modifier on <code>s///</code> and <code>tr///</code>. I don't know how we managed to do without that, it makes so much code so much simpler. I want more of those features.</p>

<p>On the other hand, there's another group of new features that is just as important, but not nearly as visible. It's the under-the-hood or right on top of it. Few people know how the <code>$^H</code> and <code>%^H</code> changed in 5.10, but if you're writing pragmas you'll appreciate them. These are expert features that few people will use, but those few use them to write the modules on CPAN that everyone else uses. These features are just as important, if not more so: they lay the foundation for progress by enabling (competitive) evolution on CPAN.</p>

<p>It is important for this progress to happen not in core but on CPAN. Because if modules screw up they can be discarded and we can try to come up with something better (which you can't with the core). Because modules easily allow an allow an ecosystem of TIMTOWTDI. But most of all because the Perl community is awesome at creating modules.</p>

<p>Few people outside the echo chamber follow know Steven's work on a perl <a href="https://github.com/stevan/p5-mop">MOP</a>, but that may become the most important development in Perl OO since the arrival of his Moose (also written by him). Likewise few people are using Zefram's awesome keywords API, but that is what will allow us to do Devel::Declare kind of stuff in a sane way, and may one day open up doors to macros. Few people know of the Unicode improvements by Karl Williamson and others that make Perl hands down the <a href="http://98.245.80.27/tcpc/OSCON2011/gbu/gbu.html">best language for Unicode processing</a>. </p>

<p>We can't always know end-user's requirement in advance. That's why <strong>big core features should be open ended</strong>. Maybe that doesn't make for spectacular perldeltas, but it does lead to a better end result.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Find the exploit&#133;</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2011/09/find-the-exploit.html" />
    <id>tag:blogs.perl.org,2011:/users/leon_timmermans//150.2188</id>

    <published>2011-09-13T18:36:16Z</published>
    <updated>2011-09-13T19:47:11Z</updated>

    <summary>Two of these can permanently drop the UID too 1000. The other two however results in a state where a previous privileged state can be restored. Can you spot which ones are right and which ones not? And most importantly:...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="perlsetuidexploit" label="perl setuid exploit" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>Two of these can permanently drop the UID too 1000. The other two however results in a state where a previous privileged state can be restored. Can you spot which ones are right and which ones not? And most importantly: why?</p>

<pre><code>$&lt; = 1000;
$&gt; = 1000;

$&gt; = 1000;
$&lt; = 1000;

$&lt; = $&gt; = 1000

$&gt; = $&lt; = 1000
</code></pre>
]]>
        

    </content>
</entry>

<entry>
    <title>Smarter matching</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2011/06/smarter-matching.html" />
    <id>tag:blogs.perl.org,2011:/users/leon_timmermans//150.1852</id>

    <published>2011-06-15T15:07:12Z</published>
    <updated>2011-06-15T15:08:51Z</updated>

    <summary>Smartmatching is complicated. Anyone suggesting otherwise simply hasn&apos;t used it much. Something that appears to be as simple as when @array can have 5 rather different meanings depending on the value of $_, the two most important being «each element...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="perlsmartmatch" label="perl smartmatch" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>Smartmatching is complicated. Anyone suggesting otherwise simply hasn't used it much. Something that appears to be as simple as <code>when @array</code> can have 5 rather different meanings depending on the value of <code>$_</code>, the two most important being «each element in <code>@$_</code> matches the corresponding element in <code>@array</code>» and «<code>$_</code> matches any of <code>@array</code>». <strong>This is madness</strong>. I believe there's a lot of value in being able to explicitly differentiate <code>when list(@array)</code> and <code>when any(@array)</code>.</p>

<p>Hence <a href="http://search.cpan.org/perldoc?Smart::Match">Smart::Match</a>. It's a module that does exactly that and more. Not only does it allow you to disambiguate smartmatches, it also allows you to use powerful new matches by using higher order matchers. For example it doesn't just allow you to match against <code>string_length(4)</code>, but also <code>string_length(even)</code> or <code>string_length(range(13,42))</code>. This makes smartmatching a lot easier and saner than doing it raw.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Le Roi est mort, vive le Roi!</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2011/03/le-roi-est-mort-vive-le-roi.html" />
    <id>tag:blogs.perl.org,2011:/users/leon_timmermans//150.1535</id>

    <published>2011-03-08T22:34:13Z</published>
    <updated>2011-03-10T01:19:30Z</updated>

    <summary>Like I said in my previous blogpost, Module::Build has some serious technical problems. This causes another problem that I didn&apos;t discuss previously, but that&apos;s maybe the worst thing: no one loves it. MakeMaker also has some crazy internals, but it...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="buildpl" label="Build.PL" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="future" label="future" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="modulebuild" label="module::build" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl5" label="perl5" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>Like I said in my <a href="http://blogs.perl.org/users/leon_timmermans/2011/02/what-went-wrong-with-modulebuild.html">previous blogpost,</a> Module::Build has some serious technical problems. This causes another problem that I didn't discuss previously, but that's maybe the worst thing: no one loves it. MakeMaker also has some crazy internals, but it commands the love of a dedicated group of hackers. It's because of that more than anything else that I'm pretty sure its flame won't extinguish any time soon. Module::Build does not have such a luxury; no one seems motivated anymore to maintain it (if you are, do please take up contact with its current maintainer, David Golden). I fear Module::Build is screwed.</p>

<h1>The way out</h1>

<p>The core idea of Module::Build, that of a module builder written in Perl itself is a really good one in my opinion. Module::Build paved the way to do that, but this idea is not tied to Module::Build. End users and CPAN clients don't really care what's behind that Build.PL command, as long as it behaves according to the interface that was defined by Module::Build. That interface is currently in the process of being <a href="https://github.com/dagolden/cpan-api-buildpl/blob/master/lib/CPAN/API/BuildPL.pm">specified</a>. The first experiment is <a href="https://github.com/Leont/module-build-tiny">Module::Build::Tiny</a>, a proof-of-concept that does the simplest thing possible for pure Perl modules.</p>

<h1>The module builder I dream of</h1>

<p>Since 5.10.1 the toolchain supports <em>configure_requires</em>. This means that the end user no longer has to have the install tool installed before installing the module, the toolchain will take care of this. This means that now the module building is just another program for most purposes.</p>

<ol>
<li><p>Dependencies <br />
Module::Build does not have a proper dependency graph. This decision is in many ways at the core of it's design. Writing a proper dependency graph has a serious upfront costs and makes a lot of simple things more complicated, however it also makes a lot of complicated things more simple. It also makes it much more simple to debug various issues, if only because you can serialize a graph.</p></li>
<li><p>Abstraction <br />
ExtUtils::MakeMaker uses make, which does have a dependency graph. However there is no convenient way to manipulate it. It boils down to either appending some make commands to the string containing the Makefile or even manipulating it using regexps. This makes it way too difficult to customize the build process. CPAN authors should be able to specify <em>what</em> they want done, not <em>how</em>.</p></li>
<li><p>Extendability <br />
Like I said in my previous post, Dist::Zilla showed how easy it can be to extend a program. My imaginary module builder should be just as extendable. However that doesn't mean it shouldn't have the right defaults. The default configuration that handles modules that don't do anything special (which is probably 95% of them right now) should be as simple as:</p>

<pre><code>[@Basic]
</code></pre>

<p>The Build.PL wouldn't need to contain any state. It would probably be as simple as:</p>

<pre><code>use Dist::Build;
Build_PL(@ARGV);
</code></pre>

<p>More simply isn't necessary. All data is either in the the meta file, configuration file or is generated by plugins.</p>

<p>The extensions could be anything, though I would obviously expect most to affect the build stage like editing or serializing the graph (perhaps even to a makefile), but it could also be in configuration (e.g. meta information), testing and installing.</p></li>
</ol>
]]>
        

    </content>
</entry>

<entry>
    <title>What went wrong with Module::Build?</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2011/02/what-went-wrong-with-modulebuild.html" />
    <id>tag:blogs.perl.org,2011:/users/leon_timmermans//150.1470</id>

    <published>2011-02-16T00:12:23Z</published>
    <updated>2011-02-16T00:28:34Z</updated>

    <summary>Module::Build is a popular module to complain about. Much of it is either whining or completely outdated (sometimes both). I use it in most of my modules and so far it is my preferred module builder, this is not merely...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="buildpl" label="Build.PL" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="inheritance" label="inheritance" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="modulebuild" label="module::build" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="roles" label="roles" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p><em>Module::Build is a popular module to complain about. Much of it is either whining or completely outdated (sometimes both). I use it in most of my modules and so far it is my preferred module builder, this is not merely a rant on something I don't want to use.</em></p>

<p>The vast majority of modules, probably something like 95%, don't need anything special. They are just some Perl files, maybe with some XS: their build process is entirely standard. That means that <strong>for 95% of all modules out there it doesn't really matter what you use</strong>, as long as it doesn't break. Module::Build, Module::Install and ExtUtils::MakeMaker all work fine. Boring, but boring is a good thing in a toolchain. Module::Build is a frequently used option, but lets be honest, it hasn't exactly eclipsed ExtUtils::MakeMaker and Module::Install. In fact, the latter seems to be the usual choice among the "cool modules" (Moose, Catalyst, etc&#133;).</p>

<h1>The rest</h1>

<p>The other 5% is where things gets interesting. There are basically two approaches to them:</p>

<ol>
<li>Writing custom code</li>
<li>Writing reusable components that you can reuse next time</li>
</ol>

<p>Obviously, the second is to be preferred whenever possible. That scenario should have been a homerun for Module::Build. Reality is different, there are hardly any extensions for it on CPAN. In fact Module::Install seems to have more of them. What the hell went wrong?</p>

<p>Module::Build is very extendable, but those extensions are not reusable. IMO there are two design decisions here to blame:</p>

<h1>Inheritance</h1>

<p>Extending Module::Build is done by subclassing it. This works fine for simple examples, but has a major problem: it only works with well single inheritance. Because of that you can not combine Module::Build::PDL with Module::Build::WithXSpp for example. This greatly limits the usefulness of such extensions. This problem should be obvious to anyone who's familiar with <a href="http://www.modernperlbooks.com/mt/2009/05/perl-roles-versus-interfaces-and-abcs.html">roles</a>. When you compare it with how easy it is to extend Dist::Zilla for example, the problem of this design becomes glaring obvious.</p>

<h1>God object</h1>

<p>The problem mentioned above is aggravated by the fact that almost all behavior is mashed together in one class. Granted, it delegates a few platform specific behaviors to platform specific subclasses, but almost all other behavior is implemented in Module::Build::Base. It has more than 5600 lines and 342 methods (269 public, 73 protected) including 84 accessors. It's massive. You can't naively add roles to that and expect it to work out.</p>

<h1>How to get out of this mess?</h1>

<p>Well, that's the topic of my next post&#133; ;-)</p>
]]>
        

    </content>
</entry>

<entry>
    <title>A lookback on the past few months</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2010/12/a-lookback-on-the-past-few-months.html" />
    <id>tag:blogs.perl.org,2010:/users/leon_timmermans//150.1290</id>

    <published>2010-12-31T18:03:52Z</published>
    <updated>2010-12-31T18:17:10Z</updated>

    <summary>It&apos;s been some time since I last blogged. My next post will be looking forward to what I&apos;m planning to write next year, but first I should blog about what stuff I&apos;ve come up with in the past couple of...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="epoll" label="epoll" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="event" label="event" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="filehandles" label="filehandles" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="sharedmemory" label="shared memory" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>It's been some time since I last blogged. My next post will be looking forward to what I'm planning to write next year, but first I should blog about what stuff I've come up with in the past couple of months.</p>

<h1>Shared memory</h1>

<p>I had already written POSIX::RT::SharedMem before, but even though POSIX IPC is a great idea (for being remarkably sane to use) it isn't widely implemented (Linux, Solaris and  recent versions of OS X support it out of the box, FreeBSD does too but you have to enable it explicitly). Therefor I ended up writing SysV::SharedMem, which does pretty much the same thing, accessing shared memory as a string, but implemented using a different backend. It's largely derived from File::Map, unlike POSIX::RT::SharedMem that delegates most of the work to File::Map. Writing it has made my conviction that SysV IPC is an incredably crappy API even stronger, but fortunately that's largely hidden from the end-user.</p>

<h1>Building blocks</h1>

<p>I wrote a number of building blocks, mostly small and simple ones, though one ended up being a bit larger and more complicated than initially planned. </p>

<ul>
<li>Threads::Sigmask <br />
This module enables thread specific signal masks on threaded perls, but falls back on process signal masks on non-threaded perls.</li>
<li>Signal::Mask <br />
A convenient tie-based interface for signal masks</li>
<li>Linux::FD <br />
eventfd, signalfd and timerfd filehandles</li>
<li>Linux::Epoll <br />
A callback style scalable event multiplexer for Linux</li>
</ul>

<p>They cover a number of different things, but there is a line through them: they are all the pieces needed to write a modern, fast and efficient event loop for Linux. There are many event-loops written in C that use these functions, but in Perl they were either unavailable(thread specific signal masks, special filehandles) or had modules that were unsatisfying to me (epoll). I'm not sure that event-loop needs to be written, but I find experimenting with it highly educational.</p>

<h1>Misc</h1>

<p>Other than that, an increasing amount of my time has gone to maintainance of existing modules. I'm barely past 20 and it already feel bogged by them, I can't imagine what it must be like to have 200 modules on CPAN.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>The proof Perl gets you laid</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2010/11/the-proof-perl-gets-you-laid.html" />
    <id>tag:blogs.perl.org,2010:/users/leon_timmermans//150.1184</id>

    <published>2010-11-18T17:16:01Z</published>
    <updated>2010-11-18T17:22:17Z</updated>

    <summary>Of course we already knew it, but now we&apos;ve got proof!...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="sarcasm" label="sarcasm" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>Of course we already knew it, but now we've got proof!</p>

<p><img alt="the_proof.png" src="http://blogs.perl.org/users/leon_timmermans/2010/11/18/the_proof.png" width="460" height="662" class="mt-image-none" style="" /></p>]]>
        
    </content>
</entry>

<entry>
    <title>Perl Is My Community</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2010/09/perl-is-my-community.html" />
    <id>tag:blogs.perl.org,2010:/users/leon_timmermans//150.1028</id>

    <published>2010-09-17T23:06:21Z</published>
    <updated>2011-02-23T23:25:19Z</updated>

    <summary>I like the Perl community. We have a open, tolerant and helpful community. Looking around to other languages, I do think we&#8217;re in a much better shape then most people seem to realize. I loathe the Python community&#8217;s snobbish and...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="community" label="community" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="pinc" label="pinc" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>I like the Perl community. We have a open, tolerant and helpful community. Looking around to other languages, I do think we&#8217;re in a much better shape then most people seem to realize.</p>

<p>I loathe the Python community&#8217;s snobbish and hostile attitude to newcomers and outsiders. Maybe I&#8217;m biased by having to counter FUD in people who have been exposed to the Python community, but I can&#8217;t call it anything else. I wouldn&#8217;t be the first to suggest that&#8217;s the main reason they never took over even when they were otherwise in a much better shape than we were. They threw bricks into their own windows and I am somewhat doubtful they&#8217;ll get a second chance.</p>

<p>PHP did the exact opposite, and behold: they&#8217;re more popular than sliced bread. That seemed to be a double edged knife though: it seems to attract more people who have no idea how little they know than any other language, resulting in the PHP community being completely dominated by amateurs. Don&#8217;t get me wrong - I don&#8217;t dislike newbies, in fact I have more friends in this category than any of the others I&#8217;m discussing here - but there has to be a certain ratio of capable versus incapable programmers for a community to remain healthy. Perl once was in that same position and we&#8217;re still recovering from it a decade later. Despite its current popularity I don&#8217;t envy the position they&#8217;re in. Maybe they&#8217;ll have their own renaissance ten years from now.</p>

<p>I&#8217;m hearing some early signs Ruby (or Rails in particular) is going to get the newbie carrot next. Maybe I&#8217;m being cynical here, but if I were a member of the Ruby community I&#8217;d worry about how to handle them. Growth is nice but how do you keep it sustainable? That may prove to be an interesting challenge for them.</p>

<p>Meanwhile, I&#8217;m comfortable and warm in the Perl community. It&#8217;s healthier than most and that&#8217;s more important than being the coolest or the most popular kid on the block.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Yet another readonly module</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2010/08/yet-another-readonly-module.html" />
    <id>tag:blogs.perl.org,2010:/users/leon_timmermans//150.961</id>

    <published>2010-08-31T21:55:57Z</published>
    <updated>2010-08-31T23:07:43Z</updated>

    <summary>I&#8217;m done with Readonly. It has served it&#8217;s purpose but I&#8217;m frustrated to the point of writing a replacement. I still think it&#8217;s a good idea to declare variables readonly, but as an implementation I find Readonly unworkable. The problem...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <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/leon_timmermans/">
        <![CDATA[<p>I&#8217;m done with <a href="http://search.cpan.org/perldoc?Readonly">Readonly</a>. It has served it&#8217;s purpose but I&#8217;m frustrated to the point of writing a replacement. I still think it&#8217;s a good idea to declare variables readonly, but as an implementation I find Readonly unworkable. The problem is two-fold.</p>

<h1>Maintenance.</h1>

<p>Readonly hasn&#8217;t been updated in 6 years. It has collected quite a <a href="https://rt.cpan.org/Dist/Display.html?Queue=Readonly">list of bugs</a>. Not all of them can be fixed, but most that can be are either trivial or already have patches. Fact is it hasn&#8217;t been done and I have my doubts on whether it will be done.</p>

<h1>Broken by design</h1>

<p>Readonly has a number of design issues. It uses ties for its implementation. This is not only slow, but also rather buggy. There are lots of subtle corner cases to ties, and Readonly has probably run into a lot of them, though I suspect there may be more waiting to be discovered. Most of its bugs are related to this. There are some more issues but they are relatively minor compared to this. Your variable shouldn&#8217;t have unexpected behavior simply because it&#8217;s readonly, that&#8217;s madness.</p>

<p>The sad part is that ties aren&#8217;t really necessary here. Perl 5 has always supported real readonly variables, and though this functionality wasn&#8217;t exposed for Perl code until 5.8. It makes a lot more sense to use the real thing. The optional Readonly::XS tries to do that for scalars, but in the most common use case of Readonly (using sub Readonly on a scalar) it isn&#8217;t actually used (this is probably a bug).</p>

<h1>Introducing Const::Fast</h1>

<p>So I&#8217;ve written my own module, <a href="http://search.cpan.org/perldoc?Const::Fast">Const::Fast</a>. It does not use ties or XS. It has one function <code>const</code>, that simply makes a scalar, array or hash recursively readonly. Without the speed penalty of ties and without the bizarre class of bugs that they bring.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Why uvar magic must die</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2010/08/why-uvar-magic-must-die.html" />
    <id>tag:blogs.perl.org,2010:/users/leon_timmermans//150.930</id>

    <published>2010-08-21T12:15:00Z</published>
    <updated>2011-12-10T21:20:31Z</updated>

    <summary>Uvar magic must die. Maybe it&#8217;s too late for a complete removal, but it&#8217;s use should at least be discouraged. One of the reasons is that it&#8217;s actually two very different things that don&#8217;t have all that much in common....</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="guts" label="guts" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="magic" label="magic" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="rant" label="rant" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="xs" label="xs" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>Uvar magic must die. Maybe it&#8217;s too late for a complete removal, but it&#8217;s use should at least be discouraged. One of the reasons is that it&#8217;s actually two very different things that don&#8217;t have all that much in common.</p>

<h1>Scalar uvar magic</h1>

<p>Scalar uvar magic isn&#8217;t actually evil, it&#8217;s just fairly useless. It&#8217;s a way to add get and set hooks to scalars. It may have been a useful interface back when it was introduced in 1993, but with the introduction of custom magic vtables in 5.8 it stopped particularly useful. The new interface is more powerful in many ways and in typical cases it that takes less code to use. There&#8217;s absolutely no reason why anyone should still be using scalar uvar magic unless you have to maintain compatibility with 5.6.</p>

<h1>Hash uvar magic</h1>

<p>I blogged before about <a href="http://blogs.perl.org/users/leon_timmermans/2010/08/what-are-magic-hash-key-transformations.html">what hash uvar magic is</a> and <a href="http://blogs.perl.org/users/leon_timmermans/2010/07/using-magic-hash-key-transformation.html">how to use it</a>. Hash uvar magic is an abomination. It is the single most horrible interface in the whole of the perl API and that is an achievement. p5p must have been asleep when they allowed it in.</p>

<p>You may wonder, why is it so evil? It abuses the relatively sane interfaces of scalar uvar magic and uses for some completely different purposes. Parameters and even properties of the parameters get completely new functions. It&#8217;s a case of fitting a square peg in a round hole.</p>

<p><img src="http://www.keychangesmusictherapy.com/wp-content/uploads/2010/08/square_peg_in_round_hole_2.jpg" alt="square peg in a round hole" title="" /></p>

<p>The callback doesn&#8217;t even receive it&#8217;s most important parameter (the key value) as an argument! You have to use <code>mg_find</code> to extract it out of one of the arguments (the hash). Equally bad, there&#8217;s absolutely no way to add data to the magic (other than adding more magic) because all possible fields are already in use: uvar itself uses <code>mg_ptr</code> and <code>mg_len</code>. The hash magic clobbers both <code>mg_obj</code> and <code>uf_index</code>.</p>

<p>The saddest thing is that all of this wasn&#8217;t necessary. It should have been easy to define some new kind of magic that passes it&#8217;s data in a more sane way quite easily. Maybe it&#8217;s not too late yet and the current API can be deprecated in favor of something sane (it&#8217;s not like people are using it a lot so far).</p>
]]>
        

    </content>
</entry>

<entry>
    <title>What are magic hash key transformations</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/leon_timmermans/2010/08/what-are-magic-hash-key-transformations.html" />
    <id>tag:blogs.perl.org,2010:/users/leon_timmermans//150.912</id>

    <published>2010-08-17T14:30:49Z</published>
    <updated>2011-02-23T23:25:32Z</updated>

    <summary>Some weeks ago I posted a brain-dump that only got reaction like that looks interesting, but I have no idea what you&#8217;re talking about, so I&#8217;m going to try to explain what I was doing. Since 5.10, perl supports uvar...</summary>
    <author>
        <name>Leon Timmermans</name>
        <uri>http://codespeaks.blogspot.com/</uri>
    </author>
    
    <category term="guts" label="guts" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="magic" label="magic" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="xs" label="xs" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/leon_timmermans/">
        <![CDATA[<p>Some weeks ago I posted a <a href="http://blogs.perl.org/users/leon_timmermans/2010/07/using-magic-hash-key-transformation.html">brain-dump</a> that only got reaction like <em>that looks interesting, but I have no idea what you&#8217;re talking about</em>, so I&#8217;m going to try to explain what I was doing.</p>

<p>Since 5.10, perl supports uvar magic on hashes, though I called it magic hash key transformations because that gives at least tries to describe what it does. This was implemented to make <a href="http://search.cpan.org/perldoc?Hash::Util::FieldHash">fieldhashes</a> possible. It&#8217;s an interface that does only one thing: when a hash element is accessed in any way the callback is called. The callback can&#8217;t change the semantics of the operation (unless it dies), all it can do is change the value of the key looked up. So it can transform $hash{A} into $hash{B}.</p>

<p>Nothing more, nothing less.</p>

<p>AFAIK, there are only 4 modules on CPAN that use it</p>

<ul>
<li>Hash::Util::FieldHash: The original user of this API.</li>
<li><a href="http://search.cpan.org/perldoc?Hash::FieldHash">Hash::FieldHash</a>: A simpler reimplementation of H::U::F.</li>
<li><a href="http://search.cpan.org/perldoc?Variable::Magic">Variable::Magic</a>: A module making magic accessable from perl (instead of XS). This means you can actually use this stuff without hacking XS (though it will obviously be a bit slower).</li>
<li><a href="http://search.cpan.org/perldoc?Class::Private">Class::Private</a>: a module I wrote and used as example in my previous post. It rewrites $hash{key} to $hash{&#8216;Package::key&#8217;} in order to prevent collisions in key values between sub- and super-classes.</li>
</ul>

<p>Why aren&#8217;t more modules using this? Probably because it&#8217;s fairly limited in what useful things it can do. I&#8217;m sure there are more uses of it, but I can&#8217;t think of any (that&#8217;s not true, for my previous post I was considering writing Acme::Keys::Rot13). It&#8217;s an interface with a limited purpose, though it can be useful sometimes.</p>

<p>In my next post, more about the darker side uvar magic.</p>
]]>
        

    </content>
</entry>

</feed>
