<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Perl on Peczenyj's Blog</title><link>http://pacman.blog.br/categories/perl/</link><description>Recent content in Perl on Peczenyj's Blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sun, 07 Apr 2013 09:55:00 +0000</lastBuildDate><atom:link href="http://pacman.blog.br/categories/perl/atom.xml" rel="self" type="application/rss+xml"/><item><title>Adding a 'dry run' capability to your Moose class with MooseX::Role::DryRunnable</title><link>http://pacman.blog.br/blog/2013/04/07/adding-a-dry-run-capability-to-your-moose-class-with-moosex-role-dryrunnable/</link><pubDate>Sun, 07 Apr 2013 09:55:00 +0000</pubDate><guid>http://pacman.blog.br/blog/2013/04/07/adding-a-dry-run-capability-to-your-moose-class-with-moosex-role-dryrunnable/</guid><description>&lt;p>A &amp;lsquo;dry run&amp;rsquo; is a testing process where the effects of a possible failure are intentionally mitigated. For example, an aerospace company may conduct a &amp;ldquo;dry run&amp;rdquo; test of a jet&amp;rsquo;s new pilot ejection seat while the jet is parked on the ground, rather than while it is in flight. Or, in software development, we can change the behavior of some methods in order to test, like avoid change data into a database (logging the action instead).&lt;/p>
&lt;p>There are many ways to implement this capability. For example, we can add an explicity return in each method and test some condition. I will show some options in this article and we will find how to use the module &lt;a href="https://metacpan.org/module/MooseX::Role::DryRunnable">MooseX::Role::DryRunnable&lt;/a> in our Moose classes (Perl).&lt;/p>
&lt;p>One simple example in Perl, reading from an environment variable &lt;code>DRY_RUN&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-perl" data-lang="perl">&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#719e07">package&lt;/span> Foo;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#719e07">sub&lt;/span> &lt;span style="color:#268bd2">bar&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	logger&lt;span style="color:#719e07">-&amp;gt;&lt;/span>debug(&lt;span style="color:#2aa198">&amp;#34;Foo::bar @_&amp;#34;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	&lt;span style="color:#719e07">return&lt;/span> &lt;span style="color:#719e07">if&lt;/span> &lt;span style="color:#268bd2">$ENV&lt;/span>{&lt;span style="color:#2aa198">&amp;#39;DRY_RUN&amp;#39;&lt;/span>};
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>	&lt;span style="color:#719e07">...&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Lazy::Bool my first module in CPAN</title><link>http://pacman.blog.br/blog/2013/01/23/lazy-bool-my-first-module-in-cpan/</link><pubDate>Wed, 23 Jan 2013 20:15:00 +0000</pubDate><guid>http://pacman.blog.br/blog/2013/01/23/lazy-bool-my-first-module-in-cpan/</guid><description>&lt;p>&lt;a href="https://metacpan.org/release/Lazy-Bool">Lazy::Bool&lt;/a> is my first module in &lt;a href="http://www.cpan.org/">CPAN&lt;/a> (The Comprehensive Perl Archive Network). It is a simple module (only 60 lines) and few methods/operators but can be useful in some situation. The source code can be found in my &lt;a href="https://github.com/peczenyj/Lazy-Bool">github&lt;/a>.&lt;/p>
&lt;p>##Example##&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-perl" data-lang="perl">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#719e07">use&lt;/span> Lazy::Bool;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#719e07">use&lt;/span> Test::More tests&lt;span style="color:#719e07">=&amp;gt;&lt;/span> &lt;span style="color:#2aa198">3&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#719e07">my&lt;/span> &lt;span style="color:#268bd2">$a&lt;/span> &lt;span style="color:#719e07">=&lt;/span> &lt;span style="color:#2aa198">6&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#719e07">my&lt;/span> &lt;span style="color:#268bd2">$b&lt;/span> &lt;span style="color:#719e07">=&lt;/span> &lt;span style="color:#2aa198">4&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#719e07">my&lt;/span> &lt;span style="color:#268bd2">$x&lt;/span> &lt;span style="color:#719e07">=&lt;/span> Lazy::Bool&lt;span style="color:#719e07">-&amp;gt;&lt;/span>&lt;span style="color:#719e07">new&lt;/span>(sub{ &lt;span style="color:#268bd2">$a&lt;/span> &lt;span style="color:#719e07">&amp;gt;&lt;/span> &lt;span style="color:#268bd2">$b&lt;/span> });
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#719e07">my&lt;/span> &lt;span style="color:#268bd2">$false&lt;/span> &lt;span style="color:#719e07">=&lt;/span> Lazy::Bool::false;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#719e07">my&lt;/span> &lt;span style="color:#268bd2">$result&lt;/span> &lt;span style="color:#719e07">=&lt;/span> (&lt;span style="color:#268bd2">$x&lt;/span> &lt;span style="color:#719e07">|&lt;/span> &lt;span style="color:#268bd2">$false&lt;/span>) &lt;span style="color:#719e07">&amp;amp;&lt;/span> ( &lt;span style="color:#719e07">!&lt;/span> ( &lt;span style="color:#268bd2">$false&lt;/span> &lt;span style="color:#719e07">&amp;amp;&lt;/span> &lt;span style="color:#719e07">!&lt;/span> &lt;span style="color:#268bd2">$false&lt;/span> ) );
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#586e75"># now the expressions will be evaluate&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ok(&lt;span style="color:#268bd2">$result&lt;/span>, &lt;span style="color:#2aa198">&amp;#34;complex expression should be true&amp;#34;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ok(&lt;span style="color:#719e07">!!&lt;/span> &lt;span style="color:#268bd2">$x&lt;/span> , &lt;span style="color:#2aa198">&amp;#34;double negation of true value should be true&amp;#34;&lt;/span>); 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ok(&lt;span style="color:#719e07">!!!&lt;/span> &lt;span style="color:#268bd2">$false&lt;/span>, &lt;span style="color:#2aa198">&amp;#34;truple negation of false value should be true&amp;#34;&lt;/span>);
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Schwartzian transform</title><link>http://pacman.blog.br/blog/2013/01/22/schwartzian-transform/</link><pubDate>Tue, 22 Jan 2013 16:00:00 +0000</pubDate><guid>http://pacman.blog.br/blog/2013/01/22/schwartzian-transform/</guid><description>&lt;p>I will show in this post one of the most useful things that I learn in Perl: the famous Schwartzian transform. With examples in Ruby&lt;/p>
&lt;blockquote>
&lt;p>In computer science, the Schwartzian transform is a Perl programming idiom used to improve the efficiency of sorting a list of items. This idiom is appropriate for comparison-based sorting when the ordering is actually based on the ordering of a certain property (the key) of the elements, where computing that property is an intensive operation that should be performed a minimal number of times. The Schwartzian Transform is notable in that it does not use named temporary arrays.&lt;/p></description></item><item><title>TDD com Perl</title><link>http://pacman.blog.br/blog/2008/05/02/tdd-com-perl/</link><pubDate>Fri, 02 May 2008 15:00:00 -0300</pubDate><guid>http://pacman.blog.br/blog/2008/05/02/tdd-com-perl/</guid><description>&lt;div class='post'>
É possivel fazer Test Driven Development com Perl? Mas claro :)&lt;br />&lt;br />Artigo interessante sobre &lt;a href="http://perldoc.perl.org/Test/More.html">Test::More&lt;/a>:&lt;br />&lt;a href="http://www.testingreflections.com/node/view/5333">http://www.testingreflections.com/node/view/5333&lt;/a>&lt;br />&lt;br />Tutorial bem sucinto:&lt;br />&lt;a href="http://www.wgz.org/chromatic/perl/IntroTestMore.pdf">http://www.wgz.org/chromatic/perl/IntroTestMore.pdf&lt;/a>&lt;br />&lt;br />Excelente apresentação:&lt;br />&lt;a href="http://wellington.pm.org/archive/200606/tdd/">http://wellington.pm.org/archive/200606/tdd/&lt;/a>&lt;/div>
&lt;h2>Comments&lt;/h2>
&lt;div class='comments'>
&lt;div class='comment'>
&lt;div class='author'>Tiago Peczenyj&lt;/div>
&lt;div class='content'>
Trabalho que é coisa séria ninguem comenta... ;-)&lt;/div>
&lt;/div>
&lt;/div></description></item></channel></rss>