<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Perlsphere</title>
  <link rel="alternate" href="http://perlsphere.net/" type="text/html"/>
  <updated>2012-05-17T16:13:06Z</updated>
  <generator>Plagger/0.7.17</generator>
  <subtitle>The Perl firehose! The Web's biggest collection of Perl 5 blogs.&lt;br /&gt;If you'd like your Perl 5 blog or tech blog's Perl category to appear here, send mail to &amp;#108;&amp;#101;&amp;#111;&amp;#64;&amp;#99;&amp;#117;&amp;#99;&amp;#107;&amp;#111;&amp;#111;&amp;#46;&amp;#111;&amp;#114;&amp;#103;&lt;br /&gt;(Please have several posts already).</subtitle>
  <id>tag:perlsphere.net,2006:smartfeed:all</id>
  <entry>
    <title>Test::WWW::Selenium::More</title>
    <link rel="alternate" href="http://ericjohnson.posterous.com/testwwwseleniummore" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">I recently released Test::WWW::Selenium::More to CPAN. It is a small
collection of utilities to help you write Selenium tests. Here are some
reasons to use it:

  1. 

    It has a manual which provides a short but fairly comprehensive howto
    guide to Selenium testing in Perl.

  2. 

    It uses Moose so you can more easily use roles. For example you might
    want a role for methods that deal with authentication and a role for
    methods that deal with payments.

  3. 

    Smarter testing with methods like wait_for_jquery() and
    jquery_click(). You should never sleep() in your Selenium tests
    because that leads to slow tests with random failures which leads to
    frustration, low morale, hair pulling, and heavy drinking.

  4. 

    Method chaining. Here is what this looks like:

    use Test::Most; use Test::WWW::Selenium::More;

    Test::WWW::Selenium::More-&gt;new()

    –&gt;note(‘Search google’) –&gt;open_ok(“http://www.google.com”)
    –&gt;title_like(qr/Google Search/) –&gt;type_ok(‘cat pictures’)
    –&gt;follow_link_ok(‘Search’)

    –&gt;note(‘Check the number of results’) –&gt;is_text_present_ok(‘2
    bajillion results’);

    done_testing;

Bugs or patches? https://github.com/kablamo/Test-WWW-Selenium-More

Permalink | Leave a comment »</div>
    </summary>
    <content type="html">
        &lt;p&gt;
	&lt;p&gt;I recently released &lt;a href="https://metacpan.org/module/Test::WWW::Selenium::More"&gt;Test::WWW::Selenium::More&lt;/a&gt; to CPAN.  It is a small collection of utilities to help you write Selenium tests.  Here are some reasons to use it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It has a &lt;a href="https://metacpan.org/module/Test::WWW::Selenium::More::Manual"&gt;manual&lt;/a&gt; which
provides a short but fairly comprehensive howto guide to Selenium testing in
Perl.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It uses Moose so you can more easily use roles.  For example you might want
a role for methods that deal with authentication and a role for methods that
deal with payments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Smarter testing with methods like wait_for_jquery() and jquery_click().  You
should never sleep() in your Selenium tests because that leads to slow tests
with random failures which leads to frustration, low morale, hair pulling, and
heavy drinking.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Method chaining.  Here is what this looks like:&lt;/p&gt;

&lt;p&gt; use Test::Most;
 use Test::WWW::Selenium::More;&lt;/p&gt;

&lt;p&gt; Test::WWW::Selenium::More-&amp;gt;new()&lt;/p&gt;

&lt;p&gt;   &amp;ndash;&amp;gt;note(&amp;lsquo;Search google&amp;rsquo;)
   &amp;ndash;&amp;gt;open_ok(&amp;ldquo;&lt;a href="http://www.google.com"&gt;http://www.google.com&lt;/a&gt;&amp;rdquo;)
   &amp;ndash;&amp;gt;title_like(qr/Google Search/)
   &amp;ndash;&amp;gt;type_ok(&amp;lsquo;cat pictures&amp;rsquo;)
   &amp;ndash;&amp;gt;follow_link_ok(&amp;lsquo;Search&amp;rsquo;)&lt;/p&gt;

&lt;p&gt;   &amp;ndash;&amp;gt;note(&amp;lsquo;Check the number of results&amp;rsquo;)
   &amp;ndash;&amp;gt;is_text_present_ok(&amp;lsquo;2 bajillion results&amp;rsquo;);&lt;/p&gt;

&lt;p&gt; done_testing;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Bugs or patches?  &lt;a href="https://github.com/kablamo/Test-WWW-Selenium-More"&gt;https://github.com/kablamo/Test-WWW-Selenium-More&lt;/a&gt;&lt;/p&gt;
	
&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ericjohnson.posterous.com/testwwwseleniummore"&gt;Permalink&lt;/a&gt; 

	| &lt;a href="http://ericjohnson.posterous.com/testwwwseleniummore#comment"&gt;Leave a comment&amp;nbsp;&amp;nbsp;&amp;raquo;&lt;/a&gt;

&lt;/p&gt;
      </content>
    <published>2012-05-17T05:49:46-07:00</published>
    <updated>2012-05-17T05:49:46-07:00</updated>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006:http://ericjohnson.posterous.com/testwwwseleniummore</id>
  </entry>
  <entry>
    <title>Time Will Tell</title>
    <link rel="alternate" href="http://www.modernperlbooks.com/mt/2012/05/time-will-tell.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">The May 2012 Dr. Dobb's interview with Ward Cunningham has an interesting
quote about Ward's notion of technical debt:

  I was really devoted to finding great code, especially when objects
  were new. Objects gave us an extra dimension beyond functional
  decomposition. And the question was, "Are these the right objects or
  not?" And the answer was, "Time will tell."

I work off and on with a handful of great programmers in the Portland
area. Several years ago, James Shore and Dave Woldrich created
CardMeeting, an agile remote collaboration tool. Jim and Dave are both
very good programmers. For this project, they decided to forgo their
usual test-driven development and just write code so as to deliver a
working prototype on a vry strict deadline.

Jim took to calling that experience "leveraged technical debt". My
estimate (not having read the code, but having tested a lot of code
written without testing in mind) is that it takes at least as long to
write tests for untested code as it took to write the code and much
longer the more time has passed between writing the code and writing the
tests.

Jim, Dave, and I have all worked on small, software-driven businesses
doing things we've never seen anyone else do before. We've all had to
deal with the risk of building lots of code that may or may not solve the
problems of real customers with real money. When I say write the wrong
code first, I don't mean "deliberately do things you know won't work" or
"paint yourself into a corner" or even "use the fact you don't know
everything you're doing as an excuse to play with completely new
technologies you don't know how to use". (Not that the latter is a bad
thing, but if you decide to do that, do so only after you've considered
the risks and the rewards.)

Last night, we had a short conversation with John Wilger, another PDXer.
He works with a successful and relatively young startup with a huge
software component. I don't want to put words in his mouth, but it sounds
like their software is, colloquially, a mess. Their developer team is
trying to get to the point of slapping hands whenever someone needs to
make a change and starts by copying and pasting code.

Four years after founding (and two years after discovering its cash cow
business), the company was worth at least $3 billion.

It's irresponsible to derive meaningful statistics from a single data
point, but we can say this: the technical debt of their codebase didn't
entirely prevent the company from achieving its current measure of
success. (You can also say that the liberal application of candy-flavored
magical unicorn shavings of Ruby and Rails didn't prevent people from
making an unholy mess.)

Time will tell if changing the development culture and refactoring the
code and paying down all of the technical debt will help the company
adapt and take advantages of new opportunities.

Time will tell if the codebase collapses under its own weight.

Time will tell if a competitor (and several exist!) will prove more agile
and nimble because it has much better flexibility thanks, in part, to
better code.

The whole situation reminds me of Facebook's HipHop virtual machine,
where it's apparently cheaper and easier and faster and less risky to
hire lots of developers to create and maintain a compatibility layer for
the existing code than to rewrite existing code in a better language, or
in a better fashion, or to improve it meaningfully.

I'm not suggesting that the only way to build a big business from nothing
is to write bad code. I'm not suggesting that scaling to billions in
revenue is the goal of all software-driven businesses. I'm not suggesting
that you have to choose between test-driven development and business
success.

In an ideal world, I can write the right software the first time. I can
have sufficient test coverage to have complete confidence in the behavior
of the code. I can deliver a feature which gets me paying customers in an
afternoon without having to rewrite other parts of the code or taking
shortcuts I know that I'll have to clean up when I get a spare weekend
afternoon.

For a profession where some of us call ourselves "engineers", we
certainly spend a lot of time discussing practical concerns as if the
risks and rewards and limitations of the real world did not apply. (I
wonder if the academic/practical divide between computer science and
software development has some relationship to this.)

In the real world, I have to remind myself every day when I'm working on
proof of concept code that proving my concept workable is more important
than solidifying my code into well-tested and well-designed software and
when I'm working on code I intend to keep that doing things as right as
possible now will help me modify it to get it more right in the future.

None of this guarantees success. All of this benefits from the hard-won
experiences I have from doing things the wrong way—and occasionally
getting it very right. (In the real world, I spent part of the day
finding and deploying a shim to turn SVG into VML for Internet Explorer 8
and earlier.)

Maybe Jim and Dave could have thrown out a couple of features and spent
more time writing tests for the most valuable parts of their application.
Maybe I'm wasting my time optimizing SQL queries for a search feature no
one will ever use. Maybe John's company waited too long to untangle the
admin and the user sides of their application.

If we're honest with ourselves, the best answer we can give is that time
will tell. May we pay attention when it does.</div>
    </summary>
    <content type="html">
        &lt;p&gt;The &lt;a href="http://www.drdobbs.com/architecture-and-design/240000393"&gt;May 2012 Dr. Dobb's interview with Ward Cunningham&lt;/a&gt; has an interesting quote about Ward's notion of technical debt:&lt;/p&gt;

&lt;blockquote&gt;&lt;em&gt;I was really devoted to finding great code, especially when objects were new. Objects gave us an extra dimension beyond functional decomposition. And the question was, "Are these the right objects or not?" And the answer was, "Time will tell."&lt;/em&gt;&lt;/blockquote&gt;

&lt;p&gt;I work off and on with a handful of great programmers in the Portland area.
Several years ago, &lt;a href="http://jamesshore.com/"&gt;James Shore&lt;/a&gt; and &lt;a href="http://woldrich.com/"&gt;Dave Woldrich&lt;/a&gt; created &lt;a href="http://cardmeeting.com/"&gt;CardMeeting&lt;/a&gt;, an agile remote collaboration
tool. Jim and Dave are both very good programmers. For this project, they
decided to forgo their usual test-driven development and just write code so as
to deliver a working prototype on a vry strict deadline.&lt;/p&gt;

&lt;p&gt;Jim took to calling that experience "leveraged technical debt". My estimate
(not having read the code, but having tested a lot of code written without
testing in mind) is that it takes at least as long to write tests for untested
code as it took to write the code &lt;em&gt;and much longer the more time has passed
between writing the code and writing the tests&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Jim, Dave, and I have all worked on small, software-driven businesses doing
things we've never seen anyone else do before. We've all had to deal with the
risk of building lots of code that may or may not solve the problems of real
customers with real money. When I say &lt;a href="http://www.modernperlbooks.com/mt/2012/05/write-the-wrong-code-first.html"&gt;write
the wrong code first&lt;/a&gt;, I don't mean "deliberately do things you know won't
work" or "paint yourself into a corner" or even "use the fact you don't know
everything you're doing as an excuse to play with completely new technologies
you don't know how to use". (Not that the latter is a bad thing, but if you
decide to do that, do so only after you've considered the risks and the
rewards.)&lt;/p&gt;

&lt;p&gt;Last night, we had a short conversation with &lt;a href="http://johnwilger.com/"&gt;John Wilger&lt;/a&gt;, another PDXer. He works with a
successful and relatively young startup with a huge software component. I don't
want to put words in his mouth, but it sounds like their software is,
colloquially, a mess. Their developer team is trying to get to the point of
slapping hands whenever someone needs to make a change and starts by copying
and pasting code.&lt;/p&gt;

&lt;p&gt;Four years after founding (and two years after discovering its cash cow
business), the company was worth at least $3 billion.&lt;/p&gt;

&lt;p&gt;It's irresponsible to derive meaningful statistics from a single data point,
but we can say this: the technical debt of their codebase didn't entirely
prevent the company from achieving its current measure of success. (You can
also say that the liberal application of candy-flavored magical unicorn
shavings of Ruby and Rails didn't prevent people from making an unholy
mess.)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Time will tell&lt;/em&gt; if changing the development culture and refactoring
the code and paying down all of the technical debt will help the company adapt
and take advantages of new opportunities.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Time will tell&lt;/em&gt; if the codebase collapses under its own weight.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Time will tell&lt;/em&gt; if a competitor (and several exist!) will prove more
agile and nimble because it has much better flexibility thanks, in part, to
better code.&lt;/p&gt;

&lt;p&gt;The whole situation reminds me of &lt;a href="https://www.facebook.com/notes/facebook-engineering/the-hiphop-virtual-machine/10150415177928920"&gt;Facebook's
HipHop virtual machine&lt;/a&gt;, where it's apparently cheaper and easier and
faster and less risky to hire lots of developers to create and maintain a
compatibility layer for the existing code than to rewrite existing code in a
better language, or in a better fashion, or to improve it meaningfully.&lt;/p&gt;

&lt;p&gt;I'm not suggesting that the only way to build a big business from nothing is
to write bad code. I'm not suggesting that scaling to billions in revenue is
the goal of all software-driven businesses. I'm not suggesting that you have to
choose between test-driven development and business success.&lt;/p&gt;

&lt;p&gt;In an ideal world, I can write the right software the first time. I can have
sufficient test coverage to have complete confidence in the behavior of the
code. I can deliver a feature which gets me paying customers in an afternoon
without having to rewrite other parts of the code or taking shortcuts I know
that I'll have to clean up when I get a spare weekend afternoon.&lt;/p&gt;

&lt;p&gt;For a profession where some of us call ourselves "engineers", we certainly
spend a lot of time discussing practical concerns as if the risks and rewards
and limitations of the real world did not apply. (I wonder if the
academic/practical divide between computer science and software development has
some relationship to this.)&lt;/p&gt;

&lt;p&gt;In the real world, I have to remind myself every day when I'm working on
proof of concept code that proving my concept workable is more important than
solidifying my code into well-tested and well-designed software and when I'm
working on code I intend to keep that doing things as right as possible now
will help me modify it to get it more right in the future.&lt;/p&gt;

&lt;p&gt;None of this guarantees success. All of this benefits from the hard-won
experiences I have from doing things the wrong way&amp;mdash;and occasionally
getting it very right. (In the real world, I spent part of the day finding and
deploying a shim to turn SVG into VML for Internet Explorer 8 and earlier.)&lt;/p&gt;

&lt;p&gt;Maybe Jim and Dave could have thrown out a couple of features and spent more
time writing tests for the most valuable parts of their application. Maybe I'm
wasting my time optimizing SQL queries for a search feature no one will ever
use. Maybe John's company waited too long to untangle the admin and the user
sides of their application.&lt;/p&gt;

&lt;p&gt;If we're honest with ourselves, the best answer we can give is that time
will tell. May we pay attention when it does.&lt;/p&gt;
        
    </content>
    <category term="refactoring software development testing"/>
    <published>2012-05-16T22:28:41Z</published>
    <updated>2012-05-16T22:28:41Z</updated>
    <author>
      <name>chromatic</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.modernperlbooks.com,2012:/mt//1.450</id>
  </entry>
  <entry>
    <title>Hidden unhelpful reviews on cpanratings.org</title>
    <link rel="alternate" href="http://blogs.perl.org/users/phred/2012/05/hidden-unhelpful-reviews-on-cpanratingsorg.html" type="text/html"/>
    <summary type="text">I noticed that on the module review pages linked from search.cpan.org and
metacpan.org that 'unhelpful' reviews are inaccessible. The text is
contained in a div as such:


&lt; div data-dist="module_name" id="show_unhelpful"&gt;

3 hidden unhelpful reviews

&lt; /div&gt;

Does anyone know if that link is expected to expand and show the
unhelpful review text? I'm always interested in opinions of others,
whether they be good, bad, or ugly.</summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>I noticed that on the module review pages linked from search.cpan.org and metacpan.org that 'unhelpful' reviews are inaccessible. The text is contained in a div as such:</p>

<p><br/>
&lt; div data-dist="module_name" id="show_unhelpful"&gt;</p>

<p>   3 hidden unhelpful reviews</p>

<p>&lt; /div&gt;</p>

<p>Does anyone know if that link is expected to expand and show the unhelpful review text? I'm always interested in opinions of others, whether they be good, bad, or ugly.</p>
        
    </div>
    </content>
    <published>2012-05-16T17:56:30Z</published>
    <updated>2012-05-16T17:56:30Z</updated>
    <author>
      <name>Phred</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:blogs.perl.org,2012:/users/phred//210.3252</id>
  </entry>
  <entry>
    <title>Perl Unicode Cookbook: Match Unicode Properties in Regex</title>
    <link rel="alternate" href="http://www.perl.com/pub/2012/05/perlunicook-match-unicode-properties-in-regex.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Editor's note: Perl guru Tom Christiansen created and maintains a list of
44 recipes for working with Unicode in Perl 5. Perl.com is pleased to
serialize this list over the coming weeks.


℞ 25: Match Unicode properties in regex with \p, \P
---------------------------------------------------

Every Unicode codepoint has one or more properties, indicating the rules
which apply to that codepoint. Perl's regex engine is aware of these
properties; use the \p{} metacharacter sequence to match a codepoint
possessing that property and its inverse, \P{} to match a codepoint
lacking that property.

Each property has a short name and a long name. For example, to match any
codepoint which has the Letter property, you may use \p{Letter} or \p{L}.
Similarly, you may use \P{Uppercase} or \P{Upper}. perldoc perlunicode's
"Unicode Character Properties" section describes these properties in
greater detail.

Examples of these properties useful in regex include:

 \pL, \pN, \pS, \pP, \pM, \pZ, \pC
 \p{Sk}, \p{Ps}, \p{Lt}
 \p{alpha}, \p{upper}, \p{lower}
 \p{Latin}, \p{Greek}
 \p{script=Latin}, \p{script=Greek}
 \p{East_Asian_Width=Wide}, \p{EA=W}
 \p{Line_Break=Hyphen}, \p{LB=HY}
 \p{Numeric_Value=4}, \p{NV=4}</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>Editor's note:</em> Perl guru <a href="http://training.perl.com/">Tom Christiansen</a> created and maintains a list of 44 recipes for working with Unicode in Perl 5. Perl.com is pleased to serialize this list over the coming weeks.</p>

<h2 id="Match-Unicode-properties-in-regex-with-p-P">℞ 25: Match Unicode properties in regex with <code>\p</code>, <code>\P</code></h2>

<p>Every Unicode codepoint has one or more properties, indicating the rules
which apply to that codepoint. Perl's regex engine is aware of these
properties; use the <code>\p{}</code> metacharacter sequence to match a
codepoint possessing that property and its inverse, <code>\P{}</code> to match
a codepoint lacking that property.</p>

<p>Each property has a short name and a long name. For example, to match any
codepoint which has the <code>Letter</code> property, you may use
<code>\p{Letter}</code> or <code>\p{L}</code>. Similarly, you may use
<code>\P{Uppercase}</code> or <code>\P{Upper}</code>. <a href="http://perldoc.perl.org/perlunicode.html#Unicode-Character-Properties">perldoc
perlunicode's "Unicode Character Properties" section</a> describes these
properties in greater detail.</p>

<p>Examples of these properties useful in regex include:</p>

<pre><code> \pL, \pN, \pS, \pP, \pM, \pZ, \pC
 \p{Sk}, \p{Ps}, \p{Lt}
 \p{alpha}, \p{upper}, \p{lower}
 \p{Latin}, \p{Greek}
 \p{script=Latin}, \p{script=Greek}
 \p{East_Asian_Width=Wide}, \p{EA=W}
 \p{Line_Break=Hyphen}, \p{LB=HY}
 \p{Numeric_Value=4}, \p{NV=4}</code></pre>
        
    </div>
    </content>
    <published>2012-05-16T13:00:01Z</published>
    <updated>2012-05-16T13:00:01Z</updated>
    <author>
      <name>Tom Christiansen</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.perl.com,2012:/pub//2.2028</id>
  </entry>
  <entry>
    <title>Use of DBI in Sqitch</title>
    <link rel="alternate" href="http://feedproxy.google.com/~r/justatheory/atomsum/~3/L2fS5_mX_GU/dbi-in-sqitch.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Sqitch uses the native database client applications (psql, sqlite3, mysql,
etc.). So for tracking metadata about the state of deployments, I have
been trying to stick to using them. I’m first targeting PostgreSQL, and
as a result need to open a connection to psql, start a transaction, and
be able to read and write stuff to it as migrations go along. The IPC is
a huge PITA. Furthermore, getting things properly quoted is also pretty
annoying — and it will be worse for SQLite and MySQL, I expect (psql’s
--set support is pretty slick).

Read More »

[IMAGE]</div>
    </summary>
    <content type="html">
&lt;p&gt;&lt;a href="http://sqitch.org/"&gt;Sqitch&lt;/a&gt; uses the native database client applications (&lt;a href="http://www.postgresql.org/docs/current/static/app-psql.html"&gt;&lt;code&gt;psql&lt;/code&gt;&lt;/a&gt;, &lt;a href="http://man.he.net/man1/sqlite3"&gt;&lt;code&gt;sqlite3&lt;/code&gt;&lt;/a&gt;, &lt;a href="http://dev.mysql.com/doc/refman/5.5/en/mysql.html"&gt;&lt;code&gt;mysql&lt;/code&gt;&lt;/a&gt;, etc.). So for tracking metadata about the state of deployments, I have been trying to stick to using them. I&amp;rsquo;m first targeting PostgreSQL, and as a result need to open a connection to &lt;code&gt;psql&lt;/code&gt;, start a transaction, and be able to read and write stuff to it as migrations go along. &lt;a href="http://stackoverflow.com/questions/10569805/what-is-the-preferred-cross-platform-ipc-perl-module"&gt;The IPC&lt;/a&gt; is a &lt;a href="http://www.perlmonks.org/?node_id=970244"&gt;huge PITA&lt;/a&gt;. Furthermore, getting things properly quoted is also pretty annoying &amp;mdash; and it will be worse for SQLite and MySQL, I expect (&lt;code&gt;psql&lt;/code&gt;&amp;rsquo;s &lt;code&gt;--set&lt;/code&gt; support is pretty slick).&lt;/p&gt;&lt;p&gt;&lt;a href="http://justatheory.com/computers/databases/dbi-in-sqitch.html"&gt;Read More »&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/justatheory/atomsum/~4/L2fS5_mX_GU"&gt;</content>
    <published>2012-05-15T17:41:00Z</published>
    <updated>2012-05-15T17:41:00Z</updated>
    <author>
      <name>David E. Wheeler</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:justatheory.com,2012:/computers/databases/dbi-in-sqitch</id>
  </entry>
  <entry>
    <title>New Type Constraint Module for Perl</title>
    <link rel="alternate" href="http://blog.urth.org/2012/05/new-type-constraint-module-for-perl.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">I recently uploaded a new distro to CPAN recently called Type. The
concepts are largely on Moose's built-in type system, but it's a
standalone distribution.

Right now this is all very alpha, and the current release is not intended
for use by anyone. I've released so people can take a look at critique
the design. I've tried to remedy some of the problems that Moose's type
system has. MooseX::Types fixes some of these problems but then
introduces its own. Type addresses the problems of both.

My long-term goal is to replace Moose's built-in system with Type. This
will probably mean rewriting Type to not use Moose itself. The current
release uses Moose because it made it easy to prototype the system.

Here's the comparison with Moose and MooseX::Types from the Type distro's
docs:


Type names are strings, but they're not global
----------------------------------------------

Unlike Moose and MooseX::Types, type names are always local to the
current package. There is no possibility of name collision between
different modules, so you can safely use short types names for code.

Unlike MooseX::Types, types are strings, so there is no possibility of
colliding with existing class or subroutine names.


No type auto-creation
---------------------

Types are always retrieved using the t() subroutine. If you pass an
unknown name to this subroutine it dies. This is different from Moose and
MooseX::Types, which assume that unknown names are class names.


Exceptions are objects
----------------------

The $type-&gt;validate_or_die() method throws a Type::Exception object on
failure, not a string.


Anon types are explicit
-----------------------

With Moose and MooseX::Types, you use the same subroutine, subtype(), to
declare both named and anonymous types. With Type, you use declare() for
named types and anon() for anonymous types.


Class and object types are separate
-----------------------------------

Moose and MooseX::Types have class_type and duck_type. The former type
requires an object, while the latter accepts a class name or object.

In Type, the distinction between accepting an object versus object or
class is explicit. There are four declaration helpers, object_can_type,
object_isa_type, any_can_type, and any_isa_type.


Overloading support is baked in
-------------------------------

Perl's overloading is broken as hell, but ignoring it makes Moose's type
system frustrating.


Types can either have a constraint or inline generator, not both
----------------------------------------------------------------

Moose and MooseX::Types types can be defined with a subroutine reference
as the constraint, an inline generator subroutine, or both. This is
purely for backwards compatibility, and it makes the internals more
complicated than they need to be.

With Type, a constraint can have either a subroutine reference or an
inline generator, not both.


Coercions can be inlined
------------------------

I simply never got around to implementing this in Moose.


No crazy coercion features
--------------------------

Moose has some bizarre (and mostly) undocumented features relating to
coercions and parameterizable types. This is a misfeature.


Your feedback is requested
--------------------------

The current distro has mostly complete docs, so it should give you a
sense of what I'm aiming at.

I'd love to hear from the Perl community on this distribution. Do this
seem like it'd help fix problems you've had with Moose types? Can you
imagine using this distribution without using Moose? What's on your
wishlist?</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>I recently uploaded a new distro to CPAN recently called <a href="https://metacpan.org/release/DROLSKY/Type-0.02-TRIAL">Type</a>. The concepts are largely on Moose's built-in type system, but it's a standalone distribution.</p>

<p>Right now this is all very alpha, and the current release is not intended for use by anyone. I've released so people can take a look at critique the design. I've tried to remedy some of the problems that Moose's type system has. MooseX::Types fixes some of these problems but then introduces its own. Type addresses the problems of both.</p>

<p>My long-term goal is to replace Moose's built-in system with Type. This will probably mean rewriting Type to <em>not</em> use Moose itself. The current release uses Moose because it made it easy to prototype the system.</p>

<p>Here's the comparison with Moose and MooseX::Types from the Type distro's docs:</p>

<h2>Type names are strings, but they're not global</h2>

<p>Unlike Moose and MooseX::Types, type names are always local to the current package. There is no possibility of name collision between different modules, so you can safely use short types names for code.</p>

<p>Unlike MooseX::Types, types are strings, so there is no possibility of colliding with existing class or subroutine names.</p>

<h2>No type auto-creation</h2>

<p>Types are always retrieved using the <code>t()</code> subroutine. If you pass an unknown name to this subroutine it dies. This is different from Moose and MooseX::Types, which assume that unknown names are class names.</p>

<h2>Exceptions are objects</h2>

<p>The <code>$type-&gt;validate_or_die()</code> method throws a <code>Type::Exception</code> object on failure, not a string.</p>

<h2>Anon types are explicit</h2>

<p>With Moose and MooseX::Types, you use the same subroutine, <code>subtype()</code>, to declare both named and anonymous types. With Type, you use <code>declare()</code> for named types and <code>anon()</code> for anonymous types.</p>

<h2>Class and object types are separate</h2>

<p>Moose and MooseX::Types have <code>class_type</code> and <code>duck_type</code>. The former type requires an object, while the latter accepts a class name or object.</p>

<p>In Type, the distinction between accepting an object versus object or class is explicit. There are four declaration helpers, <code>object_can_type</code>, <code>object_isa_type</code>, <code>any_can_type</code>, and <code>any_isa_type</code>.</p>

<h2>Overloading support is baked in</h2>

<p>Perl's overloading is broken as hell, but ignoring it makes Moose's type system frustrating.</p>

<h2>Types can either have a constraint or inline generator, not both</h2>

<p>Moose and MooseX::Types types can be defined with a subroutine reference as the constraint, an inline generator subroutine, or both. This is purely for backwards compatibility, and it makes the internals more complicated than they need to be.</p>

