<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Moose on Peczenyj's Blog</title><link>http://pacman.blog.br/categories/moose/</link><description>Recent content in Moose 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/moose/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></channel></rss>