<p>With Type, a constraint can have <em>either</em> a subroutine reference or an inline generator, not both.</p>

<h2>Coercions can be inlined</h2>

<p>I simply never got around to implementing this in Moose.</p>

<h2>No crazy coercion features</h2>

<p>Moose has some bizarre (and mostly) undocumented features relating to coercions and parameterizable types. This is a misfeature.</p>

<h2>Your feedback is requested</h2>

<p>The current distro has mostly complete docs, so it should give you a sense of what I'm aiming at.</p>

<p>I'd love to hear from the Perl community on this distribution. Do this seem like it'd help fix problems you've had with Moose types? Can you imagine using this distribution without using Moose? What's on your wishlist?</p>

        

    </div>
    </content>
    <category term="Programming"/>
    <published>2012-05-15T03:21:27Z</published>
    <updated>2012-05-15T03:21:27Z</updated>
    <author>
      <name>Dave Rolsky</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:blog.urth.org,2012://2.208</id>
  </entry>
  <entry>
    <title>Perlbuzz news roundup for 2012-05-14</title>
    <link rel="alternate" href="http://feedproxy.google.com/~r/PerlBuzz/~3/9yfCnPNae8Q/perlbuzz-news-roundup-for-2012-05-14.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">These links are collected from the Perlbuzz Twitter feed. If you have
suggestions for news bits, please mail me at andy@perlbuzz.com.

  * YAPC::NA will be livestreamed in real-time for free (blog.yapcna.org)

  * Introduction to how to do Perl one-liners (catonmat.net)

  * NYTProf, File IO, and an Optimization Gone Awry (modernperlbooks.com)

  * Reddit API for Perl (blogs.perl.org)

  * Lots of Perl authors at YAPC::NA this year (blog.yapcna.org)

  * Review of "Programming Perl, 4th ed." (i-programmer.info)

  * Don't use Cache::Memcached for UTF8 strings (domm.plix.at)

  * PerlGSL, interfaces to the GNU Scientific Library (blogs.perl.org)

  * Learning Perl with testing (nbezzala.blogspot.com)

  * Separating presentation and content in TT (modernperlbooks.com)

[IMAGE] [IMAGE] [IMAGE] [IMAGE][IMAGE]</div>
    </summary>
    <content type="html">
        &lt;p&gt;
These links are collected from the
&lt;a href="http://twitter.com/perlbuzz"&gt;Perlbuzz Twitter feed&lt;/a&gt;.
If you have suggestions for news bits, please mail me at
&lt;a href="mailto:andy@perlbuzz.com"&gt;andy@perlbuzz.com&lt;/a&gt;.
&lt;/p&gt;

&lt;ul&gt;

&lt;li&gt;YAPC::NA will be livestreamed in real-time for free (&lt;a href="http://blog.yapcna.org/post/22588737837/yapc-na-will-be-televised"&gt;blog.yapcna.org&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Introduction to how to do Perl one-liners (&lt;a href="http://www.catonmat.net/blog/introduction-to-perl-one-liners/"&gt;catonmat.net&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;NYTProf, File IO, and an Optimization Gone Awry (&lt;a href="http://www.modernperlbooks.com/mt/2012/05/nytprof-file-io-and-an-optimization-gone-awry.html"&gt;modernperlbooks.com&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Reddit API for Perl (&lt;a href="http://blogs.perl.org/users/jeff_ober/2012/05/reddit-api-for-perl.html"&gt;blogs.perl.org&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Lots of Perl authors at YAPC::NA this year (&lt;a href="http://blog.yapcna.org/post/22717040291/lots-of-perl-authors"&gt;blog.yapcna.org&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Review of "Programming Perl, 4th ed." (&lt;a href="http://i-programmer.info/bookreviews/116-perl/4189-programming-perl.html"&gt;i-programmer.info&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Don't use Cache::Memcached for UTF8 strings (&lt;a href="http://domm.plix.at/perl/2012_05_10_dont_use_cache_memcached_for_utf8_strings.html"&gt;domm.plix.at&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;PerlGSL, interfaces to the GNU Scientific Library (&lt;a href="http://blogs.perl.org/users/joel_berger/2012/05/announcing-perlgsl---a-collection-of-perlish-interfaces-to-the-gnu-scientific-library.html"&gt;blogs.perl.org&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Learning Perl with testing (&lt;a href="http://nbezzala.blogspot.com/2012/04/learning-perl-with-testing.html"&gt;nbezzala.blogspot.com&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Separating presentation and content in TT (&lt;a href="http://www.modernperlbooks.com/mt/2012/05/separating-presentation-from-content-in-templates.html"&gt;modernperlbooks.com&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

        
    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/PerlBuzz?a=9yfCnPNae8Q:-WfIU6fGL0o:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PerlBuzz?d=yIl2AUoC8zA"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PerlBuzz?a=9yfCnPNae8Q:-WfIU6fGL0o:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PerlBuzz?i=9yfCnPNae8Q:-WfIU6fGL0o:F7zBnMyn0Lo"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PerlBuzz?a=9yfCnPNae8Q:-WfIU6fGL0o:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PerlBuzz?i=9yfCnPNae8Q:-WfIU6fGL0o:V_sGLiPBpWU"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/PerlBuzz?a=9yfCnPNae8Q:-WfIU6fGL0o:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/PerlBuzz?d=qj6IDK7rITs"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/PerlBuzz/~4/9yfCnPNae8Q"&gt;</content>
    <category term="CPAN Perl 5 Conferences"/>
    <published>2012-05-14T19:20:11Z</published>
    <updated>2012-05-14T19:20:11Z</updated>
    <author>
      <name>Andy Lester</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:perlbuzz.com,2012://1.885</id>
  </entry>
  <entry>
    <title>Separating Presentation from Content in Templates</title>
    <link rel="alternate" href="http://www.modernperlbooks.com/mt/2012/05/separating-presentation-from-content-in-templates.html" type="text/html"/>
    <summary type="text">A couple of comments on Simple Attribute-Based Template Exporting have
asked for an example. I'll show off more of this code in my YAPC::NA 2012
and Open Source Bridge 2012 talk about how to write the wrong code (along
with a handful of other techniques).

(I assume some knowledge of Template Toolkit (besides far too many books
about finance, accounting, and investing, the Template Toolkit book is
always within reach these days); I've set up a wrapper template which
provides the standard look and feel of my application and I
include/process other templates liberally. If you understand that much,
you'll be able to follow along.)

One of the interesting templates in the system displays a list of
chapters of a book in progress. A cron job rebuilds a static page from
this template once a day. The template looks something much like:

[% USE Bootstrap -%]
[%- canonical_url = 'http://sitename.example.com/book/' _ link -%]

[%- add_og_properties({
    'fb:admins'      =&gt; '436500086365356',
    'og:title'       =&gt; title _ ' | sitename.example.com',
    'og:type'        =&gt; 'article',
    'og:image'       =&gt; 'http://static.sitename.example.com/images/logo.png',
    'og:url'         =&gt; canonical_url,
    'og:description' =&gt; text.chunk(300).0,
    'og:site_name'   =&gt; 'Sitename: site tag line',
   })
-%]
[%- add_meta(
    'pagetitle'     =&gt; title _ ' | sitename.example.com',
    'feed_url'      =&gt; 'http://static.sitename.example.com/book/atom.xml'
    'canonical_url' =&gt; canonical_url
) -%]

[% article_text = BLOCK -%]
&lt;article&gt;
&lt;h2&gt;[% title | html %]&lt;/h2&gt;
&lt;p&gt;Published: &lt;time datetime="[% date %]"&gt;[% nice_date %]&lt;/time&gt;&lt;/p&gt;
[% text %]
&lt;/article&gt;

&lt;ul class="pager"&gt;
[%- IF prev -%]
    &lt;li&gt;&lt;a href="[% prev.link %].html"&gt;← [% prev.title | html %]&lt;/a&gt;&lt;/li&gt;
[%- END -%]
    &lt;li&gt;&lt;a href="/onehourinvestor"&gt;index&lt;/a&gt;&lt;/li&gt;
[%- IF next -%]
    &lt;li&gt;&lt;a href="[% next.link %].html"&gt;[% next.title | html %] →&lt;/a&gt;&lt;/li&gt;
[%- END -%]
&lt;/ul&gt;

[% INCLUDE 'components/social_links.tt', title =&gt; title %]
[%- END -%]
[%- row(
    maincontent( article_text ),
    sidebar(
        sideblock( process( 'components/cached/book_latest_chapters.tt' ) ),
        sideblock( process( 'components/cached/book_drafts.tt'          ) )
    )
) -%]

The emboldened lines are most important; they put all of the content
produced or assembled by this template in the HTML structure the site
needs. That is to say, everything on the site needs to fit into something
I call a row. A row can contain multiple elements, such as maincontent
and a sidebar, or fullcontent by itself with no sidebar. A sidebar can
contain multiple sideblocks.

(You can ignore the other functions; they put metadata in the right
places to pass to wrapper templates.)

Within my template plugin (called Bootstrap), each of these elements is a
simple Perl function which takes one or more arguments and interpolates
it into some HTML:

sub row :Export
{
    return &lt;&lt;END_HTML;
&lt;div class="row"&gt;
    @_
&lt;/div&gt;
END_HTML
}

sub sidebar :Export
{
    return &lt;&lt;END_HTML;
&lt;div class="span4"&gt;
    @_
&lt;/div&gt;
END_HTML
}

(I initially tried to write these functions as templates within Template
Toolkit itself, but there comes a point at which you want a real
language. That point came very early for me.)

I lose no love over the varname = BLOCK pattern necessary to populate
variables to pass to these plugin functions, but it works for now. In
some of my templates—usually those with lots of text I might end up
changing later—I extract that text into a separate template under
components/content/ to make it easy to edit. (This idea came up during a
client project where the client wanted to edit the legal clickthrough
arrangement after users create accounts. I didn't want lawyers or anyone
to have the ability to mess up the templating language, so I said "Edit
this single file as plain HTML and you'll be fine." It worked great.)

While my programmer brain says "This is ugly, and you're a horrible
person for committing this hack upon the world—you're calling Perl from
your template system to generate HTML you're stuffing into a template and
that puts your presentation elements in Perl code, you awful human
being!", it keeps the presentation code in a single place where I can
update it infrequently (being that I don't change the layout of the site
dramatically) without having to change the divs and classes of multiple
templates.

I'm not arguing that this technique as expressed here is right. It's
probably not optimal; there may be easier approaches to achieve the same
effects.

I am saying that this currently works very well for me. I'm not typing
the same HTML over and over and over again, and I can tweak it much more
easily than I did before when I was refining the look and feel. In fact,
I've even forgotten the exact details of the layout, from the HTML/CSS
point of view, and now think only in terms of rows, maincontent, and
sidebars.

Working abstractions are very nice.</summary>
    <content type="html">
        &lt;p&gt;A couple of comments on &lt;a href="http://www.modernperlbooks.com/mt/2012/05/simple-attribute-based-template-exporting.html"&gt;Simple
Attribute-Based Template Exporting&lt;/a&gt; have asked for an example. I'll show off
more of this code in my &lt;a href="http://act.yapcna.org/2012/talk/50"&gt;YAPC::NA
2012&lt;/a&gt; and &lt;a href="http://opensourcebridge.org/proposals/796"&gt;Open Source
Bridge 2012&lt;/a&gt; talk about how to write the wrong code (along with a handful of
other techniques).&lt;/p&gt;

&lt;p&gt;(I assume some knowledge of &lt;a href="http://search.cpan.org/perldoc?Template"&gt;Template Toolkit&lt;/a&gt; (besides
far too many books about finance, accounting, and investing, the Template
Toolkit book is always within reach these days); I've set up a wrapper template
which provides the standard look and feel of my application and I
include/process other templates liberally. If you understand that much, you'll
be able to follow along.)&lt;/p&gt;

&lt;p&gt;One of the interesting templates in the system displays a list of chapters
of a book in progress. A cron job rebuilds a static page from this template
once a day. The template looks something much like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[% USE Bootstrap -%]
[%- canonical_url = 'http://sitename.example.com/book/' _ link -%]

[%- add_og_properties({
    'fb:admins'      =&amp;gt; '436500086365356',
    'og:title'       =&amp;gt; title _ ' | sitename.example.com',
    'og:type'        =&amp;gt; 'article',
    'og:image'       =&amp;gt; 'http://static.sitename.example.com/images/logo.png',
    'og:url'         =&amp;gt; canonical_url,
    'og:description' =&amp;gt; text.chunk(300).0,
    'og:site_name'   =&amp;gt; 'Sitename: site tag line',
   })
-%]
[%- add_meta(
    'pagetitle'     =&amp;gt; title _ ' | sitename.example.com',
    'feed_url'      =&amp;gt; 'http://static.sitename.example.com/book/atom.xml'
    'canonical_url' =&amp;gt; canonical_url
) -%]

[% article_text = BLOCK -%]
&amp;lt;article&amp;gt;
&amp;lt;h2&amp;gt;[% title | html %]&amp;lt;/h2&amp;gt;
&amp;lt;p&amp;gt;Published: &amp;lt;time datetime="[% date %]"&amp;gt;[% nice_date %]&amp;lt;/time&amp;gt;&amp;lt;/p&amp;gt;
[% text %]
&amp;lt;/article&amp;gt;

&amp;lt;ul class="pager"&amp;gt;
[%- IF prev -%]
    &amp;lt;li&amp;gt;&amp;lt;a href="[% prev.link %].html"&amp;gt;&amp;larr; [% prev.title | html %]&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
[%- END -%]
    &amp;lt;li&amp;gt;&amp;lt;a href="/onehourinvestor"&amp;gt;index&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
[%- IF next -%]
    &amp;lt;li&amp;gt;&amp;lt;a href="[% next.link %].html"&amp;gt;[% next.title | html %] &amp;rarr;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
[%- END -%]
&amp;lt;/ul&amp;gt;

[% INCLUDE 'components/social_links.tt', title =&amp;gt; title %]
[%- END -%]

&lt;strong&gt;[%- row(
    maincontent( article_text ),
    sidebar(
        sideblock( process( 'components/cached/book_latest_chapters.tt' ) ),
        sideblock( process( 'components/cached/book_drafts.tt'          ) )
    )
) -%]&lt;/strong&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The emboldened lines are most important; they put all of the
&lt;em&gt;content&lt;/em&gt; produced or assembled by this template in the HTML structure
the site needs. That is to say, everything on the site needs to fit into
something I call a &lt;code&gt;row&lt;/code&gt;. A &lt;code&gt;row&lt;/code&gt; can contain multiple
elements, such as &lt;code&gt;maincontent&lt;/code&gt; and a &lt;code&gt;sidebar&lt;/code&gt;, or
&lt;code&gt;fullcontent&lt;/code&gt; by itself with no &lt;code&gt;sidebar&lt;/code&gt;. A
&lt;code&gt;sidebar&lt;/code&gt; can contain multiple &lt;code&gt;sideblock&lt;/code&gt;s.&lt;/p&gt;

&lt;p&gt;(You can ignore the other functions; they put metadata in the right places
to pass to wrapper templates.)&lt;/p&gt;

&lt;p&gt;Within my template plugin (called &lt;code&gt;Bootstrap&lt;/code&gt;), each of these
elements is a simple Perl function which takes one or more arguments and
interpolates it into some HTML:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sub row :Export
{
    return &amp;lt;&amp;lt;END_HTML;
&amp;lt;div class="row"&amp;gt;
    @_
&amp;lt;/div&amp;gt;
END_HTML
}

sub sidebar :Export
{
    return &amp;lt;&amp;lt;END_HTML;
&amp;lt;div class="span4"&amp;gt;
    @_
&amp;lt;/div&amp;gt;
END_HTML
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;(I initially tried to write these functions as templates within Template
Toolkit itself, but there comes a point at which you want a real language. That
point came very early for me.)&lt;/p&gt;

&lt;p&gt;I lose no love over the &lt;code&gt;varname = BLOCK&lt;/code&gt; pattern necessary to
populate variables to pass to these plugin functions, but it works for now. In
some of my templates&amp;mdash;usually those with lots of text I might end up
changing later&amp;mdash;I extract that text into a separate template under
&lt;em&gt;components/content/&lt;/em&gt; to make it easy to edit. (This idea came up during
a client project where the client wanted to edit the legal clickthrough
arrangement after users create accounts. I didn't want lawyers or anyone to
have the ability to mess up the templating language, so I said "Edit this
single file as plain HTML and you'll be fine." It worked great.)&lt;/p&gt;

&lt;p&gt;While my programmer brain says "This is ugly, and you're a horrible person
for committing this hack upon the world&amp;mdash;you're calling Perl from your
template system to generate HTML you're stuffing into a template and that puts
your presentation elements in Perl code, you awful human being!", it keeps the
presentation code in a single place where I can update it infrequently (being
that I don't change the layout of the site dramatically) without having to
change the divs and classes of multiple templates.&lt;/p&gt;

&lt;p&gt;I'm not arguing that this technique as expressed here is &lt;em&gt;right&lt;/em&gt;.
It's probably not optimal; there may be easier approaches to achieve the same
effects.&lt;/p&gt;

&lt;p&gt;I am saying that this currently works very well for me. I'm not typing the
same HTML over and over and over again, and I can tweak it much more easily
than I did before when I was refining the look and feel. In fact, I've even
&lt;em&gt;forgotten&lt;/em&gt; the exact details of the layout, from the HTML/CSS point of
view, and now think only in terms of rows, maincontent, and sidebars.&lt;/p&gt;

&lt;p&gt;Working abstractions are very nice.&lt;/p&gt;
        
    </content>
    <category term="modern perl perl templating web programming"/>
    <published>2012-05-14T18:47:11Z</published>
    <updated>2012-05-14T18:47:11Z</updated>
    <author>
      <name>chromatic</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.modernperlbooks.com,2012:/mt//1.449</id>
  </entry>
  <entry>
    <title>Perl Unicode Cookbook: Disable Unicode-awareness in Builtin Character Classes</title>
    <link rel="alternate" href="http://www.perl.com/pub/2012/05/perlunicook-disable-unicode-awareness-in-builtin-character-classes.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Editor's note: Perl guru Tom Christiansen created and maintains a list of
44 recipes for working with Unicode in Perl 5. Perl.com is pleased to
serialize this list over the coming weeks.


℞ 24: Disabling Unicode-awareness in builtin charclasses
--------------------------------------------------------

Many regex tutorials gloss over the fact that builtin character classes
include far more than ASCII characters. In particular, classes such as
"word character" (\w), "word boundary" (\b), "whitespace" (\s), and
"digit" (\d) respect Unicode.

Perl 5.14 added the /a regex modifier to disable \w, \b, \s, \d, and the
POSIX classes from working correctly on Unicode. This restricts these
classes to mach only ASCII characters. Use the re pragma to restrict
these claracter classes in a lexical scope:

 use v5.14;
 use re "/a";

... or use the /a modifier to affect a single regex:

 my($num) = $str =~ /(\d+)/a;

You may always use speciﬁc un-Unicode properties, such \p{ahex} and
\p{POSIX_Digit}. Properties still work normally no matter what charset
modiﬁers (/d /u /l /a /aa) are in eﬀect.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>Editor's note:</em> Perl guru <a href="http://training.perl.com/">Tom Christiansen</a> created and maintains a list of 44 recipes for working with Unicode in Perl 5. Perl.com is pleased to serialize this list over the coming weeks.</p>

<h2 id="Disabling-Unicode-awareness-in-builtin-charclasses">℞ 24: Disabling Unicode-awareness in builtin charclasses</h2>

<p>Many regex tutorials gloss over the fact that builtin character classes include far more than ASCII characters. In particular, classes such as "word character" (<code>\w</code>), "word boundary" (<code>\b</code>), "whitespace" (<code>\s</code>), and "digit" (<code>\d</code>) respect Unicode.</p>

<p>Perl 5.14 added the <code>/a</code> regex modifier to disable <code>\w</code>, <code>\b</code>, <code>\s</code>, <code>\d</code>, and the <small>POSIX</small> classes from working correctly on Unicode. This restricts these classes to mach only ASCII characters. Use the <a href="http://perldoc.perl.org/re.html">re</a> pragma to restrict these claracter classes in a lexical scope:</p>

<pre><code> use v5.14;
 use re "/a";</code></pre>

<p>... or use the <code>/a</code> modifier to affect a single regex:</p>

<pre><code> my($num) = $str =~ /(\d+)/a;</code></pre>

<p>You may always use speciﬁc un-Unicode properties, such <code>\p{ahex}</code> and <code>\p{POSIX_Digit}</code>. Properties still work normally no matter what charset modiﬁers (<code>/d /u /l /a /aa</code>) are in eﬀect.</p>
        
    </div>
    </content>
    <published>2012-05-14T13:00:01Z</published>
    <updated>2012-05-14T13:00:01Z</updated>
    <author>
      <name>Tom Christiansen</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.perl.com,2012:/pub//2.2026</id>
  </entry>
  <entry>
    <title>Introducing KanaSwirl</title>
    <link rel="alternate" href="/2012/05/introducing-kanaswirl.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">KanaSwirl in the App Store

Some of you are reading this on the most efficient language learning
device ever designed: the iPhone. It can store many days' worth of target
language music and podcasts, many lifetimes' worth of target language
books, countless mono- and bilingual dictionaries, and includes an
operating system localized to practically any language people speak. Not
to mention there are loads of great apps designed for and by speakers of
your target language. And it even fits in your pocket so you can carry
your immersive environment with you all the time.

To that end, I have written and released a game called KanaSwirl. It
teaches you the 46 Japanese hiragana characters in a fun, quick, and easy
way. It is the kind of app I wish existed when I was starting out with
Japanese. It took me something like two months to become comfortable with
the kana. I hope my game enables everyone to trounce that.

If you have finished going through the learning process, KanaSwirl looks
like this:

Given the prompt MU you tap the corresponding kana, む. Pretty simple,
which is the point! You can pick it up at any time and do as many reviews
as you like.

Even simpler, if you are just starting out, the game goes easy on you.
You start off with just two characters, あ and い. Once you get the hang of
those, the game teaches you う, and so on.

The game dynamically responds to how well you're doing. On the individual
game level, if you are correctly answering the prompts quickly or slowly,
characters are added to or removed from the circle. And again, on the
global level, if you have been generally answering all the characters
correctly, KanaSwirl will teach you the next character.

It also tracks and offers some statistics about your reviews. I am very
interested in expanding this part of the experience. I look forward to
the day my app bluntly tells me what characters I frequently confuse.

I had a very fun week creating this game. The only problem is my Japanese
study suffered a lot that week. :)


Anki

KanaSwirl may seem like a competitor to Anki, but I think both have their
own separate strengths and complement eachother. I love Anki to death,
and if I have any success with Japanese it is Anki's fault. Anki is
certainly better at keeping tens of thousands of facts in your head (I'm
living proof!). It is also not limited to individual words or characters
like KanaSwirl is, but works with complete sentences or even pictures.

KanaSwirl has its advantages too. For one, when you finish your Anki
reviews for the day, it can be harmful to its spacing algorithm to get a
head start on future reviews, so you cannot sink as much free time into
it as you have — you stop reviewing when it says you are done. Secondly,
Anki is simply very sterile. This is certainly desirable for the kind of
proper study tool Anki is, but KanaSwirl intentionally makes it fun.
Finally, Anki does not guide you into learning new stuff. It is strictly
for reviewing the content you have imported into it. KanaSwirl introduces
new characters to you as you become ready for them.

Ultimately I want games I don't feel guilty playing. Sure Angry Birds is
entertaining, but at the end of the day what do you get out of it?


XCode/Objective-C development

This was my first non-Perl project in a very long time. It was also my
very first Objective C exposure. I'm having a blast with it. It feels
more natural as a C-with-objects than C++ ever did. Even though it is a
statically-typed, compiled language, I don't feel constrained. Other than
by the lack of map. Integer division tripped me up until I realized it
was happening.

Though Objective C is of course a C-like language, memory management was
surprisingly trivial. I wrote the initial bulk of the code without
concerning myself with memory problems. Occasionally I segfaulted on
sending a message to an autoreleased value. Apple provides a useful tool
called Zombies for detecting and fixing that class of problem. The
morning of the day I submitted version 1.0 for review, I decided to
actually look at how much memory my app was leaking. Another tool Apple
provides as part of its Instruments toolset is Leaks. To find the
sections of code that were causing memory leaks, all I had to do was
launch the app, play around until Leaks found something, then examine
stack traces. All told, nearly all of my errors were caused by blindly
using [[NSString alloc] initWithFormat:] which creates a string object
using sprintf-style interpolation. The problem is that strings
constructed that way must be manually released.

XCode is a solid IDE, and that is saying a lot coming from a die-hard vim
user. I am productive even without XVim (vim bindings for Xcode).
Admittedly I did copy blocks of code into vim for the nastiest edits I
needed to do.

I'm using the cocos2d game framework and I'm quite impressed with how
easy it is to use.

id twirlAndMove = [CCSpawn actions:
                    [CCRotateBy actionWithDuration:spinoutDuration angle:360],
                    [CCMoveBy actionWithDuration:spinoutDuration position:ccp(x,y)],
                    nil];
[kanaButton runAction: twirlAndMove];

After adding those simple lines of code the app suddenly became a game.
Now instead of simply popping into existence in-place, the kana buttons
you tap to answer questions now simultaneously rotate 360 degrees and
move from the center to their desired position (calculated with sin and
cos). Now the game is dynamic. cocos2d is full of easy, effective tools
like this. Another tool I want to highlight is scene transitions — just a
single additional function call lets you page flip from one scene to the
other, or slide, or any of the other dozens of builtin transitions. The
only thing I have found lacking so far is drawing individual pixels or
lines. You can do it with OpenGL but it isn't as frictionless as the rest
of the API.

The only big stumbling block I had was designing the icon. I think it's
passable. The designy bits in the app is actually limited to programmatic
effects: transitions, animations, and particle effects. For particle
effects I used an app called Particle Mint which gives you live previews
and editing on the device you will eventually run the game on. I wouldn't
say it was a delight to use, but it definitely got the job done without
getting in my way too much.

iPad support wasn't tricky at all. I just needed to switch to using sizes
and positions that refer to screen size instead of a constant number of
points. So if there ever were a third iOS device size, I probably would
not need to change much code to support it.


See also

I have been tweeting as @RPGlanguage since day one about this project,
including lots of screenshots and development notes. RPGlanguage is my
umbrella name for the (many!) games I plan to write.

There's also a token website rpglanguage.net which is currently just more
KanaSwirl screenshots.


I look forward to hearing your feedback! I'm very proud of what I
created.</div>
    </summary>
    <content type="html">
&lt;div&gt;
 &lt;a href="http://rpglanguage.net/KanaSwirl.app"&gt;
  &lt;img alt=""&gt;
  &lt;p&gt;KanaSwirl in the App Store&lt;/p&gt;
 &lt;/a&gt;
&lt;/div&gt;    

&lt;p&gt;&lt;span id="audience"&gt;Some of you&lt;/span&gt; are reading this on the most efficient language learning device ever designed: the iPhone. It can store many days' worth of target language music and podcasts, many lifetimes' worth of target language books, countless mono- and bilingual dictionaries, and includes an operating system localized to practically any language people speak. Not to mention there are loads of great apps designed for and by speakers of your target language. And it even fits in your pocket so you can carry your immersive environment with you all the time.
&lt;/p&gt;
&lt;p&gt;To that end, I have written and released a game called &lt;a href="http://rpglanguage.net/KanaSwirl.app"&gt;KanaSwirl&lt;/a&gt;. It teaches you the 46 Japanese hiragana characters in a fun, quick, and easy way. It is the kind of app I wish existed when I was starting out with Japanese. It took me something like two months to become comfortable with the kana. I hope my game enables everyone to trounce that.
&lt;/p&gt;
&lt;p&gt;If you have finished going through the learning process, KanaSwirl looks like this:&lt;/p&gt;
&lt;img alt=""&gt;
&lt;p&gt;Given the prompt MU you tap the corresponding kana, む. Pretty simple, which is the point! You can pick it up at any time and do as many reviews as you like.&lt;/p&gt;
&lt;p&gt;Even simpler, if you are just starting out, the game goes easy on you. You start off with just two characters, あ and い. Once you get the hang of those, the game teaches you う, and so on.&lt;/p&gt;
&lt;img alt=""&gt;
&lt;p&gt;The game dynamically responds to how well you're doing. On the individual game level, if you are correctly answering the prompts quickly or slowly, characters are added to or removed from the circle. And again, on the global level, if you have been generally answering all the characters correctly, KanaSwirl will teach you the next character.&lt;/p&gt;
&lt;p&gt;It also tracks and offers some statistics about your reviews. I am very interested in expanding this part of the experience. I look forward to the day my app bluntly tells me what characters I frequently confuse.&lt;/p&gt;
&lt;img alt=""&gt;
&lt;p&gt;I had a very fun week creating this game. The only problem is my Japanese study suffered a &lt;em&gt;lot&lt;/em&gt; that week. :)
&lt;/p&gt;
&lt;h3&gt;Anki&lt;/h3&gt;
&lt;p&gt;KanaSwirl may seem like a competitor to &lt;a href="http://ankisrs.net"&gt;Anki&lt;/a&gt;, but I think both have their own separate strengths and complement eachother. I love Anki to death, and if I have any success with Japanese it is Anki's fault. Anki is certainly better at keeping tens of thousands of facts in your head (I'm living proof!). It is also not limited to individual words or characters like KanaSwirl is, but works with complete sentences or even pictures.
&lt;/p&gt;
&lt;p&gt;KanaSwirl has its advantages too. For one, when you finish your Anki reviews for the day, it can be harmful to its spacing algorithm to get a head start on future reviews, so you cannot sink as much free time into it as you have &amp;mdash; you stop reviewing when it says you are done. Secondly, Anki is simply very sterile. This is certainly desirable for the kind of proper study tool Anki is, but KanaSwirl intentionally makes it fun. Finally, Anki does not guide you into learning new stuff. It is strictly for reviewing the content you have imported into it. KanaSwirl introduces new characters to you as you become ready for them.&lt;/p&gt;
&lt;p&gt;Ultimately I want &lt;em&gt;games&lt;/em&gt; I don't feel guilty playing. Sure Angry Birds is entertaining, but at the end of the day what do you get out of it?
&lt;/p&gt;
&lt;h3&gt;XCode/Objective-C development&lt;/h3&gt;
&lt;p&gt;This was my first non-Perl project in a very long time. It was also my very first Objective C exposure. I'm having a blast with it. It feels more natural as a C-with-objects than C++ ever did. Even though it is a statically-typed, compiled language, I don't feel constrained. Other than by the lack of &lt;code&gt;map&lt;/code&gt;. Integer division tripped me up until I realized it was happening.
&lt;/p&gt;
&lt;p&gt;Though Objective C is of course a C-like language, memory management was surprisingly trivial. I wrote the initial bulk of the code without concerning myself with memory problems. Occasionally I segfaulted on sending a message to an &lt;code&gt;autorelease&lt;/code&gt;d value. Apple provides a useful tool called &lt;em&gt;Zombies&lt;/em&gt; for detecting and fixing that class of problem. The morning of the day I submitted version 1.0 for review, I decided to actually look at how much memory my app was leaking. Another tool Apple provides as part of its &lt;em&gt;Instruments&lt;/em&gt; toolset is &lt;em&gt;Leaks&lt;/em&gt;. To find the sections of code that were causing memory leaks, all I had to do was launch the app, play around until Leaks found something, then examine stack traces. All told, nearly all of my errors were caused by blindly using &lt;code&gt;[[NSString alloc] initWithFormat:]&lt;/code&gt; which creates a string object using &lt;code&gt;sprintf&lt;/code&gt;-style interpolation. The problem is that strings constructed that way must be manually released.
&lt;/p&gt;
&lt;p&gt;XCode is a solid IDE, and that is saying a lot coming from a die-hard vim user. I am productive even without &lt;a href="https://github.com/JugglerShu/XVim"&gt;XVim&lt;/a&gt; (vim bindings for Xcode). Admittedly I did copy blocks of code into vim for the nastiest edits I needed to do.
&lt;/p&gt;
&lt;p&gt;I'm using the &lt;a href="http://www.cocos2d-iphone.org/"&gt;cocos2d&lt;/a&gt; game framework and I'm quite impressed with how easy it is to use.
&lt;/p&gt;
&lt;pre class="objc code_snippet"&gt;
&lt;span class="synType"&gt;id&lt;/span&gt; twirlAndMove = [CCSpawn actions:
                    [CCRotateBy actionWithDuration:spinoutDuration angle:&lt;span class="synConstant"&gt;360&lt;/span&gt;],
                    [CCMoveBy actionWithDuration:spinoutDuration position:ccp(x,y)],
                    &lt;span class="synConstant"&gt;nil&lt;/span&gt;];
[kanaButton runAction: twirlAndMove];
&lt;/pre&gt;
&lt;p&gt;After adding those simple lines of code the app suddenly became a game. Now instead of simply popping into existence in-place, the kana buttons you tap to answer questions now simultaneously rotate 360 degrees and move from the center to their desired position (calculated with &lt;code&gt;sin&lt;/code&gt; and &lt;code&gt;cos&lt;/code&gt;). Now the game is dynamic. cocos2d is full of easy, effective tools like this. Another tool I want to highlight is scene transitions &amp;mdash; just a single additional function call lets you page flip from one scene to the other, or slide, or any of the other dozens of builtin transitions. The only thing I have found lacking so far is drawing individual pixels or lines. You can do it with OpenGL but it isn't as frictionless as the rest of the API.
&lt;/p&gt;
&lt;p&gt;The only big stumbling block I had was designing the icon. I think it's passable. The designy bits in the app is actually limited to programmatic effects: transitions, animations, and particle effects. For particle effects I used an app called &lt;a href="http://itunes.apple.com/us/app/particle-mint/id445400440"&gt;Particle Mint&lt;/a&gt; which gives you live previews and editing on the device you will eventually run the game on. I wouldn't say it was a delight to use, but it definitely got the job done without getting in my way too much.
&lt;/p&gt;
&lt;p&gt;iPad support wasn't tricky at all. I just needed to switch to using sizes and positions that refer to screen size instead of a constant number of points. So if there ever were a third iOS device size, I probably would not need to change much code to support it.&lt;/p&gt;
&lt;h3&gt;See also&lt;/h3&gt;
&lt;p&gt;I have been tweeting as &lt;a href="http://twitter.com/RPGlanguage"&gt;@RPGlanguage&lt;/a&gt; since day one about this project, including lots of screenshots and development notes. RPGlanguage is my umbrella name for the (many!) games I plan to write.
&lt;/p&gt;
&lt;p&gt;There's also a token website &lt;a href="http://rpglanguage.net"&gt;rpglanguage.net&lt;/a&gt; which is currently just more KanaSwirl screenshots.
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;I look forward to hearing your feedback! I'm very proud of what I created.&lt;/p&gt;</content>
    <published>2012-05-14T00:00:00Z</published>
    <updated>2012-05-14T00:00:00Z</updated>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006:/2012/05/introducing-kanaswirl.html</id>
  </entry>
  <entry>
    <title>Perl Mova / YAPC::Russia 2012 is over!</title>
    <link rel="alternate" href="http://showmetheco.de/articles/2012/5/perl-mova-yapc-russia-2012-is-over.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">So the conference is over. And here are some numbers, photos, links,
thoughts, etc.

→ Keep reading</div>
    </summary>
    <content type="html">
                        
&lt;p&gt;So the conference is over.
And here are some numbers,
photos,
links,
thoughts,
etc.&lt;/p&gt;

            &amp;rarr; &lt;a href="/articles/2012/5/perl-mova-yapc-russia-2012-is-over.html#cut"&gt;Keep reading&lt;/a&gt;          </content>
    <category term="perl conference"/>
    <published>2012-05-14T02:00:00+02:00</published>
    <updated>2012-05-14T02:00:00+02:00</updated>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006:http://showmetheco.de/articles/2012/5/perl-mova-yapc-russia-2012-is-over.html</id>
  </entry>
  <entry>
    <title>Simple Attribute-Based Template Exporting</title>
    <link rel="alternate" href="http://www.modernperlbooks.com/mt/2012/05/simple-attribute-based-template-exporting.html" type="text/html"/>
    <summary type="text">If you're like me and your design skills are sufficient to modify
something decent to look nice but insufficient to create something from
first principles, you can do a lot worse than to play with Twitter
Bootstrap for your next web site.

I've used it successfully for a few projects and it's been great.

It's a lot better now that I've written my own silly little Template
Toolkit plugin to reduce the need for writing lots of repetitive HTML in
my templates. (It's like Haml but less ugly and more Perlish and easier
to extend.)

Writing a TT2 plugin is relatively easy. Of course I do it the wrong way;
when you initialize your plugin, you have the ability to manipulate TT2's
stash. This is the data structure representing the variables in scope in
your templates. Where a well-behaved template should use object methods
to perform its operations, my code stuffs function references in the
stash. Here's the relevant code:

sub new
{
    my ($class, $context, @params) = @_;

    $class-&gt;add_functions( $context );

    return $class-&gt;SUPER::new( $context, @params );
}

sub add_functions
{
    my ($class, $context) = @_;
    my $stash             = $context-&gt;stash;

    while (my ($name, $ref) = each %exports)
    {
        $stash-&gt;set( $name, $ref );
    }

    $stash-&gt;set( process =&gt; sub { $context-&gt;process( @_ ) } );
}

I'll fix this eventually, but the process of making this work was
interesting.

In my first attempt (see Write the Wrong Code First for the
justification), I'd write the function I needed, like row(), which
creates a new Bootstrap row or maincontent() which creates the main
content area of the page. Then I'd add that function to the %exports hash
and everything would work.

After the sixth function, keeping that list up to date was tedious. Then
I kept forgetting it. After all, any time you have to update the same
data in two places, you're doing something wrong.

Now the code looks more like:

sub row :Export{
    return &lt;&lt;END_HTML;
&lt;div class="row"&gt;
    @_
&lt;/div&gt;
END_HTML
}

... with a single code attribute marking those functions which I want to
stuff into the template stash. I've used Attribute::Handlers before, but
I always end up reading the manual and playing with things to get them to
work correctly. (Something about the way you have to write another
package and inherit from it to get your attributes to work correctly
always confuses me.)

My second attempt lasted no longer than ten minutes. I switched to
Attribute::Lexical. This is almost as trivial to use as to explain:

use Attribute::Lexical 'CODE:Export' =&gt; \&amp;export_code;

Whenever any function has the :Export attribute, Perl wil lcall my
export_code() function:

my %exports;

sub export_code
{
    my $referent = shift;
    my $name     = Sub::Identify::sub_name( $referent );

    return unless $name;
    $exports{$name} = $referent;
}

The first argument to this function is a reference to the exported
function. I use Sub::Identify to get the name of the function reference.
(That wouldn't work for anonymous functions, but I can control that
here.) Then I store the name of the function and the function reference
in a hash.

It took as long to write as it does to explain.

A lot of people dislike the use of attributes. Used poorly, they create
weird couplings and plenty of action at a distance. Attribute::Handlers
can be confusing.

I like to think that I'm using attributes well here (even if I'm abusing
TT2 more than a little), and that they've simplified my code so that I
can avoid repeating myself and performing manual busywork that I'm likely
to forget. Even better, the code to use them isn't magical at all: it's
all hidden behind the pleasant interfaces of Attribute::Lexical and
Sub::Identify.</summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>If you're like me and your design skills are sufficient to modify something
decent to look nice but insufficient to create something from first principles,
you can do a lot worse than to play with <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a> for your next
web site.</p>

<p>I've used it successfully for a few projects and it's been great.</p>

<p>It's a lot better now that I've written my own silly little <a href="http://template-toolkit.org/">Template Toolkit</a> plugin to reduce the
need for writing lots of repetitive HTML in my templates. (It's like <a href="http://haml-lang.com/">Haml</a> but less ugly and more Perlish and easier
to extend.)</p>

<p>Writing a TT2 plugin is relatively easy. Of course I do it the wrong way;
when you initialize your plugin, you have the ability to manipulate TT2's
stash. This is the data structure representing the variables in scope in your
templates. Where a well-behaved template should use object methods to perform
its operations, my code stuffs function references in the stash. Here's the
relevant code:</p>

<pre><code>sub new
{
    my ($class, $context, @params) = @_;

    $class-&gt;add_functions( $context );

    return $class-&gt;SUPER::new( $context, @params );
}

sub add_functions
{
    my ($class, $context) = @_;
    my $stash             = $context-&gt;stash;

    while (my ($name, $ref) = each %exports)
    {
        $stash-&gt;set( $name, $ref );
    }

    $stash-&gt;set( process =&gt; sub { $context-&gt;process( @_ ) } );
}</code></pre>

<p>I'll fix this eventually, but the process of making this work was
interesting.</p>

<p>In my first attempt (see <a href="http://www.modernperlbooks.com/mt/2012/05/write-the-wrong-code-first.html">Write
the Wrong Code First</a> for the justification), I'd write the function I
needed, like <code>row()</code>, which creates a new Bootstrap row or
<code>maincontent()</code> which creates the main content area of the page.
Then I'd add that function to the <code>%exports</code> hash and everything
would work.</p>

<p>After the sixth function, keeping that list up to date was tedious. Then I
kept forgetting it. After all, any time you have to update the same data in two
places, you're doing something wrong.</p>

<p>Now the code looks more like:</p>

<pre><code>sub row <strong>:Export</strong>
{
    return &lt;&lt;END_HTML;
&lt;div class="row"&gt;
    @_
&lt;/div&gt;
END_HTML
}</code></pre>

<p>... with a single code attribute marking those functions which I want to
stuff into the template stash. I've used <a href="http://search.cpan.org/perldoc?Attribute::Handlers">Attribute::Handlers</a>
before, but I always end up reading the manual and playing with things to get
them to work correctly. (Something about the way you have to write another
package and inherit from it to get your attributes to work correctly always
confuses me.)</p>

<p>My second attempt lasted no longer than ten minutes. I switched to <a href="http://search.cpan.org/perldoc?Attribute::Lexical">Attribute::Lexical</a>. This is almost as trivial to use as to explain:</p>

<pre><code>use Attribute::Lexical 'CODE:Export' =&gt; \&amp;export_code;</code></pre>

<p>Whenever any function has the <code>:Export</code> attribute, Perl wil lcall
my <code>export_code()</code> function:</p>

<pre><code>my %exports;

sub export_code
{
    my $referent = shift;
    my $name     = Sub::Identify::sub_name( $referent );

    return unless $name;
    $exports{$name} = $referent;
}</code></pre>

<p>The first argument to this function is a reference to the exported function.
I use <a href="http://search.cpan.org/perldoc?Sub::Identify">Sub::Identify</a>
to get the name of the function reference. (That wouldn't work for anonymous
functions, but I can control that here.) Then I store the name of the function
and the function reference in a hash.</p>

<p>It took as long to write as it does to explain.</p>

<p>A lot of people dislike the use of attributes. Used poorly, they create
weird couplings and plenty of action at a distance.
<code>Attribute::Handlers</code> can be confusing.</p>

<p>I like to think that I'm using attributes well here (even if I'm abusing TT2
more than a little), and that they've simplified my code so that I can avoid
repeating myself and performing manual busywork that I'm likely to forget. Even
better, the code to use them isn't magical at all: it's all hidden behind the
pleasant interfaces of <code>Attribute::Lexical</code> and
<code>Sub::Identify</code>.</p>
        
    </div>
    </content>
    <category term="cpan modern perl perl web programming"/>
    <published>2012-05-11T20:29:01Z</published>
    <updated>2012-05-11T20:29:01Z</updated>
    <author>
      <name>chromatic</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.modernperlbooks.com,2012:/mt//1.448</id>
  </entry>
  <entry>
    <title>Perl Unicode Cookbook: Get Character Categories</title>
    <link rel="alternate" href="http://www.perl.com/pub/2012/05/perlunicook-get-character-categories.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Editor's note: Perl guru Tom Christiansen created and maintains a list of
44 recipes for working with Unicode in Perl 5. Perl.com is pleased to
serialize this list over the coming weeks.


℞ 23: Get character category
----------------------------

Unicode is a set of characters and a list of rules and properties applied
to those characters. The Unicode Character Database collects those
properties. The core module Unicode::UCD provides access to these
properties.

These general properties group characters into groups, such as upper- or
lowercase characters, punctuation symbols, math symbols, and more. (See
Unicode::UCD's general_categories() for more information.)

The charinfo() function returns a hash reference containing a wealth of
information about the Unicode character in question. In particular, its
category value contains the short name of a character's category.

To find the general category of a numeric codepoint:

 use Unicode::UCD qw(charinfo);
 my $cat = charinfo(0x3A3)-&gt;{category};  # "Lu"

To translate this category into something more human friendly:

 use Unicode::UCD qw( charinfo general_categories );
 my $categories = general_categories();
 my $cat        = charinfo(0x3A3)-&gt;{category};  # "Lu"
 my $full_cat   = $categories{ $cat }; # "UppercaseLetter"</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>Editor's note:</em> Perl guru <a href="http://training.perl.com/">Tom Christiansen</a> created and maintains a list of 44 recipes for working with Unicode in Perl 5. Perl.com is pleased to serialize this list over the coming weeks.</p>

<h2 id="Get-character-category">℞ 23: Get character category</h2>

<p>Unicode is a set of characters and a list of rules and properties applied to
those characters. The <a href="http://www.unicode.org/ucd/">Unicode Character
Database</a> collects those properties. The core module <a href="http://search.cpan.org/perldoc?Unicode::UCD">Unicode::UCD</a> provides
access to these properties.</p>

<p>These general properties group characters into groups, such as upper- or
lowercase characters, punctuation symbols, math symbols, and more. (See
<code>Unicode::UCD</code>'s <code>general_categories()</code> for more
information.)</p>

<p>The <code>charinfo()</code> function returns a hash reference containing a
wealth of information about the Unicode character in question. In particular,
its <code>category</code> value contains the short name of a character's
category.</p>

<p>To find the general category of a numeric codepoint:</p>

<pre><code> use Unicode::UCD qw(charinfo);
 my $cat = charinfo(0x3A3)-&gt;{category};  # "Lu"</code></pre>

<p>To translate this category into something more human friendly:</p>

<pre><code> use Unicode::UCD qw( charinfo general_categories );
 my $categories = general_categories();
 my $cat        = charinfo(0x3A3)-&gt;{category};  # "Lu"
 my $full_cat   = $categories{ $cat }; # "UppercaseLetter"</code></pre>
        
    </div>
    </content>
    <published>2012-05-11T13:00:01Z</published>
    <updated>2012-05-11T13:00:01Z</updated>
    <author>
      <name>Tom Christiansen</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.perl.com,2012:/pub//2.2024</id>
  </entry>
  <entry>
    <title>How do you update your system Perl?</title>
    <link rel="alternate" href="http://blogs.perl.org/users/brian_d_foy/2012/05/how-do-you-update-your-system-perl.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Although I'm an advocate of configuring and installing your own perl
while leaving the system perl alone, I'd like to have a list of the
various ways particular distros and package managers do it for the system
perl.

  1. The package manager program (e.g. yum, apt-get)

  2. The package name(s) to get the standard distribution, including the
    docs, ExtUtils::MakeMaker, and everything else

  3. Does that package manager allows you to configure, per-package, the
    installation location.

  4. Discovering module packages (what is the name, version of the
    module, etc)

  5. Your distro version, if it matters (do some distros change package
    managers)?

I can make a chart here if people chime in with what they know about
their system. I've seen scattered hints, but no where that pulls this all
together for the various major distros.</div>
    </summary>
    <content type="html">
        &lt;p&gt;Although I'm an advocate of configuring and installing your own perl while leaving the system perl alone, I'd like to have a list of the various ways particular distros and package managers do it for the system perl.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The package manager program (e.g. yum, apt-get)
&lt;li&gt;The package name(s) to get the standard distribution, including the docs, ExtUtils::MakeMaker, and everything else
&lt;li&gt;Does that package manager allows you to configure, per-package, the installation location.
&lt;li&gt;Discovering module packages (what is the name, version of the module, etc)
&lt;li&gt;Your distro version, if it matters (do some distros change package managers)?
&lt;/ol&gt;

&lt;p&gt;I can make a chart here if people chime in with what they know about their system. I've seen scattered hints, but no where that pulls this all together for the various major distros.&lt;/p&gt;
        
    </content>
    <published>2012-05-11T02:23:16Z</published>
    <updated>2012-05-11T02:23:16Z</updated>
    <author>
      <name>brian d foy</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:blogs.perl.org,2012:/users/brian_d_foy//178.3230</id>
  </entry>
  <entry>
    <title>New on CPAN: MooseX::CachingProxy</title>
    <link rel="alternate" href="http://ericjohnson.posterous.com/new-on-cpan-moosexcachingproxy" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Last week I released MooseX::CachingProxy to CPAN.

Its a small module that intercepts requests from your LWP based
application. Those requests are relayed on to the intended server unless
they already exist in the cache.

To toggle on and off the caching proxy, MooseX::CachingProxy provides the
attribute ‘caching_proxy’. Here is a quick demo:

package MyApp;
use Moose;
use WWW::Mechanize; # or any LWP based library
with 'MooseX::CachingProxy';

sub url { 'http://example.com' } # required by MooseX::CachingProxy

sub download { 
    my $self = shift;
    $self-&gt;start_caching_proxy;
    return WWW::Mechanize-&gt;new()-&gt;get($self-&gt;url . '/foo'); 
}

Under the covers, its a tiny Plack application that mashes up
Plack::Middleware::Cache and Plack::App::Proxy.

Permalink | Leave a comment »</div>
    </summary>
    <content type="html">
        &lt;p&gt;
	&lt;p&gt;Last week I released &lt;a href="https://metacpan.org/module/MooseX::CachingProxy"&gt;MooseX::CachingProxy&lt;/a&gt; to CPAN.&lt;/p&gt;

&lt;p&gt;Its a small module that intercepts requests from your LWP based application.
Those requests are relayed on to the intended server unless they already exist
in the cache.&lt;/p&gt;

&lt;p&gt;To toggle on and off the caching proxy, MooseX::CachingProxy provides the
attribute &amp;lsquo;caching_proxy&amp;rsquo;.  Here is a quick demo:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;package MyApp;
use Moose;
use WWW::Mechanize; # or any LWP based library
with 'MooseX::CachingProxy';

sub url { 'http://example.com' } # required by MooseX::CachingProxy

sub download { 
    my $self = shift;
    $self-&amp;gt;start_caching_proxy;
    return WWW::Mechanize-&amp;gt;new()-&amp;gt;get($self-&amp;gt;url . '/foo'); 
}&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Under the covers, its a tiny Plack application that mashes up
&lt;a href="https://metacpan.org/module/Plack::Middleware::Cache"&gt;Plack::Middleware::Cache&lt;/a&gt; and &lt;a href="https://metacpan.org/module/Plack::App::Proxy"&gt;Plack::App::Proxy&lt;/a&gt;.&lt;/p&gt;
	
&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ericjohnson.posterous.com/new-on-cpan-moosexcachingproxy"&gt;Permalink&lt;/a&gt; 

	| &lt;a href="http://ericjohnson.posterous.com/new-on-cpan-moosexcachingproxy#comment"&gt;Leave a comment&amp;nbsp;&amp;nbsp;&amp;raquo;&lt;/a&gt;

&lt;/p&gt;
      </content>
    <published>2012-05-10T13:42:00-07:00</published>
    <updated>2012-05-10T13:42:00-07:00</updated>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006:http://ericjohnson.posterous.com/new-on-cpan-moosexcachingproxy</id>
  </entry>
  <entry>
    <title>Announcing: PerlGSL - A Collection of Perlish Interfaces to the Gnu Scientific Library</title>
    <link rel="alternate" href="http://blogs.perl.org/users/joel_berger/2012/05/announcing-perlgsl---a-collection-of-perlish-interfaces-to-the-gnu-scientific-library.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">With this post I am happy to announce the release of my new distribution:
PerlGSL. This accompanies several other releases I’ve made in the past
few days, I’ll get to those in a moment.

A few days ago I asked what I should call my new multidimensional
integration module. The discussion centered on whether it was more
important that it required the GSL library, or whether it was a set of
bindings for the GSL (was that set complete)? Was it a dist in its own
right needing a toplevel name, or that it was mathematical and should be
under Math::?

After discussion and reflection, I have decided that I wanted a toplevel
namespce for this project, mostly because the need to satisfy the
external dependency on the GSL separates these modules from others. To
make it worthy of that honor, I have made it into a dist in its own
right, not unlike other named dists like Mojolicious or Catalyst, though
more modular.

Unlike those projects I am not reserving the entire namespace for myself;
I want people to contribute to the PerlGSL namespace. Is it a set of
bindings to the GSL? No, but close. I’m calling the namespace a
‘collection of interfaces’. Can there can be more than one interface to
the same library? I’m OK with that. Does any need to span an entire
library? No. Can a library pull several functions from different places
to create one useful Perl module? By all means!

So what does the dist named PerlGSL do? First it serves to define the
namespace. Second, if you install it, it will install what I am calling
the “standard modules”. So far I am the only author of these “standard”
modules, but I would love to add yours, though I reserve the right no to.
I want the individual modules to live on their own, but be installable
together; a modular, bottom-up collection, but one that can be installed
together for convenience. PDL, for example, is a great dist, but it’s
huge and mostly monolithic; I can’t just install what I need. I hope that
PerlGSL finds a nice balance between monolithic and separate dists.

Ok on to the technical stuff. So far I have uploaded two new modules, and
rechristened another. The new ones are PerlGSL::Integration::SingleDim
and PerlGSL::Integration::MultiDim, I think their names give away their
tasks :-). I have rechristened Math::GSLx::ODEIV2 as PerlGSL::DiffEq.
These are all part of the “standard” modules, though you only get
PerlGSL::DiffEq if you have GSL &gt;= 1.15. I have also released a new
version of Math::GSLx::ODEIV2 which announces its deprecation, though it
does still provide the ode_solver function via PerlGSL::DiffEq for now.

I hope to add more functionality as I need them. I hope you might do the
same. The GSL is too big to ask one person to wrap it all; very few
people will ever need all of it. It is really good software though, and
it works really well with Perl. I hope you enjoy it.

(Sorry, this has been a bit stream of consciousness, I have been working
on this a little too much in the past few days to compose something
concise it would seem.)</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>With this post I am happy to announce the release of my new distribution: <a href="http://p3rl.org/PerlGSL"><code>PerlGSL</code></a>. This accompanies several other releases I’ve made in the past few days, I’ll get to those in a moment.</p>

<p>A few days ago I <a href="http://blogs.perl.org/users/joel_berger/2012/05/on-cpan-namespaces-urban-namespace-planning.html">asked</a> what I should call my new multidimensional integration module. The discussion centered on whether it was more important that it required the GSL library, or whether it was a set of bindings for the GSL (was that set complete)? Was it a dist in its own right needing a toplevel name, or that it was mathematical and should be under <code>Math::</code>? </p>

<p>After discussion and reflection, I have decided that I wanted a toplevel namespce for this project, mostly because the need to satisfy the external dependency on the GSL separates these modules from others. To make it worthy of that honor, I have made it into a dist in its own right, not unlike other named dists like Mojolicious or Catalyst, though more modular.</p>

<p>Unlike those projects I am not reserving the entire namespace for myself; I want people to contribute to the <code>PerlGSL</code> namespace. Is it a set of bindings to the GSL? No, but close. I’m calling the namespace a ‘collection of interfaces’. Can there can be more than one interface to the same library? I’m OK with that. Does any need to span an entire library? No. Can a library pull several functions from different places to create one useful Perl module? By all means!</p>

<p>So what does the dist named <code>PerlGSL</code> do? First it serves to define the namespace. Second, if you install it, it will install what I am calling the “standard modules”. So far I am the only author of these “standard” modules, but I would love to add yours, though I reserve the right no to. I want the individual modules to live on their own, but be installable together; a modular, bottom-up collection, but one that can be installed together for convenience. <a href="http://pdl.perl.org"><code>PDL</code></a>, for example, is a great dist, but it’s huge and mostly monolithic; I can’t just install what I need. I hope that <code>PerlGSL</code> finds a nice balance between monolithic and separate dists.</p>

<p>Ok on to the technical stuff. So far I have uploaded two new modules, and rechristened another. The new ones are <a href="http://p3rl.org/PerlGSL::Integration::SingleDim"><code>PerlGSL::Integration::SingleDim</code></a> and <a href="http://p3rl.org/PerlGSL::Integration::MultiDim"><code>PerlGSL::Integration::MultiDim</code></a>, I think their names give away their tasks :-). I have rechristened <code>Math::GSLx::ODEIV2</code> as <a href="http://p3rl.org/PerlGSL::DiffEq"><code>PerlGSL::DiffEq</code></a>. These are all part of the “standard” modules, though you only get <code>PerlGSL::DiffEq</code> if you have GSL &gt;= 1.15. I have also released a new version of <code>Math::GSLx::ODEIV2</code> which announces its deprecation, though it does still provide the <code>ode_solver</code> function via <code>PerlGSL::DiffEq</code> for now.</p>

<p>I hope to add more functionality as I need them. I hope you might do the same. The GSL is too big to ask one person to wrap it all; very few people will ever need all of it. It is really good software though, and it works really well with Perl. I hope you enjoy it.</p>

<p>(Sorry, this has been a bit stream of consciousness, I have been working on this a little too much in the past few days to compose something concise it would seem.)</p>

        

    </div>
    </content>
    <category term="Announcing Science/Math"/>
    <published>2012-05-10T16:19:43Z</published>
    <updated>2012-05-10T16:19:43Z</updated>
    <author>
      <name>Joel Berger</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:blogs.perl.org,2012:/users/joel_berger//1022.3227</id>
  </entry>
  <entry>
    <title>Perl Unicode Cookbook: Match Unicode Linebreak Sequence</title>
    <link rel="alternate" href="http://www.perl.com/pub/2012/05/perlunicook-match-unicode-linebreak-sequence.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Editor's note: Perl guru Tom Christiansen created and maintains a list of
44 recipes for working with Unicode in Perl 5. Perl.com is pleased to
serialize this list over the coming weeks.


℞ 22: Match Unicode linebreak sequence in regex
-----------------------------------------------

Unicode defines several characters as providing vertical whitespace, like
the carriage return or newline characters. Unicode also gathers several
characters under the banner of a linebreak sequence. A Unicode linebreak
matches the two-character CRLF grapheme or any of the seven vertical
whitespace characters.

As documented in perldoc perlrebackslash, the \R regex backslash sequence
matches any Unicode linebreak sequence. (Similarly, the \v sequence
matches any single character of vertical whitespace.)

This is useful for dealing with textﬁles coming from diﬀerent operating
systems:

 s/\R/\n/g;  # normalize all linebreaks to \n</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>Editor's note:</em> Perl guru <a href="http://training.perl.com/">Tom Christiansen</a> created and maintains a list of 44 recipes for working with Unicode in Perl 5. Perl.com is pleased to serialize this list over the coming weeks.</p>

<h2 id="Match-Unicode-linebreak-sequence-in-regex">℞ 22: Match Unicode linebreak sequence in regex</h2>

<p>Unicode defines several characters as providing vertical whitespace, like
the carriage return or newline characters. Unicode also gathers several
characters under the banner of a <em>linebreak sequence</em>. A Unicode
linebreak matches the two-character <small>CRLF</small> grapheme or any of
the seven vertical whitespace characters.</p>

<p>As documented in <a href="http://perldoc.perl.org/perlrebackslash.html">perldoc
perlrebackslash</a>, the <code>\R</code> regex backslash sequence matches any
Unicode linebreak sequence. (Similarly, the <code>\v</code> sequence matches
any single character of vertical whitespace.)</p>

<p>This is useful for dealing with textﬁles coming from diﬀerent operating
systems:</p>

<pre><code> s/\R/\n/g;  # normalize all linebreaks to \n</code></pre>

        
    </div>
    </content>
    <published>2012-05-10T13:00:01Z</published>
    <updated>2012-05-10T13:00:01Z</updated>
    <author>
      <name>Tom Christiansen</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.perl.com,2012:/pub//2.2022</id>
  </entry>
  <entry>
    <title>Write the Wrong Code First</title>
    <link rel="alternate" href="http://www.modernperlbooks.com/mt/2012/05/write-the-wrong-code-first.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">I rewrite code often.

If I were a better programmer, designer, or businessman, I would rewrite
my code much less frequently—but I get things wrong about as often as I
get them right. Even with years of practical experience, software's still
too difficult to predict with any degree of accuracy.

As a case in point, I've been revising some financial software in the
past week. In reviewing the calculations, I found a way to simplify them
dramatically. Even better, these simplifications allow me to simplify the
interface and user experience.

That means rewriting a lot of code. That means throwing out code and
revising the storage model and making a lot of changes.

I'm fortunate to have a good test suite that runs in 15 to 20 seconds and
lets me know that everything I most need to work continues to work.
That's a lot of confidence. People who like to talk about test-driven
development and refactoring tout this as one of the benefits of
well-tested software: you can refactor with confidence.

I'm not refactoring. I'm throwing away parts of this application and
adding others. I'm changing how it behaves. Even though my test suite
helps, that's not refactoring.

As part of this project, I've added an SVG graph to a class of web pages.
I started by creating the SVG in Inkscape. Then I exported it as plain
SVG. Then I made a template for that SVG to include from the page
template.

That was still the example SVG with sample data, still the proof of
concept.

I then extracted one piece of hard-coded data and made it a templated
value. One. Everything still worked. Then I extracted the second piece of
data and so on.

It's one step at a time. It's one change at a time. I'm using Git, so I
could even commit after every single change, no matter that it's a few
characters or even merely changing the color of a bar in the graph. I can
work in steps as small and discrete as possible, and then squash them
into one big commit or rewrite them into functional units, or do whatever
I want with them.

That's the same principle behind test-driven development (or test-driven
design or even behavior-driven development, if you need to hang a new
name on the same idea). Do one thing at a time. Make your code do a
little more of what it needs to do. Prove that it all hangs together,
that it all works, that it does what you intended.

Then clean up a little bit. That's refactoring, in your code and in your
tests. That's rebasing in Git.

Sure, I wish I could know exactly what I needed to write from the start.
I wish sometimes that programming were mere transcription of the voice of
an ephemeral muse (though I find it difficult to imagine a muse dictating
Perl or JavaScript or Haskell or J aloud). I wish I were the Beethoven of
programming (without the mercurial temperament and the hearing loss).

Usually I don't get things right from the start. Fortunately, a little
discipline and the willingness to work in small steps, to erect and
replace the scaffolding as I go, and I usually get a lot closer to the
right code than if I guessed.

Maybe that means I've thrown out more code than I've written. (It's
satisfying to delete unused code, after all.) Maybe any project which
starts as a proof of concept, then has to pivot in other directions to do
what it's always needed to do always becomes a Ship of Theseus.

I'm okay with that. It's more important to me to create something useful
and then make it right than to wait on getting it right before other
people can find value in it. I may never write the right code from the
start, but I believe I can make almost-right code much, much more right,
with discipline and care and feedback.</div>
    </summary>
    <content type="html">
        &lt;p&gt;I rewrite code often.&lt;/p&gt;

&lt;p&gt;If I were a better programmer, designer, or businessman, I would rewrite my
code much less frequently&amp;mdash;but I get things wrong about as often as I get
them right. Even with years of practical experience, software's still too
difficult to predict with any degree of accuracy.&lt;/p&gt;

&lt;p&gt;As a case in point, I've been revising some financial software in the past
week. In reviewing the calculations, I found a way to simplify them
dramatically.  Even better, these simplifications allow me to simplify the
interface and user experience.&lt;/p&gt;

&lt;p&gt;That means rewriting a lot of code. That means throwing out code and
revising the storage model and making a lot of changes.&lt;/p&gt;

&lt;p&gt;I'm fortunate to have a good test suite that runs in 15 to 20 seconds and
lets me know that everything I most need to work continues to work. That's a
lot of confidence. People who like to talk about test-driven development and
refactoring tout this as one of the benefits of well-tested software: you can
refactor with confidence.&lt;/p&gt;

&lt;p&gt;I'm not refactoring. I'm throwing away parts of this application and adding
others. I'm changing how it behaves. Even though my test suite helps, that's
not refactoring.&lt;/p&gt;

&lt;p&gt;As part of this project, I've added an SVG graph to a class of web pages. I
started by creating the SVG in Inkscape. Then I exported it as plain SVG. Then
I made a template for that SVG to include from the page template.&lt;/p&gt;

&lt;p&gt;That was still the example SVG with sample data, still the proof of
concept.&lt;/p&gt;

&lt;p&gt;I then extracted one piece of hard-coded data and made it a templated value.
One. Everything still worked. Then I extracted the second piece of data and so
on.&lt;/p&gt;

&lt;p&gt;It's one step at a time. It's one change at a time. I'm using Git, so I
could even commit after every single change, no matter that it's a few
characters or even merely changing the color of a bar in the graph. I can work
in steps as small and discrete as possible, and then squash them into one big
commit or rewrite them into functional units, or do whatever I want with
them.&lt;/p&gt;

&lt;p&gt;That's the same principle behind test-driven development (or test-driven
design or even behavior-driven development, if you need to hang a new name on
the same idea). Do one thing at a time. Make your code do a little more of what
it needs to do. Prove that it all hangs together, that it all works, that it
does what you intended.&lt;/p&gt;

&lt;p&gt;Then clean up a little bit. That's refactoring, in your code and in your
tests. That's rebasing in Git.&lt;/p&gt;

&lt;p&gt;Sure, I wish I could know exactly what I needed to write from the start. I
wish sometimes that programming were mere transcription of the voice of an
ephemeral muse (though I find it difficult to imagine a muse dictating Perl or
JavaScript or Haskell or J aloud). I wish I were the Beethoven of programming
(without the mercurial temperament and the hearing loss).&lt;/p&gt;

&lt;p&gt;Usually I don't get things right from the start. Fortunately, a little
discipline and the willingness to work in small steps, to erect and replace the
scaffolding as I go, and I usually get a lot closer to the right code than
if I guessed.&lt;/p&gt;

&lt;p&gt;Maybe that means I've thrown out more code than I've written. (It's satisfying to delete unused code, after all.) Maybe any project which starts as a proof of concept, then has to pivot in other directions to do what it's always needed to do always becomes a &lt;a href="http://faculty.washington.edu/smcohen/320/theseus.html"&gt;Ship of Theseus&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'm okay with that. It's more important to me to create something useful and
then make it right than to wait on getting it right before other people can
find value in it. I may never write the right code from the start, but I
believe I can make almost-right code much, much more right, with discipline and
care and feedback.&lt;/p&gt;
        
    </content>
    <category term="software development"/>
    <published>2012-05-09T18:37:54Z</published>
    <updated>2012-05-09T18:37:54Z</updated>
    <author>
      <name>chromatic</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.modernperlbooks.com,2012:/mt//1.447</id>
  </entry>
  <entry>
    <title>Perl Unicode Cookbook: Case-insensitive Comparisons</title>
    <link rel="alternate" href="http://www.perl.com/pub/2012/05/perlunicook-case-insensitive-comparisons.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Editor's note: Perl guru Tom Christiansen created and maintains a list of
44 recipes for working with Unicode in Perl 5. Perl.com is pleased to
serialize this list over the coming weeks.


℞ 21: Unicode case-insensitive comparisons
------------------------------------------

Unicode is more than an expanded character set. Unicode is a set of rules
about how characters behave and a set of properties about each character.

Comparing strings for equivalence often requires normalizing them to a
standard form. That normalized form often requires that all characters be
in a specific case. ℞ 20: Unicode casing demonstrated that converting
between upper- and lower-case Unicode characters is more complicated than
simply mapping [A-Z] to [a-z]. (Remember also that many characters have a
title case form!)

The proper solution for normalized comparisons is to perform casefolding
instead of mapping a subset of some characters to another. Perl 5.16
added a new feature fc(), or "foldcase", to perform Unicode casefolding
as the /i pattern modiﬁer has always provided. This feature is available
for other Perls thanks to the CPAN module Unicode::CaseFold:

 use feature "fc"; # fc() function is from v5.16
 # OR
 use Unicode::CaseFold;

 # sort case-insensitively
 my @sorted = sort { fc($a) cmp fc($b) } @list;

 # both are true:
 fc("tschüß")  eq fc("TSCHÜSS")
 fc("Σίσυφος") eq fc("ΣΊΣΥΦΟΣ")

Fold cases properly goes into more detail about case folding in Perl.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>Editor's note:</em> Perl guru <a href="http://training.perl.com/">Tom Christiansen</a> created and maintains a list of 44 recipes for working with Unicode in Perl 5. Perl.com is pleased to serialize this list over the coming weeks.</p>

<h2 id="Unicode-case-insensitive-comparisons">℞ 21: Unicode case-insensitive comparisons</h2>

<p>Unicode is more than an expanded character set. Unicode is a set of rules
about how characters behave and a set of properties about each character.</p>

<p>Comparing strings for equivalence often requires normalizing them to a
standard form. That normalized form often requires that all characters be in a
specific case. <a href="http://www.perl.com/pub/2012/05/perl-unicook-unicode-casing.html">℞ 20:
Unicode casing</a> demonstrated that converting between upper- and lower-case
Unicode characters is more complicated than simply mapping <code>[A-Z]</code>
to <code>[a-z]</code>. (Remember also that many characters have a title case
form!)</p>

<p>The proper solution for normalized comparisons is to perform <a href="http://www.w3.org/International/wiki/Case_folding">casefolding</a>
instead of mapping a subset of some characters to another. Perl 5.16 added a
new feature <c>fc()</c>, or "foldcase", to perform Unicode casefolding as the
<code>/i</code> pattern modiﬁer has always provided. This feature is available
for other Perls thanks to the <small>CPAN</small> module <a href="http://search.cpan.org/perldoc?Unicode::CaseFold"><code>Unicode::CaseFold</code></a>:</p>

<pre><code> use feature "fc"; # fc() function is from v5.16
 # OR
 use Unicode::CaseFold;

 # sort case-insensitively
 my @sorted = sort { fc($a) cmp fc($b) } @list;

 # both are true:
 fc("tschüß")  eq fc("TSCHÜSS")
 fc("Σίσυφος") eq fc("ΣΊΣΥΦΟΣ")</code></pre>

<p><a href="http://www.effectiveperlprogramming.com/blog/1507">Fold cases properly</a> goes into more detail about case folding in Perl.</p>

        
    </div>
    </content>
    <published>2012-05-09T13:00:01Z</published>
    <updated>2012-05-09T13:00:01Z</updated>
    <author>
      <name>Tom Christiansen</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.perl.com,2012:/pub//2.2020</id>
  </entry>
  <entry>
    <title>Perl Unicode Cookbook: Unicode Casing</title>
    <link rel="alternate" href="http://www.perl.com/pub/2012/05/perl-unicook-unicode-casing.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Editor's note: Perl guru Tom Christiansen created and maintains a list of
44 recipes for working with Unicode in Perl 5. Perl.com is pleased to
serialize this list over the coming weeks.


℞ 20: Unicode casing
--------------------

Unicode casing is very diﬀerent from ASCII casing. Some of the complexity
of Unicode comes about because Unicode characters may change dramatically
when changing from upper to lower case and back. For example, the Greek
language has two characters for the lower case sigma, depending on
whether the letter is in a medial (σ) or final (ς) position in a word.
Greek only has a single upper case sigma (Σ). (Some classical Greek texts
from the Hellenistic period use a crescent-shaped variant of the sigma
called the lunate sigma, or ϲ.)

Unicode casing is important for changing case and for performing
case-insensitive matching:

 uc("henry ⅷ")  # "HENRY Ⅷ"
 uc("tschüß")   # "TSCHÜSS"  notice ß =&gt; SS

 # both are true:
 "tschüß"  =~ /TSCHÜSS/i   # notice ß =&gt; SS
 "Σίσυφος" =~ /ΣΊΣΥΦΟΣ/i   # notice Σ,σ,ς sameness</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>Editor's note:</em> Perl guru <a href="http://training.perl.com/">Tom Christiansen</a> created and maintains a list of 44 recipes for working with Unicode in Perl 5. Perl.com is pleased to serialize this list over the coming weeks.</p>

<h2 id="Unicode-casing">℞ 20: Unicode casing</h2>

<p>Unicode casing is very diﬀerent from <small>ASCII</small> casing. Some of
the complexity of Unicode comes about because Unicode characters may change
dramatically when changing from upper to lower case and back. For example, the
Greek language has two characters for the lower case sigma, depending on
whether the letter is in a medial (σ) or final (ς) position in a word. Greek
only has a single upper case sigma (Σ). (Some classical Greek texts from the Hellenistic period use a crescent-shaped variant of the sigma called the lunate sigma, or ϲ.)</p>

<p>Unicode casing is important for changing case <em>and</em> for performing case-insensitive matching:</p>

<pre><code> uc("henry ⅷ")  # "HENRY Ⅷ"
 uc("tschüß")   # "TSCHÜSS"  notice ß =&gt; SS

 # both are true:
 "tschüß"  =~ /TSCHÜSS/i   # notice ß =&gt; SS
 "Σίσυφος" =~ /ΣΊΣΥΦΟΣ/i   # notice Σ,σ,ς sameness</code></pre>

        
    </div>
    </content>
    <published>2012-05-08T13:00:01Z</published>
    <updated>2012-05-08T13:00:01Z</updated>
    <author>
      <name>Tom Christiansen</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.perl.com,2012:/pub//2.2018</id>
  </entry>
  <entry>
    <title>NYTProf, File IO, and an Optimization Gone Awry</title>
    <link rel="alternate" href="http://www.modernperlbooks.com/mt/2012/05/nytprof-file-io-and-an-optimization-gone-awry.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">One of my projects performs a lot of web scraping. Once every n units of
time (where n can be days or weeks), a batch process fetches several web
pages and extracts information from them. It's a problem solved very
well.

I designed this system around the idea of a pipeline of related
processes, where each component is as independent and idempotent as
possible. This has positives and negatives; it's an abstraction like any
other.

I initially wrote the "fetch remote web page" and "analyze data from that
page" as a single step, because I thought "analyze" was the main goal and
"fetch" was a dependent task. I separated them a couple of weeks ago to
simplify the system: analysis now expects data to be there, while
fetching can be parallel on a single or across multiple machines.
(Testing the analysis step is also much easier because feeding in dummy
data is now trivial.)

I use the filesystem as a cache for these fetched files. That's easy to
manage. I modified the role I use to grab data for the analysis stage to
look in the cache first, then fall back to a network request. That was
easy too. The get_formatted_data_for_analysis() method looked something
like:

sub get_formatted_data_for_analysis
{
    my ($self, $type, $key) = @_;

    my $cached_path         = $self-&gt;get_cached_path( $type, $key );
    if (-e $cached_path)
    {
        my $text = read_file( $cached_path );
        return $self-&gt;formatter-&gt;format_string( $text ) if $text;
    }

    return $self-&gt;formatter-&gt;format_string( $self-&gt;fetch_by_url( $type, $key ) );
}

I thought I was done. This trivial caching layer took five minutes to
write and gave my project a lot of flexibility.

I thought this would speed up the processing stage, because I was able to
make the fetching stage embarrassingly parallel so that more than one
fetch could block on network IO simultaneously. My rough benchmark didn't
show any speed improvement, but it was fast enough, so I moved on.

On Friday I decided to profile the slowest stage of the application with
Devel::NYTProf. The slowest stage was the processing stage. I isolated it
so that it performed no network fetching. It was still slow.

One of the formatter modules used to extract data from web pages is
HTML::FormatText::Lynx. It allows me to run lynx --dump to strip out all
of the HTML and other formatting of a document. The formatter allows you
to pass in the name of a file or the contents of a file as a string.

For some reason, most of the time in the processing stage in the profile
was spent in file IO. That wasn't too surprising; these aren't all small
files and there may be thousands of them. I dug deeper.

Most of the time in the processing stage in the profile was spent in
reading the files in my method and reading files in the formatter—reading
files, even though I was passing the contents of those files to the
formatter as strings.

I poked around at a few other things, but came back to the source code of
the formatter. A comment in HTML::FormatExternal says:

  format_string() takes the easy approach of putting the string in a
  temp file and letting format_file() do the real work. The formatter
  programs can generally read stdin and write stdout, so could do that
  with select() to simultaneously write and read back.

In other words, all of the work I was doing to read in files was busy
work, duplicating what the formatter was about to do anyway. (Okay, I
stared at the code for a couple of minutes, thinking about various
approaches of rewriting it and submitting a patch or monkey patching it.
Then I turned lazier and wiser.) I rewrote my code:

sub get_formatted_data_for_analysis
{
    my ($self, $type, $key) = @_;

    my $cached_path         = $self-&gt;get_cached_path( $type, $key );
    return $self-&gt;formatter-&gt;format_file( $cached_path ) if -e $cached_path;

    return $self-&gt;formatter-&gt;format_text( $self-&gt;fetch_by_url( $type, $key ) );
}

The result was a 25% performance improvement.

Three things jumped out at me in this process. First, how nice is it to
have a working tool like NYTProf and a community that distributes source
code, so that I could examine the whole stack of my application to
isolate performance problems? Second, how interesting that an assumption
and an admitted shortcut in a dependency could have such an effect on my
own code. Third, how much more I like my new code with all of the file
handling gone; pushing that responsibility elsewhere is a nice
simplification without the performance improvement.

Perhaps the two tools I miss most from my C programming days are
Valgrind/Callgrind and KCachegrind, but NYTProf goes a long way toward
filling that gap. Besides, I'm at least 20 times more productive with a
language like Perl.</div>
    </summary>
    <content type="html">
        &lt;p&gt;One of my projects performs a lot of web scraping. Once every &lt;em&gt;n&lt;/em&gt;
units of time (where &lt;em&gt;n&lt;/em&gt; can be days or weeks), a batch process fetches
several web pages and extracts information from them. It's a problem solved
very well.&lt;/p&gt;

&lt;p&gt;I designed this system around the idea of a pipeline of related processes,
where each component is as independent and idempotent as possible. This has
positives and negatives; it's an abstraction like any other.&lt;/p&gt;

&lt;p&gt;I initially wrote the "fetch remote web page" and "analyze data from that
page" as a single step, because I thought "analyze" was the main goal and
"fetch" was a dependent task. I separated them a couple of weeks ago to
simplify the system: analysis now expects data to be there, while fetching can
be parallel on a single or across multiple machines. (Testing the analysis step
is also much easier because feeding in dummy data is now trivial.)&lt;/p&gt;

&lt;p&gt;I use the filesystem as a cache for these fetched files. That's easy to
manage. I modified the role I use to grab data for the analysis stage to look
in the cache first, then fall back to a network request. That was easy too. The
&lt;code&gt;get_formatted_data_for_analysis()&lt;/code&gt; method looked something like:&lt;p&gt;

&lt;pre&gt;&lt;code&gt;sub get_formatted_data_for_analysis
{
    my ($self, $type, $key) = @_;

    my $cached_path         = $self-&amp;gt;get_cached_path( $type, $key );
    if (-e $cached_path)
    {
        my $text = read_file( $cached_path );
        return $self-&amp;gt;formatter-&amp;gt;format_string( $text ) if $text;
    }

    return $self-&amp;gt;formatter-&amp;gt;format_string( $self-&amp;gt;fetch_by_url( $type, $key ) );
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I thought I was done. This trivial caching layer took five minutes to write and gave my project a lot of flexibility.&lt;/p&gt;

&lt;p&gt;I thought this would speed up the processing stage, because I was able to
make the fetching stage embarrassingly parallel so that more than one fetch
could block on network IO simultaneously. My rough benchmark didn't show any
speed improvement, but it was fast enough, so I moved on.&lt;/p&gt;

&lt;p&gt;On Friday I decided to profile the slowest stage of the application with &lt;a href="http://search.cpan.org/perldoc?Devel::NYTProf"&gt;Devel::NYTProf&lt;/a&gt;. The
slowest stage was the processing stage. I isolated it so that it performed no
network fetching. It was still slow.&lt;/p&gt;

&lt;p&gt;One of the formatter modules used to extract data from web pages is &lt;a href="http://search.cpan.org/perldoc?HTML::FormatText::Lynx"&gt;HTML::FormatText::Lynx&lt;/a&gt;.
It allows me to run &lt;code&gt;lynx --dump&lt;/code&gt; to strip out all of the HTML and
other formatting of a document. The formatter allows you to pass in the name of
a file or the contents of a file as a string.&lt;/p&gt;

&lt;p&gt;For some reason, most of the time in the processing stage in the profile was
spent in file IO. That wasn't too surprising; these aren't all small files and
there may be thousands of them. I dug deeper.&lt;/p&gt;

&lt;p&gt;Most of the time in the processing stage in the profile was spent in reading
the files in my method and reading files in the formatter&amp;mdash;reading files,
even though I was passing the contents of those files to the formatter as
strings.&lt;/p&gt;

&lt;p&gt;I poked around at a few other things, but came back to the source code of
the formatter. A comment in &lt;a href="http://search.cpan.org/perldoc?HTML::FormatExternal"&gt;HTML::FormatExternal&lt;/a&gt;
says:

&lt;blockquote&gt;&lt;code&gt;format_string()&lt;/code&gt; takes the easy approach of putting the
string in a temp file and letting &lt;code&gt;format_file()&lt;/code&gt; do the real work.
The formatter programs can generally read stdin and write stdout, so could do
that with &lt;code&gt;select()&lt;/code&gt; to simultaneously write and read
back.&lt;/blockquote&gt;

&lt;p&gt;In other words, all of the work I was doing to read in files was busy work,
duplicating what the formatter was about to do anyway. (Okay, I stared at the
code for a couple of minutes, thinking about various approaches of rewriting it
and submitting a patch or monkey patching it. Then I turned lazier and wiser.)
I rewrote my code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sub get_formatted_data_for_analysis
{
    my ($self, $type, $key) = @_;

    my $cached_path         = $self-&amp;gt;get_cached_path( $type, $key );
    return $self-&amp;gt;formatter-&amp;gt;format_file( $cached_path ) if -e $cached_path;

    return $self-&amp;gt;formatter-&amp;gt;format_text( $self-&amp;gt;fetch_by_url( $type, $key ) );
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The result was a 25% performance improvement.&lt;/p&gt;

&lt;p&gt;Three things jumped out at me in this process. First, how nice is it to have
a working tool like NYTProf and a community that distributes source code, so
that I could examine the whole stack of my application to isolate performance
problems? Second, how interesting that an assumption and an admitted shortcut
in a dependency could have such an effect on my own code. Third, how much more
I like my new code with all of the file handling gone; pushing that
responsibility elsewhere is a nice simplification without the performance
improvement.&lt;/p&gt;

&lt;p&gt;Perhaps the two tools I miss most from my C programming days are
Valgrind/Callgrind and KCachegrind, but NYTProf goes a long way toward filling
that gap. Besides, I'm at least 20 times more productive with a language like
Perl.&lt;/p&gt;

        
    </content>
    <category term="cpan modern perl perl profiling software development"/>
    <published>2012-05-07T21:56:41Z</published>
    <updated>2012-05-07T21:56:41Z</updated>
    <author>
      <name>chromatic</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:www.modernperlbooks.com,2012:/mt//1.446</id>
  </entry>
  <entry>
    <title>Floating Point Rounding Errors</title>
    <link rel="alternate" href="http://blogs.perl.org/users/ovid/2012/05/floating-point-rounding-errors.html" type="text/html"/>
    <summary type="text">In Chapter 3 of my book, I mentioned offhand that sometimes you expect
the number 5, but you get 4.99999999998 instead. I sort of punted on the
explanation because it seemed to be a touch of a distraction. Naturally,
chromatic called me on that and suggested I explain a bit more. As part
of my explanation, I wrote a sample program that would print out the
fractions used to build the mantissa of a number. For example, .75 is 1/2
+ 1/4.

Here's the program:

use strict;                                                                                                                                                                    
use warnings;

my $num  = .75;
my $bits = 32;

my $accumulator = 0;
my $bitstring   = '';
my @fractions;
for ( 1 .. $bits ) {
    my $denominator = 2**$_;
    my $fraction    = 1 / $denominator;
    if ( $accumulator + $fraction &lt;= $num ) {
        push @fractions, "1/$denominator";
        $bitstring .= "1";
        $accumulator += $fraction;
    }
    else {
        $bitstring .= "0";
    }
}
my $fractions = join " + ", @fractions;
print &lt;&lt;"END";
Fractions: $fractions
Bits:      $bitstring
Result:    $accumulator
END

So running that will print:

Fractions: 1/2 + 1/4
Bits:      11000000000000000000000000000000
Result:    0.75

But using .3 for the number will print (formatted to fit the blog):

Fractions: 1/4 + 1/32 + 1/64 + 1/512 + 1/1024 + 1/8192 
  + 1/16384 + 1/131072 + 1/262144 + 1/2097152 
  + 1/4194304 + 1/33554432 + 1/67108864
  + 1/536870912 + 1/1073741824
Bits:      01001100110011001100110011001100
Result:    0.299999999813735

I think this plus my accompanying text (not reproduced here) does a
reasonable job of showing the rounding errors. Can I do better?</summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>In Chapter 3 of my book, I mentioned offhand that sometimes you expect the number 5, but you get 4.99999999998 instead. I sort of punted on the explanation because it seemed to be a touch of a distraction. Naturally, chromatic called me on that and suggested I explain a bit more. As part of my explanation, I wrote a sample program that would print out the fractions used to build the mantissa of a number. For example, .75 is 1/2 + 1/4.</p>

        <p>Here's the program:</p>

<pre><code>use strict;                                                                                                                                                                    
use warnings;

my $num  = .75;
my $bits = 32;

my $accumulator = 0;
my $bitstring   = '';
my @fractions;
for ( 1 .. $bits ) {
    my $denominator = 2**$_;
    my $fraction    = 1 / $denominator;
    if ( $accumulator + $fraction &lt;= $num ) {
        push @fractions, "1/$denominator";
        $bitstring .= "1";
        $accumulator += $fraction;
    }
    else {
        $bitstring .= "0";
    }
}
my $fractions = join " + ", @fractions;
print &lt;&lt;"END";
Fractions: $fractions
Bits:      $bitstring
Result:    $accumulator
END
</code></pre>

<p>So running that will print:</p>

<pre><code>Fractions: 1/2 + 1/4
Bits:      11000000000000000000000000000000
Result:    0.75
</code></pre>

<p>But using .3 for the number will print (formatted to fit the blog):</p>

<pre><code>Fractions: 1/4 + 1/32 + 1/64 + 1/512 + 1/1024 + 1/8192 
  + 1/16384 + 1/131072 + 1/262144 + 1/2097152 
  + 1/4194304 + 1/33554432 + 1/67108864
  + 1/536870912 + 1/1073741824
Bits:      01001100110011001100110011001100
Result:    0.299999999813735
</code></pre>

<p>I think this plus my accompanying text (not reproduced here) does a reasonable job of showing the rounding errors. Can I do better?</p>

    </div>
    </content>
    <category term="book floating point perl"/>
    <published>2012-05-07T19:20:38Z</published>
    <updated>2012-05-07T19:20:38Z</updated>
    <author>
      <name>Ovid</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:blogs.perl.org,2012:/users/ovid//11.3211</id>
  </entry>
  <entry>
    <title>On CPAN Namespaces: Urban Namespace Planning</title>
    <link rel="alternate" href="http://blogs.perl.org/users/joel_berger/2012/05/on-cpan-namespaces-urban-namespace-planning.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">I’m having a bit of a conundrum over where to put my next GSL-based
module. First some background.

I’m already the author of a GSL-based module (see my first rant), the
horribly named Math::GSLx::ODEIV2. This name reflects the same odd
namespacing conundrum that I find myself in again, as well as the
sub-library name odeiv2.c/h.

Duke Leto has already essentially taken the whole Math::GSL namespace by
brute-force SWIG-ing the entire library. Much of this work is not fully
implemented, but still parked. Further, since the namespace is already
fairly crowded, its next to impossible to tell which parts are his and
which would be anyone else’s. So lets call that out of the running. Note
that I’m not complaining about his efforts, but it makes choosing a name
harder.

I released my first module which uses GSL under the namespace Math::GSLx,
but this is also less than desirable since it seems to be related to
Math::GSL which it isn’t (at least not in the way that MooseX is related
to Moose). Its also hard to type and hard to search for.

This leave me thinking about starting a new toplevel, which I do not
undertake lightly. My two concepts are the simple GSL and the more namey
PerlGSL. I say namey since toplevels with names like Mojolicious are not
contentious since they represent more of a concept than an implementation
detail (like Net::).

To be distinct from Math::GSL I would encourage users of PerlGSL to

  1. Make their interfaces Perlish rather than the utilitarian output the
    SWIG may produce

  2. Give their module a name that is descriptive without squatting on
    the sub-library name or other implemenations

In this way if two different authors want to provide an interface to
GSL’s Monte Carlo multidimensional integrator, one might be
PerlGSL::Integration::MultiDim (since there are a number of 1D
integrators to be considered) and another might be
PerlGSL::Integration::NDim.

Once I settle on a toplevel, I expect that I will “release” a namespace
decriptor module (not unlike Alien) describing this for future users. It
might also eventually pull in the GSL library via Alien::GSL once my
Alien::Base work permits. From there I would release
PerlGSL::Integration::MultiDim and rechristen Math::GSLx::ODEIV2 as
PerlGSL::DiffEq (assuming the toplevel PerlGSL).

Anyway, I’m interested in your comments, so please let me know!</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>I’m having a bit of a conundrum over where to put my next GSL-based module. First some background.</p>

<p>I’m already the author of a GSL-based module (see my <a href="http://blogs.perl.org/users/joel_berger/2012/01/on-cpan-namespaces.html">first rant</a>), the horribly named <a href="http://p3rl.org/Math::GSLx::ODEIV2"><code>Math::GSLx::ODEIV2</code></a>. This name reflects the same odd namespacing conundrum that I find myself in again, as well as the sub-library name <code>odeiv2.c/h</code>.</p>

<p>Duke Leto has already essentially taken the whole <a href="http://p3rl.org/Math::GSL"><code>Math::GSL</code></a> namespace by brute-force SWIG-ing the entire library. Much of this work is <a href="https://metacpan.org/module/Math::GSL::Monte">not fully implemented</a>, but still parked. Further, since the namespace is already fairly crowded, its next to impossible to tell which parts are his and which would be anyone else’s. So lets call that out of the running. Note that I’m not complaining about his efforts, but it makes choosing a name harder.</p>

<p>I released my first module which uses GSL under the namespace Math::GSLx, but this is also less than desirable since it seems to be related to Math::GSL which it isn’t (at least not in the way that MooseX is related to Moose). Its also hard to type and hard to search for.</p>

<p>This leave me thinking about starting a new toplevel, which I do not undertake lightly. My two concepts are the simple <code>GSL</code> and the more namey <code>PerlGSL</code>. I say namey since toplevels with names like <code>Mojolicious</code> are not contentious since they represent more of a concept than an implementation detail (like <code>Net::</code>). </p>

<p>To be distinct from <code>Math::GSL</code> I would encourage users of <code>PerlGSL</code> to </p>

<ol>
<li>Make their interfaces Perlish rather than the utilitarian output the SWIG may produce</li>
<li>Give their module a name that is descriptive without squatting on the sub-library name or other implemenations</li>
</ol>

<p>In this way if two different authors want to provide an interface to GSL’s Monte Carlo multidimensional integrator, one might be <code>PerlGSL::Integration::MultiDim</code> (since there are a number of 1D integrators to be considered) and another might be <code>PerlGSL::Integration::NDim</code>.</p>

<p>Once I settle on a toplevel, I expect that I will “release” a namespace decriptor module (not unlike <a href="http://p3rl.org/Alien"><code>Alien</code></a>) describing this for future users. It might also eventually pull in the GSL library via <a href="http://p3rl.org/Alien::GSL"><code>Alien::GSL</code></a> once my <a href="https://github.com/jberger/Alien-Base"><code>Alien::Base</code></a> work permits. From there I would release <code>PerlGSL::Integration::MultiDim</code> and rechristen <code>Math::GSLx::ODEIV2</code> as <code>PerlGSL::DiffEq</code> (assuming the toplevel <code>PerlGSL</code>). </p>

<p>Anyway, I’m interested in your comments, so please let me know!</p>

        

    </div>
    </content>
    <category term="CPAN Love Feedback Wanted"/>
    <published>2012-05-07T19:14:50Z</published>
    <updated>2012-05-07T19:14:50Z</updated>
    <author>
      <name>Joel Berger</name>
    </author>
    <id>tag:perlsphere.net,2006:tag:blogs.perl.org,2012:/users/joel_berger//1022.3210</id>
  </entry>
  <entry>
    <title> Module pre-requisites analyser </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/cpandeps-release" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/cpandeps-release</id>
  </entry>
  <entry>
    <title> CPANdeps </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/cpandeps" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/cpandeps</id>
  </entry>
  <entry>
    <title> Perl isn't dieing </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/perl-isnt-dying" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/perl-isnt-dying</id>
  </entry>
  <entry>
    <title> YAPC::Europe 2007 report: day 3 </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/yapc-europe-2007-day-3" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/yapc-europe-2007-day-3</id>
  </entry>
  <entry>
    <title> Devel::CheckLib can now check libraries' contents </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/Devel-CheckLib-functions" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/Devel-CheckLib-functions</id>
  </entry>
  <entry>
    <title>Upcoming Perl 6 Hackathon in Oslo, Norway</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/2012-upcoming-p6-hackathon.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">The Oslo Perl Mongers are inviting to the Perl 6 Patterns Hackathon in
Oslo in one month, and I very much look forward to being there.

Hackathons can be quite fun and productive if many programmers focus on
the same goal. So to make the hackathon a success, I'm willing to work on
whatever we decide to set as our goal(s).

One topic that is dear to me, and that is approachable by a horde of
programmers (and guided by one or two Rakudo core hackers) is bringing
database access into a usable state.

With muchly improved support for calling C functions and NativeCall.pm we
should have enough infrastructure for access mysql, postgres and SQLite
databases. MiniDBI aims to provide some basic convenience, but currently
only the mysql driver partially works.

I believe that with concentrated effort, MiniDBI and the rest of the
infrastructure can be improved to the point that it is usable, and other
modules can start to rely on it. Databases usable in Perl 6, doesn't that
sound good?

I'll see what kind of feedback I get on this idea, and if it's positive,
I'll follow up with instructions on how to install the prerequisites for
hacking on MiniDBI and its drivers.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">

<p>The Oslo Perl Mongers are <a href="https://gist.github.com/1711730">inviting to the Perl 6 Patterns
Hackathon in Oslo</a> in one month, and I very much look forward to being
there.</p>

<p>Hackathons can be quite fun and productive if many programmers focus on the
same goal. So to make the hackathon a success, I'm willing to work on whatever
we decide to set as our goal(s).</p>

<p>One topic that is dear to me, and that is approachable by a horde of
programmers (and guided by one or two Rakudo core hackers) is bringing
database access into a usable state.</p>

<p>With <a href="http://6guts.wordpress.com/2012/01/29/this-months-rakudo-star-release-and-whats-coming-next/">muchly
    improved support for calling C functions</a> and <a href="https://github.com/jnthn/zavolaj/">NativeCall.pm</a> we should have
enough infrastructure for access mysql, postgres and SQLite databases. <a href="https://github.com/mberends/MiniDBI">MiniDBI</a> aims to provide some
basic convenience, but currently only the mysql driver partially works.</p>

<p>I believe that with concentrated effort, MiniDBI and the rest of the
infrastructure can be improved to the point that it is usable, and other
modules can start to rely on it. Databases usable in Perl 6, doesn't that
sound good?</p>

<p>I'll see what kind of feedback I get on this idea, and if it's positive,
I'll follow up with instructions on how to install the prerequisites for
hacking on MiniDBI and its drivers.</p>


</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/2012-upcoming-p6-hackathon.html</id>
  </entry>
  <entry>
    <title> I Love Github </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/i-love-github" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/i-love-github</id>
  </entry>
  <entry>
    <title> Palm Treo call db module </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/palm-treophonecalldb-first-release" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/palm-treophonecalldb-first-release</id>
  </entry>
  <entry>
    <title>Current State of Exceptions in Rakudo and Perl 6</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/2011-02-exceptions.html" type="text/html"/>
    <summary type="text">It's been a while since my last update on my grant work on exceptions for
Perl 6 and Rakudo, and I can report lots of progress.

The work on Rakudo's exception system made me realize that we conflated
two concepts in the base exception type: on the one hand the
infrastructure for reporting errors and backtraces, and on the other hand
holding some sort of error message as an attribute.

As a result, we now have a base class called Exception from which all
exception types must inherit. When a non-Exception object is passed to
die(), it is wrapped in an object of class X::AdHoc. Other error classes
can decide to generate the error message without having an attribute for
it (for example hard-coded in a method).

Typed exceptions are now thrown not only from the setting, but also from
the compiler itself, namely the grammar and the action methods. In fact
the majority of errors from these two parts of the compiler are now
handled with dedicated exception types.

The most user-visible change is a new and improved backtrace printer,
which produces usually much shorter and more readable backtraces. The old
one is still available on demand. Consider the program

sub f {
    g() for 1..10;}sub g { die 'OH NOEZ' }
f;

The old backtrace printer produced:

OH NOEZ
  in sub g at /home/moritz/p6/rakudo/ex.pl:4
  in block &lt;anon&gt; at /home/moritz/p6/rakudo/ex.pl:2
  in method reify at src/gen/CORE.setting:4471
  in method reify at src/gen/CORE.setting:4376
  in method reify at src/gen/CORE.setting:4376
  in method gimme at src/gen/CORE.setting:4740
  in method eager at src/gen/CORE.setting:4715
  in method eager at src/gen/CORE.setting:1028
  in sub eager at src/gen/CORE.setting:5000
  in sub f at /home/moritz/p6/rakudo/ex.pl:2
  in block &lt;anon&gt; at /home/moritz/p6/rakudo/ex.pl:5
  in &lt;anon&gt; at /home/moritz/p6/rakudo/ex.pl:1

Where the eager, gimme and reify methods come from the 'for' lop, which
is compiled to the equivalent of eager (1..10).map: { g() }.

The new backtrace printer produces

OH NOEZ
  in sub g at ex.pl:4
  in sub f at ex.pl:2
  in block &lt;anon&gt; at ex.pl:5

It is also a special pleasure to report that after a walk through a
change to throw a typed exception, we've received a pull request by a new
developer which also changes an exception from X::AdHoc to a dedicated
type.</summary>
    <content type="html">
&lt;p&gt;It's been a while since my last update on my grant work on exceptions for
Perl 6 and Rakudo, and I can report lots of progress.&lt;/p&gt;

&lt;p&gt;The work on Rakudo's exception system made me realize that we conflated two
concepts in the base exception type: on the one hand the infrastructure for
reporting errors and backtraces, and on the other hand holding some sort of
error message as an attribute.&lt;/p&gt;

&lt;p&gt;As a result, we now have a base class called &lt;code&gt;Exception&lt;/code&gt; from
which all exception types must inherit. When a non-&lt;code&gt;Exception&lt;/code&gt;
object is passed to &lt;code&gt;die()&lt;/code&gt;, it is wrapped in an object of class
&lt;code&gt;X::AdHoc&lt;/code&gt;. Other error classes can decide to generate the error
message without having an attribute for it (for example hard-coded in a
method).&lt;/p&gt;

&lt;p&gt;Typed exceptions are now thrown not only from the setting, but also from
the compiler itself, namely the grammar and the action methods. In fact the
majority of errors from these two parts of the compiler are now handled with
dedicated exception types.&lt;/p&gt;


&lt;p&gt;The most user-visible change is a new and improved backtrace printer, which
produces usually much shorter and more readable backtraces. The old one is
still available on demand. Consider the program&lt;/p&gt;

&lt;pre&gt;
&lt;span class="synStatement"&gt;sub&lt;/span&gt; f {
    g() &lt;span class="synStatement"&gt;for&lt;/span&gt; &lt;span class="synConstant"&gt;1&lt;/span&gt;&lt;span class="synStatement"&gt;..&lt;/span&gt;&lt;span class="synConstant"&gt;10&lt;/span&gt;&lt;span class="synStatement"&gt;;&lt;/span&gt;
}
&lt;span class="synStatement"&gt;sub&lt;/span&gt; g { &lt;span class="synStatement"&gt;die&lt;/span&gt; &lt;span class="synSpecial"&gt;'&lt;/span&gt;&lt;span class="synConstant"&gt;OH NOEZ&lt;/span&gt;&lt;span class="synSpecial"&gt;'&lt;/span&gt; }
f&lt;span class="synStatement"&gt;;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;The old backtrace printer produced:

&lt;pre&gt;
OH NOEZ
  in sub g at /home/moritz/p6/rakudo/ex.pl:4
  in block &amp;lt;anon&amp;gt; at /home/moritz/p6/rakudo/ex.pl:2
  in method reify at src/gen/CORE.setting:4471
  in method reify at src/gen/CORE.setting:4376
  in method reify at src/gen/CORE.setting:4376
  in method gimme at src/gen/CORE.setting:4740
  in method eager at src/gen/CORE.setting:4715
  in method eager at src/gen/CORE.setting:1028
  in sub eager at src/gen/CORE.setting:5000
  in sub f at /home/moritz/p6/rakudo/ex.pl:2
  in block &amp;lt;anon&amp;gt; at /home/moritz/p6/rakudo/ex.pl:5
  in &amp;lt;anon&amp;gt; at /home/moritz/p6/rakudo/ex.pl:1
&lt;/pre&gt;

&lt;p&gt;Where the eager, gimme and reify methods come from the 'for' lop, which is
compiled to the equivalent of &lt;code&gt;eager (1..10).map: { g() }&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The new backtrace printer produces&lt;/p&gt;

&lt;pre&gt;
OH NOEZ
  in sub g at ex.pl:4
  in sub f at ex.pl:2
  in block &amp;lt;anon&amp;gt; at ex.pl:5
&lt;/pre&gt;


&lt;p&gt;It is also a special pleasure to report that after a &lt;a href="http://irclog.perlgeek.de/perl6/2012-02-27#i_5216391"&gt;walk through a
change to throw a typed exception&lt;/a&gt;, we've received a &lt;a href="https://github.com/rakudo/rakudo/pull/59"&gt;pull request by a new
developer&lt;/a&gt; which also changes an exception from X::AdHoc to a dedicated
type.&lt;/p&gt;



</content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/2011-02-exceptions.html</id>
  </entry>
  <entry>
    <title>The Three-Fold Function of the Smart Match Operator</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/three-functions-of-smartmatch.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">In Perl 5, if you want to match a regex against a particular string, you
write $string =~ $regex.

In the design process of Perl 6, people have realized that you cannot
only match against regexes, but lots of other things can act as patterns
too: types (checking type conformance), numbers, strings, junctions
(composites of values), subroutine signatures and so on. So smart
matching was born, and it's now written as $topic ~~ $pattern. Being a
general comparison mechanism is the first function of the smart match
operator.

But behold, there were problems. One of them was the perceived need for
special syntactic forms on the right hand side of the smart match
operator to cover some cases. Those were limited and hard to implement.
There was also the fact that now we had two different ways to invoke
regexes: smart matching, and direct invocation as m/.../, which matches
against the topic variable $_. That wasn't really a problem as such, but
it was an indicator of design smell.

And that's where the second function of the smart match operator
originated: topicalization. Previously, $a ~~ $b mostly turned into a
method call, $b.ACCEPTS($a). The new idea was to set the topic variable
to $a in a small scope, which allowed many special cases to go away. It
also nicely unified with given $topic { when $matcher { ... } }, which
was already specified as being a topicalizer.

In the new model, MATCH ~~ PAT becomes something like do { $_ = MATCH;
PAT.ACCEPTS($_) } -- which means that if MATCH accesses $_, it
automatically does what the user wants.

Awesomeness reigned, and it worked out great.

Until the compiler writers actually started to implement a few more cases
of regex matching. The first thing we noticed was that if $str ~~ $regex
{ ... } behaved quite unexpectedly. What happend was that $_ got set to
$str, the match was conducted and returned a Match object. And then
called $match.ACCEPTS($str), which failed. A quick hack around that was
to modify Match.ACCEPTS to always return the invocant (ie the Match on
which it was called), but of course that was only a stop gap solution.

The reason it doesn't work for other, more involved cases of regex
invocations is that they don't fit into the "does $a match $b?" schema.
Two examples:

# :g for "global", all matches
my @matches = $str ~~ m:g/pattern/; 

if $str ~~ s/pattern/substitution/ { ... }

People expect those to work. But global matching of a regex isn't a
simple conformance check, and that is reflected in the return value: a
list. So should we special-cases smart-matching against a list, just
because we can't get global matching to work in smart-matching otherwise?
(People have also proposed to return a kind of aggregate Match object
instead of a list; that comes with the problem that Match objects aren't
lazy, but lists are. You could "solve" that with a LazyMatch type; watch
the pattern of workarounds unfold...)

A substitution is also not a simple matching operation. In Perl 5, a s///
returns the number of successful substitutions. In Perl 6, that wouldn't
work with the current setup of the smart match operator, where it would
then smart-match the string against the returned number of matches.

So to summarize, the smart match operator has three functions: comparing
values to patterns, topicalization, and conducting regex matches.

These three functions are distinct enough to start to interact in weird
ways, which limits the flexibility in choice of return values from regex
matches and substitutions.

I don't know what the best way forward is. Maybe it is to reintroduce a
dedicated operator for regex matching, which seems to be the main feature
with which topicalization interacts badly. Maybe there are other good
ideas out there. If so, I'd love to hear about them.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>In Perl 5, if you want to match a regex against a particular
string, you write <code>$string =~ $regex</code>.</p>

<p>In the design process of Perl 6, people have realized that you cannot
only match against regexes, but lots of other things can act as
patterns too: types (checking type conformance), numbers, strings,
junctions (composites of values), subroutine signatures and so on. So
<em>smart matching</em> was born, and it's now written as
<code>$topic ~~ $pattern</code>. Being a general comparison mechanism
is the first function of the smart match operator.</p>

<p>But behold, there were problems. One of them was the perceived need
for special syntactic forms on the right hand side of the smart match
operator to cover some cases. Those were limited and hard to
implement. There was also the fact that now we had two different ways
to invoke regexes: smart matching, and direct invocation as
<code>m/.../</code>, which matches against the topic variable
<code>$_</code>. That wasn't really a problem as such, but it was an
indicator of design smell.</p>

<p>And that's where the second function of the smart match operator
originated: topicalization. Previously, <code>$a ~~ $b</code> mostly
turned into a method call, <code>$b.ACCEPTS($a)</code>. The new idea
was to <a href="https://github.com/perl6/specs/commit/f2dff276c272399a92a841818842ad663d70f23b">set
the topic variable to $a in a small scope</a>, which allowed many
special cases to go away. It also nicely unified with
<code>given $topic { when $matcher  { ... } }</code>, which was
already specified as being a topicalizer.</p>

<p>In the new model, <code>MATCH ~~ PAT</code> becomes something like
<code>do { $_ = MATCH; PAT.ACCEPTS($_) }</code> -- which means that if
<code>MATCH</code> accesses <code>$_</code>, it automatically does what the
user wants.</p>

<p>Awesomeness reigned, and it worked out great.</p>

<p>Until the compiler writers actually started to implement a few more
cases of regex matching. The first thing we noticed was that
<code>if $str ~~ $regex { ... }</code> behaved quite unexpectedly.
What happend was that <code>$_</code> got set to <code>$str</code>,
the match was conducted and returned a Match object. And then called
<code>$match.ACCEPTS($str)</code>, which failed. A quick hack around
that was to modify <code>Match.ACCEPTS</code> to always return the
invocant (ie the Match on which it was called), but of course that was
only a stop gap solution.</p>

<p>The reason it doesn't work for other, more involved cases of regex
invocations is that they don't fit into the "does $a match $b?"
schema. Two examples:</p>

<pre>
# :g for "global", all matches
my @matches = $str ~~ m:g/pattern/; 

if $str ~~ s/pattern/substitution/ { ... }
</pre>

<p>People expect those to work. But global matching of a regex isn't a
simple conformance check, and that is reflected in the return value: a
list. So should we special-cases smart-matching against a list, just
because we can't get global matching to work in smart-matching
otherwise? (People have also proposed to return a kind of aggregate
Match object instead of a list; that comes with the problem that Match
objects aren't lazy, but lists are. You could "solve" that with a
LazyMatch type; watch the pattern of workarounds unfold...)</p>

<p>A substitution is also not a simple matching operation. In Perl 5,
a s/// returns the number of successful substitutions. In Perl 6, that
wouldn't work with the current setup of the smart match operator,
where it would then smart-match the string against the returned number
of matches.</p>

<p>So to summarize, the smart match operator has three functions:
comparing values to patterns, topicalization, and conducting regex
matches.</p>

<p>These three functions are distinct enough to start to interact in
weird ways, which limits the flexibility in choice of return values
from regex matches and substitutions.</p>

<p>I don't know what the best way forward is. Maybe it is to
reintroduce a dedicated operator for regex matching, which seems to be
the main feature with which topicalization interacts badly. Maybe
there are other good ideas out there. If so, I'd love to hear about
them.</p>


</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/three-functions-of-smartmatch.html</id>
  </entry>
  <entry>
    <title>Meet DBIish, a Perl 6 Database Interface</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/2012-dbiish.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">In the aftermath of the Oslo Perl 6 hackathon 2012, I have decided to
fork and rename MiniDBI. MiniDBI is intended as a compatible port of Perl
5's excellent DBI module to Perl 6. While working on the MiniDBI
backends, I noticed that I became more and more unhappy with that. Perl 6
is sufficiently different from Perl 5 to warrant different design
decisions in the database interface layer.

Meet DBIish. It started with MiniDBI's code base, but has some
substantial deviations from MiniDBI:

  * Connection information is passed by named arguments to the driver
    (instead of a single DSN string)

  * Different naming of several methods. There's not much point in having
    both fetchrow_array and fetchrow_arrayref in Rakudo. fetchrow simply
    returns an array or a list, and the caller decides what to do with
    it.

  * Backends only need to implement fetchrow and column_names, and get
    all the other fetching methods (like fetchrow-hash, fetchall-hash)
    for free.

  * Error handling from DB connection and statement handle are unified
    into a single row

The latter two changes brought quite a reduction in backend code size.

My plans for the future include experimenting with different names and
maybe totally different APIs. When a language has lazy lists, one can
simply return all rows lazily, instead of encouraging the user to fetch
the rows one by one.

Currently the Postgresql and mysql backends support basic CRUD
operations, Postgresql with proper prepared statements and placeholders.
An SQLite backend is under way, but still needs better support from our
native call interface.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">

<p>In the aftermath of the Oslo Perl 6 hackathon 2012, I have decided to fork
and rename MiniDBI. MiniDBI is intended as a compatible port of Perl 5's
excellent DBI module to Perl 6. While working on the MiniDBI backends, I
noticed that I became more and more unhappy with that. Perl 6 is sufficiently
different from Perl 5 to warrant different design decisions in the database
interface layer.</p>

<p>Meet <a href="https://github.com/perl6/DBIish/">DBIish</a>. It started with
MiniDBI's code base, but has some substantial deviations from MiniDBI:</p>

<ul>
    <li>Connection information is passed by named arguments to the driver
    (instead of a single DSN string)</li>
    <li>Different naming of several methods. There's not much point in having
    both <code>fetchrow_array</code> and <code>fetchrow_arrayref</code> in
    Rakudo. <code>fetchrow</code> simply returns an array or a list, and the
    caller decides what to do with it.</li>
    <li>Backends only need to implement <code>fetchrow</code> and
    <code>column_names</code>, and get all the other fetching methods (like
    <code>fetchrow-hash</code>, <code>fetchall-hash</code>) for free.</li>
    <li>Error handling from DB connection and statement handle are unified
    into a single row</li>
</ul>

<p>The latter two changes brought quite a reduction in backend code size.</p>

<p>My plans for the future include experimenting with different names and
maybe totally different APIs. When a language has lazy lists, one can simply
return all rows lazily, instead of encouraging the user to fetch the rows one
by one.</p>

<p>Currently the Postgresql and mysql backends support basic CRUD operations,
Postgresql with proper prepared statements and placeholders. An SQLite backend
is under way, but still needs better support from our native call interface.</p>


</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/2012-dbiish.html</id>
  </entry>
  <entry>
    <title>Perl 6 Hackathon in Oslo: Be Prepared!</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/2012-hackathon-preparations.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">The Oslo Perl Mongers invite to the Perl 6 Patterns Hackathon in Oslo. I
have previously suggested that we hack on database connectivity, and so
far only got positive feedback. If you want to help, here is what you can
do to be prepared:

  * Get a github account

  * Build and install Rakudo

  * Build and install zavolaj/NativeCall

  * download MiniDBI

  * install and prepare databases to talk to

To hack efficiently on those projects, and to benefit from last-minute
fixes, you should obtain Rakudo, NativeCall and MiniDBI from their git
source repositories -- that last release is already outdated.

Here are the instructions in detail. If at any point you run into
problems, feel free to ask on the #perl6 IRC channel or the
perl6-users@perl.org mailing list.


Get a Github account
--------------------

All the interesting Perl 6 code lives in git repositories on github. If
you don't have an account already, sign up -- it's free.


Build and install Rakudo
------------------------

This step is described well on the Rakudo homepage. Please follow the
instruction in section "Building the compiler from source".

For the following steps it is important that you have a fresh perl6
executable file in your $PATH. If you have downloaded rakudo to
/home/you/p6/rakudo/, you can run the command

PATH=$PATH:/home/you/p6/rakudo/install/bin

(and put it in your ~/.bashrc file if you want it permanently available,
not just in this shell).


Build and install zavolaj/NativeCall
------------------------------------

NativeCall.pm is the high-level interface for calling C functions from
Perl 6 code. Install it:

$ git clone git://github.com/jnthn/zavolaj.git
$ cd zavolaj
$ cp lib/NativeCall.pm6 ~/.perl6/lib/

If you download and install ufo, you can use it create a Makefile for
zavolaj. Then you can also run make test. On Linux it might not find the
test libraries (which is mostly harmless, because you usually call
libraries that are installed into your operating system, like those from
mysql or postgres). In this case you should run LD_LIBRARY_PATH=. make
test instead.


Download MiniDBI
----------------

That's not hard at all:

$ git clone git://github.com/mberends/MiniDBI.git


Install and Prepare Databases
-----------------------------

So far, MiniDBI has (somewhat limited) support for mysql and postgres.
Since it is always easiest to start from (at least somewhat) working
code, I strongly recommend that you install at least one of those
database engines.

Most modern Linux systems allow an easy installation via the package
manager, and there are installers available for other operating systems.
Be sure to also install the headers or development files if they come as
extra packages.


Mysql

As mysql root user, run these statements:

CREATE DATABASE zavolaj;
CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testpass';
GRANT SELECT         ON   mysql.* TO 'testuser'@'localhost';
GRANT CREATE         ON zavolaj.* TO 'testuser'@'localhost';
GRANT DROP           ON zavolaj.* TO 'testuser'@'localhost';
GRANT INSERT         ON zavolaj.* TO 'testuser'@'localhost';
GRANT DELETE         ON zavolaj.* TO 'testuser'@'localhost';
GRANT LOCK TABLES    ON zavolaj.* TO 'testuser'@'localhost';
GRANT SELECT         ON zavolaj.* TO 'testuser'@'localhost';


Postgres

Launch psql as the postgres user and run these statements:

CREATE DATABASE zavolaj;
CREATE ROLE testuser LOGIN PASSWORD 'testpass';
GRANT ALL PRIVILEGES ON DATABASE zavolaj TO testuser;

You should now be able to connect with:

psql --host=localhost --dbname=zavolaj --username=testuser --password

(psql will ask you for the password. Enter testpass).


Other Databases

If you want to work on a backend for another database, it helps to have
that database installed. Sqlite is an obvious choice (easy to install,
zero setup), but of course there are other free database too, like
firebird.


Project ideas
-------------

There is a lot of stuff to do. What follows is only a loose, incomplete
collection of ideas.

  * Fix the postgres backend to actually pass its tests

  * Both mysql and postgres backends don't implement placeholders
    properly; change them (or one of them) to pass the placeholder values
    out of band.

  * Write an sqlite backend

  * Currently the user builds a DSN ("data source name") string out of
    the driver name, database name, db host name and so on, and then the
    driver parses it again. One could change that to pass all the
    information as named parameters instead.

  * Improve test coverage. For example test that numbers round-trip with
    the correct types.

  * Write a small application that uses a database. That's the best way
    to see if MiniDBI and the backends work.</div>
    </summary>
    <content type="html">

&lt;p&gt;The Oslo Perl Mongers &lt;a href="https://gist.github.com/1711730"&gt;invite to the Perl 6 Patterns
Hackathon in Oslo&lt;/a&gt;. I have &lt;a href="http://perlgeek.de/blog-en/perl-6/2012-upcoming-p6-hackathon.html"&gt;previously
suggested that we hack on database connectivity&lt;/a&gt;, and so far only got
positive feedback. If you want to help, here is what you can do to be
prepared:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Get a github account&lt;/li&gt;
    &lt;li&gt;Build and install Rakudo&lt;/li&gt;
    &lt;li&gt;Build and install zavolaj/NativeCall&lt;/li&gt;
    &lt;li&gt;download MiniDBI&lt;/li&gt;
    &lt;li&gt;install and prepare databases to talk to&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To hack efficiently on those projects, and to benefit from last-minute
fixes, you should obtain Rakudo, NativeCall and MiniDBI from their git source
repositories -- that last release is already outdated.&lt;/p&gt;

&lt;p&gt;Here are the instructions in detail. If at any point you run into problems,
feel free to ask &lt;a href="http://perl6.org/community/irc"&gt;on the #perl6 IRC
channel&lt;/a&gt; or the perl6-users@perl.org mailing list.&lt;/p&gt;

&lt;h2&gt;Get a Github account&lt;/h2&gt;

&lt;p&gt;All the interesting Perl 6 code lives in git repositories on &lt;a href="https://github.com/"&gt;github&lt;/a&gt;. If you don't have an account already, &lt;a href="https://github.com/signup/free"&gt;sign up -- it's free&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Build and install Rakudo&lt;/h2&gt;

&lt;p&gt;This step &lt;a href="http://rakudo.org/how-to-get-rakudo/"&gt;is described well
    on the Rakudo homepage&lt;/a&gt;. Please follow the instruction in section
"Building the compiler from source".&lt;/p&gt;

&lt;p&gt;For the following steps it is important that you have a fresh
&lt;code&gt;perl6&lt;/code&gt; executable file in your $PATH. If you have downloaded
rakudo to &lt;code&gt;/home/you/p6/rakudo/&lt;/code&gt;, you can run the command

&lt;pre&gt;
PATH=$PATH:/home/you/p6/rakudo/install/bin
&lt;/pre&gt;

&lt;p&gt;(and put it in your ~/.bashrc file if you want it permanently available,
not just in this shell).&lt;/p&gt;

&lt;h2&gt;Build and install zavolaj/NativeCall&lt;/h2&gt;

&lt;p&gt;NativeCall.pm is the high-level interface for calling C functions from
Perl 6 code. Install it:&lt;/p&gt;

&lt;pre&gt;
$ git clone git://github.com/jnthn/zavolaj.git
$ cd zavolaj
$ cp lib/NativeCall.pm6 ~/.perl6/lib/
&lt;/pre&gt;

&lt;p&gt;If you download and install &lt;a href="https://github.com/masak/ufo/"&gt;ufo&lt;/a&gt;, you can use it create a
Makefile for zavolaj. Then you can also run &lt;code&gt;make test&lt;/code&gt;. On Linux it might not find the
test libraries (which is mostly harmless, because you usually call libraries
that are installed into your operating system, like those from mysql or
postgres). In this case you should run &lt;code&gt;LD_LIBRARY_PATH=. make
test&lt;/code&gt; instead.&lt;/p&gt;

&lt;h2&gt;Download MiniDBI&lt;/h2&gt;

&lt;p&gt;That's not hard at all:&lt;/p&gt;

&lt;pre&gt;
$ git clone git://github.com/mberends/MiniDBI.git
&lt;/pre&gt;

&lt;h2&gt;Install and Prepare Databases&lt;/h2&gt;

&lt;p&gt;So far, MiniDBI has (somewhat limited) support for mysql and postgres.
Since it is always easiest to start from (at least somewhat) working code, I
strongly recommend that you install at least one of those database
engines.&lt;/p&gt;

&lt;p&gt;Most modern Linux systems allow an easy installation via the package
manager, and there are installers available for other operating systems. Be
sure to also install the headers or development files if they come as extra
packages.&lt;/p&gt;

&lt;h3&gt;Mysql&lt;/h3&gt;

&lt;p&gt;As mysql &lt;code&gt;root&lt;/code&gt; user, run these statements:&lt;/p&gt;

&lt;pre&gt;
CREATE DATABASE zavolaj;
CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testpass';
GRANT SELECT         ON   mysql.* TO 'testuser'@'localhost';
GRANT CREATE         ON zavolaj.* TO 'testuser'@'localhost';
GRANT DROP           ON zavolaj.* TO 'testuser'@'localhost';
GRANT INSERT         ON zavolaj.* TO 'testuser'@'localhost';
GRANT DELETE         ON zavolaj.* TO 'testuser'@'localhost';
GRANT LOCK TABLES    ON zavolaj.* TO 'testuser'@'localhost';
GRANT SELECT         ON zavolaj.* TO 'testuser'@'localhost';
&lt;/pre&gt;

&lt;h3&gt;Postgres&lt;/h3&gt;

&lt;p&gt;Launch &lt;code&gt;psql&lt;/code&gt; as the &lt;code&gt;postgres&lt;/code&gt; user and run these
statements:&lt;/p&gt;

&lt;pre&gt;
CREATE DATABASE zavolaj;
CREATE ROLE testuser LOGIN PASSWORD 'testpass';
GRANT ALL PRIVILEGES ON DATABASE zavolaj TO testuser;
&lt;/pre&gt;

&lt;p&gt;You should now be able to connect with:&lt;/p&gt;

&lt;pre&gt;psql --host=localhost --dbname=zavolaj --username=testuser --password
&lt;/pre&gt;

&lt;p&gt;(psql will ask you for the password. Enter &lt;code&gt;testpass&lt;/code&gt;).&lt;/p&gt;

&lt;h3&gt;Other Databases&lt;/h3&gt;

&lt;p&gt;If you want to work on a backend for another database, it helps to have
that database installed. &lt;a href="http://sqlite.org/"&gt;Sqlite&lt;/a&gt; is
an obvious choice (easy to install, zero setup), but of course there are
other free database too, like &lt;a href="http://firebirdsql.org/&amp;quot;"&gt;firebird&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Project ideas&lt;/h2&gt;

&lt;p&gt;There is a lot of stuff to do. What follows is only a loose, incomplete
collection of ideas.&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Fix the postgres backend to actually pass its tests&lt;/li&gt;
    &lt;li&gt;Both mysql and postgres backends don't implement placeholders
    properly; change them (or one of them) to pass the placeholder values out
    of band.&lt;/li&gt;
    &lt;li&gt;Write an sqlite backend&lt;/li&gt;
    &lt;li&gt;Currently the user builds a DSN ("data source name") string out of the
    driver name, database name, db host name and so on, and then the driver
    parses it again. One could change that to pass all the information as
    named parameters instead.&lt;/li&gt;
    &lt;li&gt;Improve test coverage. For example test that numbers round-trip with
    the correct types.&lt;/li&gt;
    &lt;li&gt;Write a small application that uses a database. That's the best way to
    see if MiniDBI and the backends work.&lt;/li&gt;
&lt;/ul&gt;




</content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/2012-hackathon-preparations.html</id>
  </entry>
  <entry>
    <title>Perl 6 Hackathon in Oslo: Report From The First Day</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/2012-oslo-hackathon-report.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Yesterday I arrived in the beautiful city of Oslo to attend the Perl 6
Patterns Hackathon. Yesterday we visited a pub, had great discussions,
food and beverages, and generally a very good time.

Today we met at 10 am, and got straight to hacking. We are located in an
office in the 6th floor of a big building, with a nice view over the
center of town, harbor, and even the Holmenkollen.

I worked on the backtrace printer, which in alarmingly many cases
reported Error while creating error string: Method 'message' not found
for invocant of class 'Any', which wasn't too helpful.

It turns out there were actually two causes. One was a subtle error in
the backtrace printer that was triggered by stricter implementation of
the specification, which was easy to find. The second bug was harder to
find, considering that you don't get easily get backtraces from errors
within the backtrace printer. In the end it was the usage of a code
object in boolean context, which turned out to be harmful. Because
regexes are also code objects, and in boolean context they search for the
outer $_ variable and try to match the regex against it. Which failed.
Hard to find, but easy to fix.

My second big project today was database connectivity. Part of it was
pestering Jonathan to fix the issues that arose from module
precompilation mixed with calling C modules, and testing all the
iterations he produced. I'm happy to report that it now works fine, which
speeds up development quite a bit.

I also fixed the postgres driver. The root cause for the failing tests
turned out to be rather simple too (a missing initialization), so simple
that it's embarrassing how long it took me to find out. On the plus side
I improved the code quite a bit in passing.

So now all tests in MiniDBI pass, which is a nice milestone, and an
indication that we need more tests.

Tomorrow I plan to change the postgres driver to use proper prepared
statments.

But the real value of such hackathon comes from interacting with the
other hackers. I'm very happy about lots of discussions with other core
hackers, as well as feedback and patches from new users and hackers.

At this occasion I'd also like to thank the organizers, Salve J. Nilsen,
Karl Rune Nilsen and Jan Ingvoldstad. It has been a great event so far,
both fun and productive. You are doing a great service to the Perl 6
community, and to the hackers you have invited.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">

<p>Yesterday I arrived in the beautiful city of Oslo to attend the <a href="https://gist.github.com/1711730">Perl 6 Patterns Hackathon</a>.
Yesterday we visited a pub, had great discussions, food and beverages, and
generally a very good time.</p>

<p>Today we met at 10 am, and got straight to hacking. We are located in an
office in the 6th floor of a big building, with a nice view over the center of
town, harbor, and even the Holmenkollen.</p>

<p>I worked on the backtrace printer, which in alarmingly many cases reported
<code>Error while creating error string: Method 'message' not found for
invocant of class 'Any'</code>, which wasn't too helpful.</p>

<p>It turns out there were actually two causes. One was a subtle error in the
backtrace printer that was triggered by <a href="https://github.com/rakudo/rakudo/commit/6ef66c9521b14f33ded88c3da8569032488d2442">stricter
    implementation of the specification</a>, which was easy to find. The
second bug was harder to find, considering that you don't get easily get
backtraces from errors within the backtrace printer. In the end it was the
usage of a code object in boolean context, which turned out to be harmful.
Because regexes are also code objects, and in boolean context they search for
the outer <code>$_</code> variable and try to match the regex against it.
Which failed. Hard to find, but easy to fix.</p>

<p>My second big project today was database connectivity. Part of it was
pestering Jonathan to fix the issues that arose from module precompilation
mixed with calling C modules, and testing all the iterations he produced. I'm
happy to report that it now works fine, which speeds up development quite a
bit.</p>

<p>I also fixed the postgres driver. The root cause for the failing tests
turned out to be rather simple too (a missing initialization), so simple that
it's embarrassing how long it took me to find out. On the plus side I improved
the code quite a bit in passing.</p>

<p>So now all tests in <a href="https://github.com/mberends/MiniDBI">MiniDBI</a> pass, which is a nice
milestone, and an indication that we need more tests.</p>

<p>Tomorrow I plan to change the postgres driver to use proper prepared
statments.</p>

<p>But the real value of such hackathon comes from interacting with the other
hackers. I'm very happy about lots of discussions with other core hackers, as
well as feedback and patches from new users and hackers.</p>

<p>At this occasion I'd also like to thank the organizers, Salve J. Nilsen,
Karl Rune Nilsen and Jan Ingvoldstad. It has been a great event so far, both fun and productive. You are
doing a great service to the Perl 6 community, and to the hackers you have
invited.</p>



</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/2012-oslo-hackathon-report.html</id>
  </entry>
  <entry>
    <title> Travelling in time: the CP2000AN </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/cp2000an" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/cp2000an</id>
  </entry>
  <entry>
    <title> Graphing tool </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/graphing-tool" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/graphing-tool</id>
  </entry>
  <entry>
    <title> XML::Tiny released </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/xml-tiny" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/xml-tiny</id>
  </entry>
  <entry>
    <title> YAPC::Europe 2007 report: day 1 </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/yapc-europe-2007-day-1" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/yapc-europe-2007-day-1</id>
  </entry>
  <entry>
    <title>Perl 6 in 2011 - A Retrospection</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/perl-6-in-2011.html" type="text/html"/>
    <summary type="text">The change of year is a good occasion to look back. Here I want to
reflect on the development of Perl 6, its compilers and ecosystem.

At the start of the year, masak's Perl 6 Coding Contest continued from
2010, concluding in the announcement of the winner. I must admit that I
still haven't read all the books I won :-)


Specification
-------------

2011 was a rather quiet year in terms of spec changes; they were a
mixture of responses to compiler writer and user feedback, and some
simplifications and cleanups.

Positional parameters used to be allowed to be called by name; this
feature is now gone. That both makes the signature binder simpler, and
removes accidental dependencies on names that weren't meant to be public.
Read the full justification for more background.

A small change that illustrates the cleanup of old, p5-inherited features
was the change that made &amp;eval stop catching exceptions. There is really
no good reason for it to catch them, except Perl 5 legacy.

say now uses a different stringification than print. The reasoning is
that print is aimed at computer-readable output, whereas say is often
used for debugging. As an example, undefined values stringify to the
empty string (and produce a warning), whereas say calls the .gist method
on the object to be said, which produces the type name on undefined
values.

An area that has been greatly solidified due to implementation progress
is Plain Old Documentation or Pod. Tadeusz Sośnierz' Google Summer of
Code project ironed out many wrinkles and inconsistencies, and changed my
perception of this part of the spec from "speculative" to "under
development".


Rakudo
------

Rakudo underwent a huge refactoring this year; it is now bootstrapped by
a new compiler called "nqp", and uses a new object model (nom).

It allows us to gain speed and memory advantages from gradual typing; for
example the mandelbrot fractral generator used to take 18 minutes to run
on a machine of mine, and now takes less than 40 seconds. Speedups in
other areas are not as big, but there is still much room for improvement
in the optimizer.

With the nom branch came support for different object representations. It
makes it possible to store object attributes in simple C-like structs,
which in turn makes it much easier and more convenient to interoperate
with C libraries.

Tadeusz' work on Pod gave Rakudo support for converting Pod to plain text
and HTML, and attach documentation objects to routines and other objects.

Rakudo now also has lazy lists, much better role handling, typed
exceptions for a few errors, the -n and -p command line options, support
for big integers, NFA-based support for proto regexes and improvements to
many built-in functions, methods and operators.


Niecza
------

It is hard to accurately summarize the development of Niecza in a few
sentences; instead of listing the many, many new features I should give
an impression on how it feels and felt for the user.

At the start of 2011, programming in niecza was a real adventure. Running
some random piece of Perl 6 code that worked with Rakudo rarely worked,
most of the time it hit a missing built-in, feature or bug.

Now it often just works, and usually much faster than in Rakudo. There
are still some missing features, but Stefan O'Rear and his fellow
contributors work tirelessly on catching up to Rakudo, and it some areas
Niecza is clearly ahead (for example Unicode support in regexes, and
longest-token matching).

Since Niecza is implemented on top of the Common Language Runtime (CLR)
(which means .NET or mono), it makes it easy to use existing CLR-based
libraries. Examples include an interactive fractal generator and a small
Tetris game in Perl 6.


Perlito
-------

Perlito aims to be a minimal compiler with multiple backends, which can
be used for embedding and experimenting with Perl 6. It had several
releases in 2011, and has interesting features like a Javascript backend.


Ecosystem
---------

The presence of two usable compilers (and in the case of Rakudo, two
viable but very different branches) has led to many questions about the
different compilers. The new Perl 6 Compiler Feature matrix tries to
answer the questions about the state of the implemented features in the
compilers.

With Panda we now have a module installer that actually works with
Rakudo. It still has some lengths to go in terms of stability and feature
completeness, but it is fun to work with.

The new Perl 6 Modules page gives an overview of existing Perl 6 modules;
we hope to evolve it into a real CPAN equivalent.


Community
---------

This year we had another Perl 6 Advent Calendar, with much positive
feedback both from the Perl 6 community and the wider programming
community.

We were also happy to welcome several new prolific contributors to the
Perl 6 compilers and modules. The atmosphere in the community still feels
relaxed, friendly and productive -- I quite enjoy it.

The year ends like it started: with a Perl 6 Coding Contest. This is a
good opportunity to dive into Perl 6, provide feedback to compiler
writers, and most of all have fun.</summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>The change of year is a good occasion to look back. Here I want to
reflect on the development of Perl 6, its compilers and ecosystem.</p>

<p>At the start of the year, masak's <a href="http://strangelyconsistent.org/p6cc2010/">Perl 6 Coding Contest</a>
continued from 2010, concluding in the <a href="http://strangelyconsistent.org/blog/announcing-the-winner-of-p6cc2010">announcement
of the winner</a>. I must admit that I still haven't read all the books I
won :-)</p>

<h2>Specification</h2>

<p>2011 was a rather quiet year in terms of spec changes; they were a
mixture of responses to compiler writer and user feedback, and
some simplifications and cleanups.</p>

<p>Positional parameters used to be allowed to be called by name; this
feature is now gone. That both makes the signature binder simpler, and
removes accidental dependencies on names that weren't meant to be public.
Read the <a href="https://gist.github.com/984783">full justification</a>
for more background.</p>

<p>A small change that illustrates the cleanup of old, p5-inherited features
was the change that <a href="https://github.com/perl6/specs/commit/e84b11137cc55ecd9f17f58976c08d361054ea05">made
&amp;eval stop catching exceptions</a>. There is really no good reason for it
to catch them, except Perl 5 legacy.</p>

<p><code>say</code> now uses a different stringification than
<code>print</code>. The reasoning is that <code>print</code> is aimed at
computer-readable output, whereas <code>say</code> is often used for
debugging. As an example, undefined values stringify to the empty string
(and produce a warning), whereas <code>say</code> calls the <code>.gist</code>
method on the object to be said, which produces the type name on undefined
values.</p>

<p>An area that has been greatly solidified due to implementation progress is
<em>Plain Old Documentation</em> or <em>Pod</em>. Tadeusz Sośnierz' Google
Summer of Code project ironed out many wrinkles and inconsistencies, and
changed my perception of this part of the spec from "speculative" to "under
development".</p>

<h2>Rakudo</h2>

<p><a href="http://rakudo.org/">Rakudo</a> underwent a huge refactoring this year; it is now <a href="http://pmthium.com/2011/02/08/new-nqp-repository-new-nom-rakudo-branch/">bootstrapped
by a new compiler called "nqp", and uses a new object model</a> (nom).</p>

<p>It allows us to gain speed and memory advantages from gradual typing; for
example the <a href="https://github.com/colomon/mandelbrot/blob/master/bin/mandelbrot-color.pl">mandelbrot
fractral generator</a> used to take 18 minutes to run on a machine of mine,
and now takes less than 40 seconds. Speedups in other areas are not as big,
but there is still much room for improvement in the optimizer.</p>

<p>With the nom branch came support for different object representations. It
makes it possible to store object attributes in simple C-like structs, which
in turn makes it much easier and more convenient to <a href="https://github.com/jnthn/zavolaj/">interoperate with C
libraries</a>.</p>

<p>Tadeusz' work on Pod gave Rakudo support for converting Pod to plain text
and HTML, and attach documentation objects to routines and other objects.</p>

<p>Rakudo now also has lazy lists, much better role handling, <a href="http://news.perlfoundation.org/2011/02/hague-grant-application-struct.html">typed
exceptions for a few errors</a>, the <code>-n</code> and <code>-p</code> command
line options, support for big integers, NFA-based support for proto regexes
and improvements to many built-in functions, methods and operators.</p>


<h2>Niecza</h2>

<p>It is hard to accurately summarize the development of <a href="https://github.com/sorear/niecza/">Niecza</a> in a few
sentences; instead of listing the many, many new features I should give
an impression on how it feels and felt for the user.</p>

<p>At the start of 2011, programming in niecza was a real adventure. Running 
some random piece of Perl 6 code that worked with Rakudo rarely worked, most
of the time it hit a missing built-in, feature or bug.</p>

<p>Now it often just works, and usually much faster than in Rakudo. There are
still some missing features, but Stefan O'Rear and his fellow contributors
work tirelessly on catching up to Rakudo, and it some areas Niecza is clearly
ahead (for example Unicode support in regexes, and longest-token
matching).</p>

<p>Since Niecza is implemented on top of the Common Language Runtime (CLR)
(which means .NET or mono), it makes it easy to use existing CLR-based
libraries. Examples include <a href="http://perl6advent.wordpress.com/2011/12/17/day-17-gtk-mandelbrot/">an
interactive fractal generator</a> and a small <a href="http://perl6advent.wordpress.com/2011/12/05/tetris-on-niecza/">Tetris
game in Perl 6.</a></p>

<h2>Perlito</h2>

<p><a href="http://www.perlito.org/">Perlito</a> aims to be a minimal compiler
with multiple backends, which can be used for embedding and experimenting with
Perl 6. It had several releases in 2011, and has interesting features like a
Javascript backend.</p>

<h2>Ecosystem</h2>

<p>The presence of two usable compilers (and in the case of Rakudo, two viable
but very different branches) has led to many questions about the different
compilers. The new <a href="http://perl6.org/compilers/features">Perl 6
Compiler Feature matrix</a> tries to answer the questions about the state of
the implemented features in the compilers.</p>

<p>With <a href="https://github.com/tadzik/panda/">Panda</a> we now have a
module installer that actually works with Rakudo. It still has some lengths to
go in terms of stability and feature completeness, but it is fun to work
with.</p>

<p>The new <a href="http://modules.perl6.org/">Perl 6 Modules</a> page gives
an overview of existing Perl 6 modules; we hope to evolve it into a real CPAN
equivalent.</p>

<h2>Community</h2>

<p>This year we had another <a href="http://perl6advent.wordpress.com/2011/12/01/perl-6-advent-calendar-2011/">Perl
6 Advent Calendar</a>, with much positive feedback both from the Perl 6
community and the wider programming community.</p>

<p>We were also happy to welcome several new prolific contributors to the Perl
6 compilers and modules. The atmosphere in the community still feels relaxed,
friendly and productive -- I quite enjoy it.</p>

<p>The year ends like it started: with a <a href="http://strangelyconsistent.org/blog/the-2011-perl-6-coding-contest">Perl
6 Coding Contest</a>. This is a good opportunity to dive into Perl 6, provide
feedback to compiler writers, and most of all have fun.</p>

 
</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/perl-6-in-2011.html</id>
  </entry>
  <entry>
    <title> Thanks, Yahoo! </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/thanks-yahoo" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/thanks-yahoo</id>
  </entry>
  <entry>
    <title> YAPC::Europe 2007 report: day 2 </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/yapc-europe-2007-day-2" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/yapc-europe-2007-day-2</id>
  </entry>
  <entry>
    <title> YAPC::Europe 2007 travel plans </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/yapc-europe-2007--travel-plans" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/yapc-europe-2007--travel-plans</id>
  </entry>
  <entry>
    <title> Wikipedia handheld proxy </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/wikipedia-proxy" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/wikipedia-proxy</id>
  </entry>
  <entry>
    <title>SQLite support for DBIish</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/2012-sqlite-in-dbiish.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">DBIish, the new database interface for Rakudo Perl 6, now has a working
SQLite backend. It uses prepared statements and placeholders, and
supports standard CRUD operations.

Previously the SQLite driver would randomly report "Malformed UTF-8
string" or segfault, but usually worked pretty well when run under
valgrind. The problem turned out to be a mismatch between the caller's
and the callee's ideas about memory management.

In particular, parrot's garbage collector would deallocate strings passed
to sqlite3_bind_text after the call was done, but sqlite wants such
values to stay around until the next call to sqlite3_step in the very
least.

Fixing this mismatch was enabled by this patch, which lets you mark
strings as explicitly managed. Such strings keep their marshalled C
string equivalent around until they are garbage-collected themselves. So
now the sqlite driver keeps a copy of the strings as long as necessary,
and the SQLite tests pass reliably.

Currently it still needs the cstr branches in the nqp and zavolaj
repositories, but they will be merged soon -- certainly before the May
release of Rakudo.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">

<p><a href="https://github.com/perl6/DBIish/">DBIish</a>, the new database
interface for Rakudo Perl 6, now has a working SQLite backend. It uses
prepared statements and placeholders, and supports standard CRUD
operations.</p>

<p>Previously the SQLite driver would randomly report "Malformed UTF-8 string"
or segfault, but usually worked pretty well when run under valgrind. The
problem turned out to be a mismatch between the caller's and the callee's
ideas about memory management.</p>

<p>In particular, parrot's garbage collector would deallocate strings passed
to <a href="http://www.sqlite.org/c3ref/bind_blob.html">sqlite3_bind_text</a>
after the call was done, but sqlite wants such values to stay around until
the next call to <a href="http://www.sqlite.org/c3ref/step.html">sqlite3_step</a> in the very
least.</p>

<p>Fixing this mismatch was enabled <a href="https://github.com/jnthn/zavolaj/commit/e94f45ca4dd5df3010ecb84051980f506e3cbe6d">by
this patch</a>, which lets you mark strings as explicitly managed. Such
strings keep their marshalled C string equivalent around until they are
garbage-collected themselves. So now <a href="https://github.com/perl6/DBIish/commit/9b339432405228a895c76bf1193bdba3f935b99b">the
sqlite driver keeps a copy of the strings</a> as long as necessary, and the SQLite
tests pass reliably.</p>

<p>Currently it still needs the <code>cstr</code> branches in the nqp and
zavolaj repositories, but they will be merged soon -- certainly before the May
release of Rakudo.</p>


</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/2012-sqlite-in-dbiish.html</id>
  </entry>
  <entry>
    <title> Bryar security hole </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/bryar-security-hole" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/bryar-security-hole</id>
  </entry>
  <entry>
    <title> POD includes </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/pod-includes" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/pod-includes</id>
  </entry>
  <entry>
    <title> cgit syntax highlighting </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/cgit-syntax-highlighting" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/cgit-syntax-highlighting</id>
  </entry>
  <entry>
    <title>Fourth Grant Report: Structured Error Messages</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/grant-report-errors-4.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Progress on my grant for error message is slow but steady. Since my last
report, I've done the following things:

  * Merged the nom-exceptions Rakudo branch, so now you can reliably
    throw Perl 6 objects as exceptions.

  * Implemented several error classes and roles in Rakudo

  * Started to throw typed errors both from runtime libraries and from
    inside the compiler

  * Hacked the default exception printer Rakudo to be much more flexible,
    for example you can now write exception classes that supress
    backtraces from the standard handler.

  * Wrote tests for typed run time and compile time errors, and at the
    same time developed a test function that makes it easy to write such
    tests.

It's time for a quick review of how far I am along the various
deliverables in the original grant proposal.

  * D1: Specification. I think the hard work here is done already, what
    remains to do is finding good default and how to manipulate them (for
    example, how to generally switch on/off printing of backtraces?).

  * D2: Error catalogue, tests: I've not worked on this one too much. The
    error classes and roles so far mostly served to exercise the
    implementation; going through the existing errors from the various
    compilers and formalizing them will be quite a bit of work, but only
    moderately complicated.

  * D3: Implementation, documentation. Like D1, the hard part is mostly
    done. We can now throw errors from within the compiler actions and
    from the setting, next up will be the grammar. Then all places where
    errors are thrown need to be changed to use the new error classes.
    Again that'll be much work, but easy to do. Documentation is still
    missing.

All in all I feel I'm well on the way, and most complex decisions have
been made.

For a more user oriented view of the new exception system I'd like to
point you to my Perl 6 advent calendar post on exceptions.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>Progress on my <a href="http://news.perlfoundation.org/2011/02/hague-grant-application-struct.html">grant
for error message</a> is slow but steady. Since my last report, I've done the
following things:</p>

<ul>
    <li>Merged the <code>nom-exceptions</code> Rakudo  branch, so now you
    can reliably throw Perl 6 objects as exceptions.</li>
    <li>Implemented several error classes and roles in Rakudo</li>
    <li>Started to throw typed errors both from runtime libraries and from
        inside the compiler</li>
    <li>Hacked the default exception printer Rakudo to be much more flexible,
        for example you can now write exception classes that supress
        backtraces from the standard handler.</li>
    <li>Wrote tests for typed run time and compile time errors, and at the
        same time developed a test function that makes it easy to write such
        tests.</li>
</ul>

<p>It's time for a quick review of how far I am along the various deliverables
in the original grant proposal.</p>

<ul>
    <li>D1: Specification. I think the hard work here is done already,
        what remains to do is finding good default and how to manipulate them
        (for example, how to generally switch on/off printing of
        backtraces?).</li>
    <li>D2: Error catalogue, tests: I've not worked on this one too much.
        The error classes and roles so far mostly served to exercise the
        implementation; going through the existing errors from the various
        compilers and formalizing them will be quite a bit of work, but only
        moderately complicated.</li>
    <li>D3: Implementation, documentation. Like D1, the hard part is mostly 
        done. We can now
       throw errors from within the compiler actions and from the setting,
       next up will be the grammar. Then all places where errors are thrown
       need to be changed to use the new error classes. Again that'll be much
       work, but easy to do. Documentation is still missing.</li>
</ul>

<p>All in all I feel I'm well on the way, and most complex decisions have been
made. </p>


<p>For a more user oriented view of the new exception system I'd like to
point you to my <a href="http://perl6advent.wordpress.com/2011/12/15/day-15-something-exceptional/">Perl
    6 advent calendar post on exceptions</a>.</p>


</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/grant-report-errors-4.html</id>
  </entry>
  <entry>
    <title>Perl 6 Hackathon in Oslo: Report From The Second Day</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/2012-oslo-hackathon-rest.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Second day of the Perl 6 Patterns Hackathon. My plans to get the rest of
placeholders and prepared statements working in the Postgresql backend
for MiniDBI succeed about 10 minutes after midnight. I just wanted to
give them a very quick try before going to bed, and was successful. Then
I went to sleep.

It was night, and it was morning. Second day.

Next I wrote an SQLite backend for MiniDBI. It blocked on missing
features in our native call infrastructure, on which arnsholt worked in
parallel. So I haven't had a chance to try the SQLite backend yet. It
probably requires some substantial amount of work before it will run, but
at least it compiles.

I also investigated prepared statements and placeholders for the mysql
backend. This is much less straight forward, because it requires filling
in members of structs, not just function calls. This by itself wouldn't
be much a problem, our native call infrastructure supports that. The
problem is that it's a struct of mixed "private" and "public" members, so
modelling the structure in Perl 6 requires modeling private data of the
mysql client library. While possible, I don't find it desirable, because
it is rather fragile.

Another notable event was the hacking dojo, where about 8 of us
collaborated to write a roman numeral conversion, using pair programming,
and fixed cycles of first writing a failing test, then getting it to run
in the simplest possible way, and finally refactoring it. It was quite an
interesting and fun experience.

I spent much of the rest of the hackathon discussing things. For example
Patrick Michaud gave a quick walk through of how lists and related types
are implemented and iterated in Rakudo.

In the evening we had very tasty Vietnamese food, and generally a good
time.

Again it was a very productive and enjoyable day, and I'm very grateful
for being invited to the Hackathon.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">

<p>Second day of the <a href="https://gist.github.com/1711730">Perl 6 Patterns
Hackathon</a>. My plans to get the rest of placeholders and prepared
statements working in the Postgresql backend for MiniDBI succeed about 10
minutes after midnight. I just wanted to give them a very quick try before
going to bed, and was successful. Then I went to sleep.</p>

<p>It was night, and it was morning. Second day.</p>

<p>Next I wrote an SQLite backend for MiniDBI. It blocked on missing features
in our native call infrastructure, on which arnsholt worked in parallel. So I
haven't had a chance to try the SQLite backend yet. It probably requires some
substantial amount of work before it will run, but at least it compiles.</p>

<p>I also investigated prepared statements and placeholders for the mysql
backend. This is much less straight forward, because it requires filling in
members of structs, not just function calls. This by itself wouldn't be much a
problem, our native call infrastructure supports that. The problem is that
it's a struct of mixed "private" and "public" members, so modelling the
structure in Perl 6 requires modeling private data of the mysql client
library. While possible, I don't find it desirable, because it is rather
fragile.</p>

<p>Another notable event was the hacking dojo, where about 8 of us
collaborated to write a roman numeral conversion, using pair programming, and
fixed cycles of first writing a failing test, then getting it to run in the
simplest possible way, and finally refactoring it. It was quite an interesting
and fun experience.</p>

<p>I spent much of the rest of the hackathon discussing things. For example
Patrick Michaud gave a quick walk through of how lists and related types are
implemented and iterated in Rakudo.</p>

<p>In the evening we had very tasty Vietnamese food, and generally a good
time.</p>

<p>Again it was a very productive and enjoyable day, and I'm very grateful for
being invited to the Hackathon.</p>



</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/2012-oslo-hackathon-rest.html</id>
  </entry>
  <entry>
    <title> CPAN Testers' CPAN author FAQ </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/cpantesters-cpan-author-faq" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/cpantesters-cpan-author-faq</id>
  </entry>
  <entry>
    <title>Why Rakudo needs NQP</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/why-rakudo-needs-nqp.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Rakudo, a popular Perl 6 compiler, is built on top of a smaller compiler
called "NQP", short for Not Quite Perl.

Reading through a recent ramble by chromatic, I felt like he said "Rakudo
needs NQP to be able to ditch Parrot, once NQP runs on a different
platform" (NQP is the "another layer", which sits between Rakudo and
Parrot, mentioned in the next-to-final paragraph).

I'm sure chromatic knows that VM independence is the least important
reason for having NQP at all, but the casual reader might not, so let me
explain the real importance of NQP for Rakudo here.

The short version is just a single word: bootstrapping.

The longer version is that large parts of Rakudo are written in Perl 6
itself (or a subset thereof), and something is needed to break the
circularity.

In particular the base of the compiler is written in a subset of Perl 6,
and NQP compiles those parts to bytecode, which can then compile the rest
of the compiler.

This is not just because we have a fancy for Perl 6, and thus want to
write as much of the code in Perl 6, but there are solid technical
reasons for writing the compiler in Perl 6.

In Perl 6, the boundary between run time and compile time is blurred, as
well as the boundary between the compiler, the run time library and
user-space code. For example you alter the grammar with which your source
code is parsed, by injecting your own grammar rules.

"Your own grammar rules" above refers to user-space code, while the
grammar that is being altered is part of the compiler. If we had written
the compiler in something else than Perl 6 (for example Java), it would
be horribly difficult to inject user-space Perl 6 code into compiled code
from a different language.

And the code not only needs to be injected, but the data passed back and
forth between the compiler and the user space need to be Perl 6 objects,
so all important data structures in the compiler need to be Perl 6 based
anyway.

And it's not just for grammar modifications: At its heart, Perl 6 is an
object oriented language. When the compiler sees a class definition, it
translates them to a series of method calls on the metaobject, which
again needs to be a Perl 6 object, otherwise it wouldn't be easily usable
and extensible from the user space.

Now you might think that grammar modifications and changes to the
Metaobject are pretty obscure features, and you could get along just fine
with an incomplete Perl 6 compiler that neglected those two areas. But
even then you'd have lots of interactions between run time and compile
time. For example consider a numeric literal like 42. Obviously that
needs to be constructed of type Int. What's less obvious is that it needs
to be constructed to be of type Int at compile time already, because Perl
6 code can run interleaved with the compilation. So the compiler needs to
be able to handle Perl 6 objects in all their generality, which is a huge
pain if the compiler is not written in Perl 6.

Rakudo has cheated on that front in the past, and consequently has had
lots of bugs and limitations due to non-Perl 6 objects leaking out at
unexpected ends. If you ever got a "Null PMC Access" from Rakudo, you
know what I mean.

The lesson we learned was that you need a Perl 6 compiler to implement a
Perl 6 compiler, even if that first Perl 6 compiler can handle only a
rather limited subset of Perl 6.

And there are also quite some benefits to this approach. For example
NQP's new regex engine is implemented as a role in NQP. It is mixed into
an NQP class which allows us to build Rakudo, but it is also mixed in a
Perl 6 class, which allows the generation of Perl 6-level Match objects
without any need to create NQP-level match objects first, and then wrap
them in Perl 6 Match objects.

That's what NQP does for us. It allows us to actually write a Perl 6
compiler.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">

<p><a href="http://rakudo.org/">Rakudo</a>, a popular <a href="http://perl6.org/">Perl 6</a> compiler, is built on top of a smaller
compiler called "NQP", short for <em>Not Quite Perl</em>.</p>

<p>Reading through a <a href="http://www.modernperlbooks.com/mt/2011/08/no-policy-can-save-wrong-code.html">recent
    ramble by chromatic</a>, I felt like he said "Rakudo needs NQP to be able
to ditch Parrot, once NQP runs on a different platform" (NQP is the "another
layer", which sits between Rakudo and Parrot, mentioned in the next-to-final
paragraph).</p>

<p>I'm sure chromatic knows that VM independence is the least important reason
for having NQP at all, but the casual reader might not, so let me explain the
real importance of NQP for Rakudo here.</p>

<p>The short version is just a single word: <a href="http://en.wikipedia.org/wiki/Bootstrapping_%28compilers%29">bootstrapping</a>.</p>

<p>The longer version is that large parts of Rakudo are written in Perl 6
itself (or a subset thereof), and something is needed to break the
circularity.</p>

<p>In particular the base of the compiler is written in a subset of Perl 6,
and NQP compiles those parts to bytecode, which can then compile the rest of
the compiler.</p>

<p>This is not just because we have a fancy for Perl 6, and thus want to write
as much of the code in Perl 6, but there are solid technical reasons for
writing the compiler in Perl 6.</p>

<p>In Perl 6, the boundary between run time and compile time is blurred, as
well as the boundary between the compiler, the run time library and user-space
code. For example you alter the grammar with which your source code is parsed, by
injecting your own grammar rules.</p>

<p>"Your own grammar rules" above refers to user-space code, while the grammar
that is being altered is part of the compiler. If we had written the compiler
in something else than Perl 6 (for example Java), it would be horribly
difficult to inject user-space Perl 6 code into compiled code from a different
language.</p>

<p>And the code not only needs to be injected, but the data passed back
and forth between the compiler and the user space need to be Perl 6 objects, so all
important data structures in the compiler need to be Perl 6 based anyway.</p>

<p>And it's not just for grammar modifications: At its heart, Perl 6 is an
object oriented language. When the compiler sees a class definition, it
translates them to a series of method calls on the <a href="http://en.wikipedia.org/wiki/Metaobject">metaobject</a>, which again
needs to be a Perl 6 object, otherwise it wouldn't be easily usable and
extensible from the user space.</p>

<p>Now you might think that grammar modifications and changes to the
Metaobject are pretty obscure features, and you could get along just fine
with an incomplete Perl 6 compiler that neglected those two areas. But even
then you'd have lots of interactions between run time and compile time. For
example consider a numeric literal like <code>42</code>. Obviously that needs
to be constructed of type <code>Int</code>. What's less obvious is that it
needs to be constructed to be of type Int at compile time already, because
Perl 6 code can run interleaved with the compilation. So the compiler needs to
be able to handle Perl 6 objects in all their generality, which is a huge pain
if the compiler is not written in Perl 6.</p>

<p>Rakudo has cheated on that front in the past, and consequently has
had lots of bugs and limitations due to non-Perl 6 objects leaking out at
unexpected ends. If you ever got a "Null PMC Access" from Rakudo, you know what I
mean.</p>

<p>The lesson we learned was that <strong>you need a Perl 6 compiler to
implement a Perl 6 compiler</strong>, even if that first Perl 6 compiler can
handle only a rather limited subset of Perl 6.</p>


<p>And there are also quite some benefits to this approach. For example <a href="http://pmthium.com/2011/07/14/new-regex-engine-for-nqp-and-nom-now-passing-7k-spectests/">NQP's new
    regex engine</a> is implemented as a role in NQP. It is mixed into an NQP
class which allows us to build Rakudo, but it is also mixed in a Perl 6 class,
which allows the generation of <a href="http://perlcabal.org/syn/S05.html#Match_objects">Perl 6-level Match
objects</a> without any need to create NQP-level match objects first, and then
wrap them in Perl 6 Match objects.</p>

<p>That's what NQP does for us. It allows us to actually write a Perl 6
compiler.</p>


</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/why-rakudo-needs-nqp.html</id>
  </entry>
  <entry>
    <title> Thankyou, Anonymous Benefactor! </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/thankyou-anonymous-benefactor" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/thankyou-anonymous-benefactor</id>
  </entry>
  <entry>
    <title> Number::Phone release </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/number-phone-release" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/number-phone-release</id>
  </entry>
  <entry>
    <title>Mini-Challenge: Write Your Prisoner's Dilemma Strategy</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/iterated-prisoners-dilemma.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Here is a small task we considered for the Perl 6 Coding Contest, but not
chose to not pursue. But it's a nice little challenge for your leisure
time.

In the Prisoner's Dilemma, two suspected criminals can choose to not
betray each other (which we call "cooperate"), or betraying the other
("defecting"). If only one suspect betrays the other, the traitor gets
released and the betrayed one gets a long sentence; if both betray each
other, both get a rather long sentence. If both cooperate, both get
rather short sentences.

It becomes more interesting when the dilemma is repeated multiple times.
Now instead of prison sentences the contestants are assigned scores,
which add up over multiple rounds.

I challenge you to write one or two strategies for the iterated
prisoner's dilemma, and send them to moritz@faui2k3.org no later than
Friday February 17.

You'll find some basic strategies and a harness here. It runs on both
newest Rakudo and Niecza.

The scoring is as follows, where True means cooperate and False means
defect:

my %scoring =
    'True True' =&gt; [4, 4],
    'True False' =&gt; [0, 6],
    'False True' =&gt; [6, 0],
    'False False' =&gt; [1, 1],

Your strategy should be a subroutine or block that accepts the named
parameters mine and theirs, which are lists of previous decisions of your
own algorithm and of its opponents, and total, which is the number of
laps to be played. It should return True if it wishes to cooperate, and
False to defect.

Here is an example strategy that starts off with cooperating, and then
randomly chooses a previous reaction of the current opponent:

sub example-strategy(:@theirs, *%) {
    @theirs.roll // True;
}

Your strategy or strategies will play against each other and against the
example strategies in the gist above. It is not allowed to submit
strategies that commit suicide to actively support another strategy.

I too have written two strategies that will take participate in the
contest. Here is the checksum to convince you I won't alter the
strategies in response to the submissions:

6d4ba99b66e4963a658c8dcfc72922dd0f74e0ad  prisoner-moritz.pl</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">

<p>Here is a small task we considered for the <a href="http://strangelyconsistent.org/blog/the-2011-perl-6-coding-contest">Perl
6 Coding Contest</a>, but not chose to not pursue. But it's a nice little
challenge for your leisure time.</p>

<p>In the <a href="http://en.wikipedia.org/wiki/Prisoner%27s_dilemma">Prisoner's
Dilemma</a>, two suspected criminals can choose to not betray each other
(which we call "cooperate"), or betraying the other ("defecting").
If only one suspect betrays the other, the traitor gets released and
the betrayed one gets a long sentence; if both betray each other, both get a
rather long sentence. If both cooperate, both get rather short sentences.</p>

<p>It becomes more interesting when the dilemma is repeated multiple times.
Now instead of prison sentences the contestants are assigned scores, which
add up over multiple rounds.</p>

<p>I challenge you to write one or two strategies for the iterated prisoner's
dilemma, and send them to moritz@faui2k3.org no later than Friday
February 17.</p>

<p>You'll find <a href="https://gist.github.com/1710688">some basic
strategies and a harness here</a>. It runs on both newest Rakudo and
Niecza.</p>

<p>The scoring is as follows, where <code>True</code> means cooperate and
<code>False</code> means defect:</p>

<pre>
my %scoring =
    'True True' =&gt; [4, 4],
    'True False' =&gt; [0, 6],
    'False True' =&gt; [6, 0],
    'False False' =&gt; [1, 1],
</pre>

<p>Your strategy should be a subroutine or block that accepts the named
parameters <code>mine</code> and <code>theirs</code>, which are lists
of previous decisions of your own algorithm and of its opponents, and
<code>total</code>, which is the number of laps to be played. It should
return <code>True</code> if it wishes to cooperate, and <code>False</code> to
defect.</p>

<p>Here is an example strategy that starts off with cooperating, and then
randomly chooses a previous reaction of the current opponent:</p>

<pre>
sub example-strategy(:@theirs, *%) {
    @theirs.roll // True;
}
</pre>

<p>Your strategy or strategies will play against each other and against the
example strategies in the gist above. It is not allowed to submit strategies
that commit suicide to actively support another strategy.</p>

<p>I too have written two strategies that will take participate in the
contest. Here is the checksum to convince you I won't alter the strategies
in response to the submissions:</p>

<pre>
6d4ba99b66e4963a658c8dcfc72922dd0f74e0ad  prisoner-moritz.pl
</pre>


</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/iterated-prisoners-dilemma.html</id>
  </entry>
  <entry>
    <title> Ill </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/ill" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/ill</id>
  </entry>
  <entry>
    <title> CPANdeps upgrade </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/cpandeps-upgraded-to-mysql" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/cpandeps-upgraded-to-mysql</id>
  </entry>
  <entry>
    <title>Results from the Prisoner's Dilemma Challenge</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/prisoners-dilemma-results.html" type="text/html"/>
    <summary type="text">The Iterated Prisoner's Dilemma Challenge is now closed; several
interesting solutions have been submitted.

Of the basic strategies, tit-for-tat (doing what the opponent did the
last time, starting off with cooperating) is usually the strongest. Since
the random strategy is, well, random, the results fluctuate a bit.

Most submitted strategies are a variation on tit-for-tat, modified in
some way or another to make it stronger. All submissions contained a
strategy that is stronger than tit-for-tat when tested against the basic
strategies only, though the interaction with other new strategies made
some of them come out weaker than tit-for-tat.


Submitted Strategies
--------------------

Without any further ado, here are the strategies and a few comments on
them.


Turn the Other Cheek

## Dean Serenevy; received on 2012-02-07%strategies&lt;turn-other-cheek-no-deal-with-devil-once-bit-twice-shy-variety-is-the-spice-o-life&gt; = sub (:@mine, :@theirs, *%) {
    my ($bitten, $shy, $they-coop) = (0, 0, False);
    for @mine Z @theirs -&gt; $me, $them {
        if $them          { $they-coop = True; }
        if $me and !$them { $bitten++; $shy = 0; }
        if !$me           { $shy++ }
    }

    return True  if 0 == $bitten;               # Cooperate if we have never been bitten    return True  if 1 == $bitten and 0 == $shy; # Turn the other cheek once    return False unless $they-coop;             # Screw you too!    return $shy &gt;= (2 ** ($bitten-1)).rand      # Once-bitten rand() shy};


Inevitable Betrayal

## Andrew Egeler, received 2012-02-09%strategies&lt;inevitable-betrayal&gt; = &amp;inevitable-betrayal;sub inevitable-betrayal (:@theirs, :$total, *%) { +@theirs &lt;($total-1) ?? @theirs[*-1] // True !! False }%strategies&lt;evil-inevitable-betrayal&gt; = &amp;evil-inevitable-betrayal;sub evil-inevitable-betrayal (:@theirs, :$total, *%) { +@theirs &lt;($total-1) ?? @theirs[*-1] // False !! False }

These are variations on tit-for-tat and evil-tit-for-tat which always
defect in the last round, because then the opponent can't retaliate
anymore.

In a typical Iterated Prisoner's Dilemma contest, strategies don't know
how many rounds are being played, just to avoid this behavior.


Tit for D'oh and Watch for Random

## Solomon Foster, receievd 2012-02-10%strategies&lt;tit-for-doh&gt; = -&gt; :@theirs, :$total, *% {
    @theirs &lt; $total - 1 ??  (@theirs[*-1] // True) !! False}
%strategies&lt;watch-for-random&gt; = -&gt; :@theirs, *% {
    @theirs &gt; 10 &amp;&amp; @theirs.grep(* == False) &gt; 5 ?? False !! (@theirs[*-1] // True)
};

tit-for-doh is the same as inevitable-betrayal. watch-for-random defects
forever once the opponent has defected too often.


Me

## Audrey Tang, received 2012-02-17%strategies&lt;me&gt; = -&gt; :@theirs, *% {
    my role Me {};    (@theirs[*-1] // Me).does(Me) but Me
};

This strategy uses a mixin in its returned boolean values to find out
when it plays against itself, or against a strategy that copies its
values from @theirs (ie tit-for-tat derivatives), in which case it
cooperates. This games the system, though doesn't explicitly violates the
stated rules.

Audrey also deserves two dishonorable mentions for two solutions that
game the test harness or the other strategies by exploiting the
technically imperfect sandboxing:

   au =&gt; -&gt; :@theirs, *% {
       use MONKEY_TYPING;       my role TRUE {};       augment class Bool {
           method Stringy(Bool:D:) {
               self.^does(TRUE) ?? 'True' !! 'False'           }
       }
       False but TRUE;   }, 

   amnesia =&gt; -&gt; :@mine, :@theirs, *% {
       my role Uh {};       my $rv = (@theirs[*-1] // Uh).does(Uh) but Uh;       @mine = @theirs = ();       $rv;   },

Those two strategies did not compete in the tournament


Lenient in the Beginning, Then Strict

I've written my own two strategies before the tournament started. Here is
the original, I've only changed the signatures to run under current
Niecza:

# a tit for tat, but a bit more friendly at the beginning# to avoid hacking on forever on evil-tit-for-tat,# but be very stringent when the other one defects too oftensub moritz-ctft(:@theirs, :$total,  *%) {
    return True if @theirs &lt; 3;    return False if @theirs.grep(*.not).elems &gt; ($total / 10);
    @theirs[*-1];};%strategies&lt;moritz-ctft&gt; = &amp;moritz-ctft;# the evil clone...sub moritz-ectft(:@theirs, :$total,  *%) {
    return True if @theirs &lt; 3;    return False if @theirs.grep(*.not).elems &gt; ($total / 10);    # did you believe in happy ends?    return False if @theirs + 1 == $total;
    @theirs[*-1];};%strategies&lt;moritz-ectft&gt; = &amp;moritz-ectft;


Results
-------

The results vary quite a bit between runs, mostly because of the random
strategy.

Here is the output from a sample run. Please don't use this for
determining the "winner", because it is just a random sample with no
statistical significance.

SUMMARY
2588    moritz-ectft
2577    me
2560    moritz-ctft
2491    inevitable-betrayal
2483    tit-for-tat
2480    tit-for-doh
2399    turn-other-cheek-no-deal-with-devil-once-bit-twice-shy-variety-is-the-spice-o-life
2319    watch-for-random
2272    good
1876    evil-inevitable-betrayal
1862    evil-tit-for-tat
1538    random
1145    bad

You see, inevitable-betrayal and tit-for-doh are exactly the same
strategy, but the random fluctuations place them on different sides of
tit-for-tat. Which is why I won't declare a winner at all, there is
simply no fair way to determine one.

At first I was surprised how well the me strategy performed. But then I
noticed that with the given game harness, a strategy fighting against
itself counts double (once for the first copy, once for the second copy).
With only 13 strategies participating, and such close results,
harmonizing perfectly with yourself gives you a critical advantage.


Visualizations

For each strategy you can find an image that shows how it worked with or
against another strategy. Green means cooperate, red means defect, and
the height of the bar is proportional to the resulting score.

  * bad

  * evil-inevitable-betrayal

  * evil-tit-for-tat

  * good

  * inevitable-betrayal

  * me

  * moritz-ctft

  * moritz-ectft

  * random

  * tit-for-doh

  * tit-for-tat

  * turn-the-other-cheek-no-deal...

  * watch-for-random


Trying to Be Fair

In an attempt to reduce the impact of the random strategy, I've changed
it to use the same random sequence against each player (and of course
against itself, which totally skews that particular result).

Again the rankings vary between different runs of the same program, but
now at least same strategies produce mostly the same result (turn-the-other-cheek
also has a random component). An example output from such a run is

SUMMARY
2558    moritz-ectft
2543    moritz-ctft
2532    me
2457    inevitable-betrayal
2457    tit-for-doh
2445    tit-for-tat
2387    turn-other-cheek-no-deal-with-devil-once-bit-twice-shy-variety-is-the-spice-o-life
2314    watch-for-random
2248    good
1856    evil-inevitable-betrayal
1844    evil-tit-for-tat
1359    random
1100    bad


TL;DR
-----

It was a lot of fun! Thanks to everybody who submitted a strategy.</summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">

<p>The <a href="http://perlgeek.de/blog-en/perl-6/iterated-prisoners-dilemma.html">Iterated
Prisoner's Dilemma Challenge</a> is now closed; several interesting solutions
have been submitted.</p>

<p>Of the <a href="https://gist.github.com/1710688">basic strategies</a>,
<em>tit-for-tat</em> (doing what the opponent did the last time, starting off
with cooperating) is usually the strongest. Since the <em>random</em>
strategy is, well, random, the results fluctuate a bit.</p>

<p>Most submitted strategies are a variation on <em>tit-for-tat</em>,
modified in some way or another to make it stronger. All submissions
contained a strategy that is stronger than <em>tit-for-tat</em> when tested
against the basic strategies only, though the interaction with other new
strategies made some of them come out weaker than <em>tit-for-tat</em>.</p>

<h2>Submitted Strategies</h2>

<p>Without any further ado, here are the strategies and a few comments on
them.</p>

<h3>Turn the Other Cheek</h3>

<pre>
<span class="synComment">## Dean Serenevy; received on 2012-02-07</span>
<span class="synIdentifier">%strategies</span><span class="synSpecial">&lt;</span><span class="synConstant">turn-other-cheek-no-deal-with-devil-once-bit-twice-shy-variety-is-the-spice-o-life</span><span class="synSpecial">&gt;</span> <span class="synStatement">=</span> <span class="synStatement">sub</span> (<span class="synStatement">:</span><span class="synIdentifier">@mine</span><span class="synStatement">,</span> <span class="synStatement">:</span><span class="synIdentifier">@theirs</span><span class="synStatement">,</span> <span class="synStatement">*%</span>) {
    <span class="synSpecial">my</span> (<span class="synIdentifier">$bitten</span><span class="synStatement">,</span> <span class="synIdentifier">$shy</span><span class="synStatement">,</span> <span class="synIdentifier">$they-coop</span>) <span class="synStatement">=</span> (<span class="synConstant">0</span><span class="synStatement">,</span> <span class="synConstant">0</span><span class="synStatement">,</span> <span class="synType">False</span>)<span class="synStatement">;</span>

    <span class="synStatement">for</span> <span class="synIdentifier">@mine</span> <span class="synStatement">Z</span> <span class="synIdentifier">@theirs</span> <span class="synStatement">-&gt;</span> <span class="synIdentifier">$me</span><span class="synStatement">,</span> <span class="synIdentifier">$them</span> {
        <span class="synStatement">if</span> <span class="synIdentifier">$them</span>          { <span class="synIdentifier">$they-coop</span> <span class="synStatement">=</span> <span class="synType">True</span><span class="synStatement">;</span> }
        <span class="synStatement">if</span> <span class="synIdentifier">$me</span> <span class="synStatement">and</span> <span class="synStatement">!</span><span class="synIdentifier">$them</span> { <span class="synIdentifier">$bitten</span><span class="synStatement">++;</span> <span class="synIdentifier">$shy</span> <span class="synStatement">=</span> <span class="synConstant">0</span><span class="synStatement">;</span> }
        <span class="synStatement">if</span> <span class="synStatement">!</span><span class="synIdentifier">$me</span>           { <span class="synIdentifier">$shy</span><span class="synStatement">++</span> }
    }

    <span class="synSpecial">return</span> <span class="synType">True</span>  <span class="synStatement">if</span> <span class="synConstant">0</span> <span class="synStatement">==</span> <span class="synIdentifier">$bitten</span><span class="synStatement">;</span>               <span class="synComment"># Cooperate if we have never been bitten</span>
    <span class="synSpecial">return</span> <span class="synType">True</span>  <span class="synStatement">if</span> <span class="synConstant">1</span> <span class="synStatement">==</span> <span class="synIdentifier">$bitten</span> <span class="synStatement">and</span> <span class="synConstant">0</span> <span class="synStatement">==</span> <span class="synIdentifier">$shy</span><span class="synStatement">;</span> <span class="synComment"># Turn the other cheek once</span>
    <span class="synSpecial">return</span> <span class="synType">False</span> <span class="synStatement">unless</span> <span class="synIdentifier">$they-coop</span><span class="synStatement">;</span>             <span class="synComment"># Screw you too!</span>
    <span class="synSpecial">return</span> <span class="synIdentifier">$shy</span> <span class="synStatement">&gt;=</span> (<span class="synConstant">2</span> <span class="synStatement">**</span> (<span class="synIdentifier">$bitten</span><span class="synStatement">-</span><span class="synConstant">1</span>))<span class="synStatement">.</span><span class="synIdentifier">rand</span>      <span class="synComment"># Once-bitten rand() shy</span>
}<span class="synStatement">;</span>

</pre>

<h3>Inevitable Betrayal</h3>

<pre>
<span class="synComment">## Andrew Egeler, received 2012-02-09</span>

<span class="synIdentifier">%strategies</span><span class="synSpecial">&lt;</span><span class="synConstant">inevitable-betrayal</span><span class="synSpecial">&gt;</span> <span class="synStatement">=</span> <span class="synIdentifier">&amp;inevitable-betrayal</span><span class="synStatement">;</span>
<span class="synStatement">sub</span> inevitable-betrayal (<span class="synStatement">:</span><span class="synIdentifier">@theirs</span><span class="synStatement">,</span> <span class="synStatement">:</span><span class="synIdentifier">$total</span><span class="synStatement">,</span> <span class="synStatement">*%</span>) { <span class="synStatement">+</span><span class="synIdentifier">@theirs</span> <span class="synSpecial">&lt;</span>
<span class="synConstant">($total-1) ?? @theirs[*-1] // True !! False }</span>

<span class="synConstant">%strategies&lt;evil-inevitable-betrayal&gt; = &amp;evil-inevitable-betrayal;</span>
<span class="synConstant">sub evil-inevitable-betrayal (:@theirs, :$total, *%) { +@theirs &lt;</span>
<span class="synConstant">($total-1) ?? @theirs[*-1] // False !! False }</span>
</pre>

<p>These are variations on <em>tit-for-tat</em> and <em>evil-tit-for-tat</em>
which always defect in the last round, because then the opponent can't
retaliate anymore.</p>

<p>In a typical Iterated Prisoner's Dilemma contest, strategies don't know how
many rounds are being played, just to avoid this behavior.</p>

<h3>Tit for D'oh and Watch for Random</h3>

<pre>
<span class="synComment">## Solomon Foster, receievd 2012-02-10</span>

<span class="synIdentifier">%strategies</span><span class="synSpecial">&lt;</span><span class="synConstant">tit-for-doh</span><span class="synSpecial">&gt;</span> <span class="synStatement">=</span> <span class="synStatement">-&gt;</span> <span class="synStatement">:</span><span class="synIdentifier">@theirs</span><span class="synStatement">,</span> <span class="synStatement">:</span><span class="synIdentifier">$total</span><span class="synStatement">,</span> <span class="synStatement">*%</span> {
    <span class="synIdentifier">@theirs</span> <span class="synStatement">&lt;</span> <span class="synIdentifier">$total</span> <span class="synStatement">-</span> <span class="synConstant">1</span> <span class="synStatement">??</span>  (<span class="synIdentifier">@theirs</span>[<span class="synStatement">*-</span><span class="synConstant">1</span>] <span class="synStatement">//</span> <span class="synType">True</span>) <span class="synStatement">!!</span> <span class="synType">False</span>
}

<span class="synIdentifier">%strategies</span><span class="synSpecial">&lt;</span><span class="synConstant">watch-for-random</span><span class="synSpecial">&gt;</span> <span class="synStatement">=</span> <span class="synStatement">-&gt;</span> <span class="synStatement">:</span><span class="synIdentifier">@theirs</span><span class="synStatement">,</span> <span class="synStatement">*%</span> {
    <span class="synIdentifier">@theirs</span> <span class="synStatement">&gt;</span> <span class="synConstant">10</span> <span class="synStatement">&amp;&amp;</span> <span class="synIdentifier">@theirs</span><span class="synStatement">.</span><span class="synIdentifier">grep</span>(<span class="synStatement">*</span> <span class="synStatement">==</span> <span class="synType">False</span>) <span class="synStatement">&gt;</span> <span class="synConstant">5</span> <span class="synStatement">??</span> <span class="synType">False</span> <span class="synStatement">!!</span> (<span class="synIdentifier">@theirs</span>[<span class="synStatement">*-</span><span class="synConstant">1</span>] <span class="synStatement">//</span> <span class="synType">True</span>)
}<span class="synStatement">;</span>
</pre>

<p><em>tit-for-doh</em> is the same as <em>inevitable-betrayal</em>.
<em>watch-for-random</em> defects forever once the opponent has defected too
often.</p>

<h3>Me</h3>

<pre>
<span class="synComment">## Audrey Tang, received 2012-02-17</span>
<span class="synIdentifier">%strategies</span><span class="synSpecial">&lt;</span><span class="synConstant">me</span><span class="synSpecial">&gt;</span> <span class="synStatement">=</span> <span class="synStatement">-&gt;</span> <span class="synStatement">:</span><span class="synIdentifier">@theirs</span><span class="synStatement">,</span> <span class="synStatement">*%</span> {
    <span class="synSpecial">my</span> <span class="synStatement">role</span> Me {}<span class="synStatement">;</span>
    (<span class="synIdentifier">@theirs</span>[<span class="synStatement">*-</span><span class="synConstant">1</span>] <span class="synStatement">//</span> Me)<span class="synStatement">.</span><span class="synIdentifier">does</span>(Me) <span class="synPreProc">but</span> Me
}<span class="synStatement">;</span>
</pre>

<p>This strategy uses a mixin in its returned boolean values to find out when
it plays against itself, or against a strategy that copies its values from
<code>@theirs</code> (ie tit-for-tat derivatives), in which case it cooperates.
This games the system, though doesn't explicitly violates the stated rules.</p>

<p>Audrey also deserves two dishonorable mentions for two solutions that game
the test harness or the other strategies by exploiting the technically
imperfect sandboxing:</p>

<pre>
   <span class="synConstant">au</span> <span class="synStatement">=&gt;</span> <span class="synStatement">-&gt;</span> <span class="synStatement">:</span><span class="synIdentifier">@theirs</span><span class="synStatement">,</span> <span class="synStatement">*%</span> {
       <span class="synPreProc">use</span> MONKEY_TYPING<span class="synStatement">;</span>
       <span class="synSpecial">my</span> <span class="synStatement">role</span> TRUE {}<span class="synStatement">;</span>
       <span class="synPreProc">augment</span> <span class="synStatement">class</span> <span class="synType">Bool</span> {
           <span class="synStatement">method</span> Stringy(<span class="synType">Bool</span><span class="synStatement">:</span><span class="synConstant">D</span><span class="synStatement">:</span>) {
               <span class="synIdentifier">self</span><span class="synStatement">.^</span><span class="synIdentifier">does</span>(TRUE) <span class="synStatement">??</span> <span class="synSpecial">'</span><span class="synConstant">True</span><span class="synSpecial">'</span> <span class="synStatement">!!</span> <span class="synSpecial">'</span><span class="synConstant">False</span><span class="synSpecial">'</span>
           }
       }
       <span class="synType">False</span> <span class="synPreProc">but</span> TRUE<span class="synStatement">;</span>
   }<span class="synStatement">,</span> 

   <span class="synConstant">amnesia</span> <span class="synStatement">=&gt;</span> <span class="synStatement">-&gt;</span> <span class="synStatement">:</span><span class="synIdentifier">@mine</span><span class="synStatement">,</span> <span class="synStatement">:</span><span class="synIdentifier">@theirs</span><span class="synStatement">,</span> <span class="synStatement">*%</span> {
       <span class="synSpecial">my</span> <span class="synStatement">role</span> Uh {}<span class="synStatement">;</span>
       <span class="synSpecial">my</span> <span class="synIdentifier">$rv</span> <span class="synStatement">=</span> (<span class="synIdentifier">@theirs</span>[<span class="synStatement">*-</span><span class="synConstant">1</span>] <span class="synStatement">//</span> Uh)<span class="synStatement">.</span><span class="synIdentifier">does</span>(Uh) <span class="synPreProc">but</span> Uh<span class="synStatement">;</span>
       <span class="synIdentifier">@mine</span> <span class="synStatement">=</span> <span class="synIdentifier">@theirs</span> <span class="synStatement">=</span> ()<span class="synStatement">;</span>
       <span class="synIdentifier">$rv</span><span class="synStatement">;</span>
   }<span class="synStatement">,</span>
</pre>

<p>Those two strategies did not compete in the tournament</p>

<h3>Lenient in the Beginning, Then Strict</h3>

<p>I've written my own two strategies before the tournament started. <a href="http://moritz.faui2k3.org/files/prisoner-moritz.pl.txt">Here is the
original</a>, I've only changed the signatures to run under current
Niecza:</p>

<pre>
<span class="synComment"># a tit for tat, but a bit more friendly at the beginning</span>
<span class="synComment"># to avoid hacking on forever on evil-tit-for-tat,</span>
<span class="synComment"># but be very stringent when the other one defects too often</span>
<span class="synStatement">sub</span> moritz-ctft(<span class="synStatement">:</span><span class="synIdentifier">@theirs</span><span class="synStatement">,</span> <span class="synStatement">:</span><span class="synIdentifier">$total</span><span class="synStatement">,</span>  <span class="synStatement">*%</span>) {
    <span class="synSpecial">return</span> <span class="synType">True</span> <span class="synStatement">if</span> <span class="synIdentifier">@theirs</span> <span class="synStatement">&lt;</span> <span class="synConstant">3</span><span class="synStatement">;</span>
    <span class="synSpecial">return</span> <span class="synType">False</span> <span class="synStatement">if</span> <span class="synIdentifier">@theirs</span><span class="synStatement">.</span><span class="synIdentifier">grep</span>(<span class="synStatement">*.</span><span class="synIdentifier">not</span>)<span class="synStatement">.</span><span class="synIdentifier">elems</span> <span class="synStatement">&gt;</span> (<span class="synIdentifier">$total</span> <span class="synStatement">/</span> <span class="synConstant">10</span>)<span class="synStatement">;</span>

    <span class="synIdentifier">@theirs</span>[<span class="synStatement">*-</span><span class="synConstant">1</span>]<span class="synStatement">;</span>
}<span class="synStatement">;</span>
<span class="synIdentifier">%strategies</span><span class="synSpecial">&lt;</span><span class="synConstant">moritz-ctft</span><span class="synSpecial">&gt;</span> <span class="synStatement">=</span> <span class="synIdentifier">&amp;moritz-ctft</span><span class="synStatement">;</span>

<span class="synComment"># the evil clone...</span>
<span class="synStatement">sub</span> moritz-ectft(<span class="synStatement">:</span><span class="synIdentifier">@theirs</span><span class="synStatement">,</span> <span class="synStatement">:</span><span class="synIdentifier">$total</span><span class="synStatement">,</span>  <span class="synStatement">*%</span>) {
    <span class="synSpecial">return</span> <span class="synType">True</span> <span class="synStatement">if</span> <span class="synIdentifier">@theirs</span> <span class="synStatement">&lt;</span> <span class="synConstant">3</span><span class="synStatement">;</span>
    <span class="synSpecial">return</span> <span class="synType">False</span> <span class="synStatement">if</span> <span class="synIdentifier">@theirs</span><span class="synStatement">.</span><span class="synIdentifier">grep</span>(<span class="synStatement">*.</span><span class="synIdentifier">not</span>)<span class="synStatement">.</span><span class="synIdentifier">elems</span> <span class="synStatement">&gt;</span> (<span class="synIdentifier">$total</span> <span class="synStatement">/</span> <span class="synConstant">10</span>)<span class="synStatement">;</span>
    <span class="synComment"># did you believe in happy ends?</span>
    <span class="synSpecial">return</span> <span class="synType">False</span> <span class="synStatement">if</span> <span class="synIdentifier">@theirs</span> <span class="synStatement">+</span> <span class="synConstant">1</span> <span class="synStatement">==</span> <span class="synIdentifier">$total</span><span class="synStatement">;</span>

    <span class="synIdentifier">@theirs</span>[<span class="synStatement">*-</span><span class="synConstant">1</span>]<span class="synStatement">;</span>
}<span class="synStatement">;</span>
<span class="synIdentifier">%strategies</span><span class="synSpecial">&lt;</span><span class="synConstant">moritz-ectft</span><span class="synSpecial">&gt;</span> <span class="synStatement">=</span> <span class="synIdentifier">&amp;moritz-ectft</span><span class="synStatement">;</span>
</pre>

<h2>Results</h2>

<p>The results vary quite a bit between runs, mostly because of the
<em>random</em> strategy.</p>

<p>Here is the output from a sample run. Please don't use this for
determining the "winner", because it is just a random sample with no
statistical significance.</p>

<pre>
SUMMARY
2588    moritz-ectft
2577    me
2560    moritz-ctft
2491    inevitable-betrayal
2483    tit-for-tat
2480    tit-for-doh
2399    turn-other-cheek-no-deal-with-devil-once-bit-twice-shy-variety-is-the-spice-o-life
2319    watch-for-random
2272    good
1876    evil-inevitable-betrayal
1862    evil-tit-for-tat
1538    random
1145    bad
</pre>

<p>You see, <em>inevitable-betrayal</em> and <em>tit-for-doh</em> are exactly
the same strategy, but the random fluctuations place them on different sides
of <em>tit-for-tat</em>. Which is why I won't declare a winner at all, there
is simply no fair way to determine one.</p>

<p>At first I was surprised how well the <em>me</em> strategy performed. But
then I noticed that with the given game harness, a strategy fighting against
itself counts double (once for the first copy, once for the second copy). With
only 13 strategies participating, and such close results, harmonizing
perfectly with yourself gives you a critical advantage.</p>

<h3>Visualizations</h3>

<p>For each strategy you can find an image that shows how it worked with or
against another strategy. Green means cooperate, red means defect, and the
height of the bar is proportional to the resulting score.</p>

<ul>
    <li><a href="http://perlgeek.de/images/blog/prisoner/bad.png">bad</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/evil-inevitable-betrayal.png" width="566" height="1248">evil-inevitable-betrayal</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/evil-tit-for-tat.png">evil-tit-for-tat</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/good.png">good</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/inevitable-betrayal.png">inevitable-betrayal</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/me.png">me</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/moritz-ctft.png">moritz-ctft</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/moritz-ectft.png">moritz-ectft</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/random.png">random</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/tit-for-doh.png">tit-for-doh</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/tit-for-tat.png">tit-for-tat</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/turn-other-cheek-no-deal.png">turn-the-other-cheek-no-deal...</a></li>
    <li><a href="http://perlgeek.de/images/blog/prisoner/watch-for-random.png">watch-for-random</a></li>
</ul>

<h3>Trying to Be Fair</h3>

<p>In an attempt to reduce the impact of the <em>random</em> strategy, I've
changed it to use the same random sequence against each player (and of course
against itself, which totally skews that particular result).</p>

<p>Again the rankings vary between different runs of the same program, but now
at least same strategies produce mostly the same result
(<em>turn-the-other-cheek</em> also has a random component). An example output
from such a run is</p>

<pre>
SUMMARY
2558    moritz-ectft
2543    moritz-ctft
2532    me
2457    inevitable-betrayal
2457    tit-for-doh
2445    tit-for-tat
2387    turn-other-cheek-no-deal-with-devil-once-bit-twice-shy-variety-is-the-spice-o-life
2314    watch-for-random
2248    good
1856    evil-inevitable-betrayal
1844    evil-tit-for-tat
1359    random
1100    bad
</pre>

<h2>TL;DR</h2>

<p>It was a lot of fun! Thanks to everybody who submitted a strategy.</p>


</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/prisoners-dilemma-results.html</id>
  </entry>
  <entry>
    <title>Rakudo Hack: Dynamic Export Lists</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/2012-rakudo-hack-dynamic-export-lists.html" type="text/html"/>
    <summary type="text">Rakudo's meta programming capabilities are very good when it comes to
objects, classes and methods. But sometimes people want to generate
subroutines on the fly and use them, and can't seem to find a way to do
it.

The problem is that subroutines are usually stored (and looked up from)
in the lexical pad (ie the same as my-variables), and those lexpads are
immutable at run time.

Today I found a solution that lets you dynamically install subroutines
with a computed name into a module, and you can then use that module from
elsewhere, and have all the generated subroutines available.

module A {
    BEGIN {
        my $name = 'foo';        my $x = sub { say 'OH HAI from &amp;foo' }
                but role { method name { $name } };        trait_mod:&lt;is&gt;(:export, $x);    }
}

Inside the module first we need a BEGIN block, so that the is export
trait will run while the module is being compiled, and thus knows which
module to associate the subroutine to.

Next comes the actual code object that is to be installed. Since the
export trait inspects the name of the subroutine, we need to give it one.
Doing that dynamically can be done by overriding the name method, here by
mixing in a role with such a method into the code object.

Finally comes the part where the export trait is applied. The code here
uses knowledge of the calling conventions that hide behind a trait.

A different script can then write

use A;foo();

And access the dynamically exported sub just like any other.

In future there will hopefully be much nicer APIs for this kind of
fiddling, but for now I'm glad that a workaround has been found.</summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">

<p>Rakudo's meta programming capabilities are very good when it comes to
objects, classes and methods. But sometimes people want to generate
subroutines on the fly and use them, and can't seem to find a way to do
it.</p>

<p>The problem is that subroutines are usually stored (and looked up from) in
the lexical pad (ie the same as <code>my</code>-variables), and those lexpads
are immutable at run time.</p>

<p>Today I found a solution that lets you dynamically install subroutines with
a computed name into a module, and you can then <code>use</code> that module
from elsewhere, and have all the generated subroutines available.</p>

<pre>
<span class="synStatement">module</span> A {
    <span class="synPreProc">BEGIN</span> {
        <span class="synSpecial">my</span> <span class="synIdentifier">$name</span> <span class="synStatement">=</span> <span class="synSpecial">'</span><span class="synConstant">foo</span><span class="synSpecial">'</span><span class="synStatement">;</span>
        <span class="synSpecial">my</span> <span class="synIdentifier">$x</span> <span class="synStatement">=</span> <span class="synStatement">sub</span> { <span class="synIdentifier">say</span> <span class="synSpecial">'</span><span class="synConstant">OH HAI from &amp;foo</span><span class="synSpecial">'</span> }
                <span class="synPreProc">but</span> <span class="synStatement">role</span> { <span class="synStatement">method</span> <span class="synIdentifier">name</span> { <span class="synIdentifier">$name</span> } }<span class="synStatement">;</span>
        trait_mod<span class="synStatement">:</span><span class="synSpecial">&lt;</span><span class="synConstant">is</span><span class="synSpecial">&gt;</span>(<span class="synStatement">:</span><span class="synConstant">export</span><span class="synStatement">,</span> <span class="synIdentifier">$x</span>)<span class="synStatement">;</span>
    }
}
</pre>

<p>Inside the module first we need a <code>BEGIN</code> block, so that the
<code>is export</code> trait will run while the module is being compiled, and
thus knows which module to associate the subroutine to.</p>

<p>Next comes the actual code object that is to be installed. Since the
<code>export</code> trait inspects the name of the subroutine, we need to give
it one. Doing that dynamically can be done by overriding the <code>name</code>
method, here by mixing in a role with such a method into the code object.</p>

<p>Finally comes the part where the export trait is applied. The code here
uses knowledge of the calling conventions that hide behind a trait.</p>

<p>A different script can then write</p>

<pre>
<span class="synPreProc">use</span> A<span class="synStatement">;</span>
foo()<span class="synStatement">;</span>
</pre>

<p>And access the dynamically exported sub just like any other.</p>

<p>In future there will hopefully be much nicer APIs for this kind of
fiddling, but for now I'm glad that a workaround has been found.</p>


</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/2012-rakudo-hack-dynamic-export-lists.html</id>
  </entry>
  <entry>
    <title> YAPC::Europe 2006 report: day 3 </title>
    <link rel="alternate" href=" http://www.cantrell.org.uk/david/journal/id/yapc-europe-2006-day-3" type="text/html"/>
    <author>
      <name>nobody</name>
    </author>
    <id>tag:perlsphere.net,2006: http://www.cantrell.org.uk/david/journal/id/yapc-europe-2006-day-3</id>
  </entry>
  <entry>
    <title>Third Grant Report: Structured Error Messages</title>
    <link rel="alternate" href="http://perlgeek.de/blog-en/perl-6/grant-report-errors-3.html" type="text/html"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Progress on my grant for error message is slower than expected, as
expected :-). Yes, you've read that sentence before.

In the past months, general hacking on the nom branch of Rakudo was just
too much fun -- and partially a prerequisite for the exceptions work.

I did manage to redo the backtraces that are generated from error
messages.

Backtraces are now generated mostly in Perl 6 code, making them much more
hackable. There's a Backtrace class, which is a list of Backtrace::Frame
objects, each knowing the code object associated with it, as well as line
number and file. (This is both specced and works in Rakudo)

Routines can have the is hidden_from_backtrace trait, which makes them
not show up in the default backtrace stringification (one can still
request a .full string representation). This is useful for routines which
are internally used to generate exceptions, like die().

Rakudo also has a --ll-exceptions command line option which provides
PIR-level backtraces, in the rare case the Perl 6 level backtraces hide
too much information.

I've also started the nom-exceptions branch in Rakudo, which aims at
lifting current limitations in Rakudo's exception handling. Currently
die() and friends generate a parrot exception, and then there's a routine
that fills the error variable $!. This routine generates a new Exception
object, and sticks the parrot exception into it.

This practice means that if you create a subclass of Exception,
instantiate it and throw it, you still only get an Exception in the error
handler, not an object of the subclass. Since the actual exception type
is very important for the ongoing work, that has to change. The branch
mentioned earlier allows one to generate a Perl 6 exception, and pass
that on as the payload of the parrot exception, which is then unwrapped
when filling $!.

As a proof of concept this works, but it suffers from not being robust
enough -- as it is, we could accidentally unwrap the payload of a CONTROL
exception, placing meaningless junk into $!. So this needs a bit more
work, which I plan to do this week (or next, if it proves to be more
difficult than anticipated).

As always, your feedback is very welcome.</div>
    </summary>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>Progress on my <a href="http://news.perlfoundation.org/2011/02/hague-grant-application-struct.html">grant
for error message</a> is slower than expected, as expected :-). Yes, you've
read that sentence before.</p>

<p>In the past months, general hacking on the nom branch of Rakudo was just
too much fun -- and partially a prerequisite for the exceptions work.</p>

<p>I did manage to redo the backtraces that are generated from error
messages.</p>

<p>Backtraces are now generated mostly in Perl 6 code, making them much more
hackable. There's a <code>Backtrace</code> class, which is a list of
<code>Backtrace::Frame</code> objects, each knowing the code object associated
with it, as well as line number and file. (This is both specced and works in
Rakudo)</p>

<p>Routines can have the <code>is hidden_from_backtrace</code> trait, which
makes them not show up in the default backtrace stringification (one can still
request a <code>.full</code> string representation). This is useful for
routines which are internally used to generate exceptions, like
<code>die()</code>.</p>

<p>Rakudo also has a <code>--ll-exceptions</code> command line option which
provides PIR-level backtraces, in the rare case the Perl 6 level backtraces
hide too much information.</p>

<p>I've also started the <code>nom-exceptions</code> branch in Rakudo, which
aims at lifting current limitations in Rakudo's exception handling. Currently
<code>die()</code> and friends generate a parrot exception, and then there's a
routine that fills the error variable <code>$!</code>. This routine generates
a new <code>Exception</code> object, and sticks the parrot exception into
it.</p>

<p>This practice means that if you create a subclass of
<code>Exception</code>, instantiate it and throw it, you still only get an
<code>Exception</code> in the error handler, not an object of the subclass.
Since the actual exception type is very important for the ongoing work, that
has to change. The branch mentioned earlier allows one to generate a Perl 6
exception, and pass that on as the payload of the parrot exception, which is
then unwrapped when filling <code>$!</code>.</p>

<p>As a proof of concept this works, but it suffers from not being robust
enough -- as it is, we could accidentally unwrap the payload of a
<code>CONTROL</code> exception, placing meaningless junk into <code>$!</code>.
So this needs a bit more work, which I plan to do this week (or next, if it
proves to be more difficult than anticipated).</p>

<p>As always, your feedback is very welcome.</p>


</div>
    </content>
    <author>
      <name>Moritz Lenz</name>
    </author>
    <id>tag:perlsphere.net,2006:http://perlgeek.de/blog-en/perl-6/grant-report-errors-3.html</id>
  </entry>
</feed>

