<?xml version="1.0" encoding="us-ascii"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Perl</title><author><name>Thomas Klausner</name></author><link href="http://domm.plix.at/perl.xml" rel="self"/><id>http://domm.plix.at/perl.xml</id><updated>2013-05-30T12:55:41+02:00</updated><generator uri="http://search.cpan.org/dist/XML-Atom-SimpleFeed/" version="0.86">XML::Atom::SimpleFeed</generator><entry><title type="html">given &#38; smartmatch in Perl 5.18</title><link href="http://domm.plix.at/perl/2013_05_given_smartmatch.html"/><id>http://domm.plix.at/perl/2013_05_given_smartmatch.html</id><updated>2013-05-30T12:55:41+02:00</updated><category term="perl"/><summary type="html">&lt;p&gt;As you might have heard, &lt;code&gt;smartmatch&lt;/code&gt; (and thus &lt;code&gt;given/when&lt;/code&gt;) have been sort of deprecated in Perl 5.18. Well, there not really deprecated, but converted to an experimental ...</summary><content type="html">&lt;p&gt;As you might have &lt;a href=&#34;https://metacpan.org/module/RJBS/perl-5.18.0/pod/perldelta.pod#The-smartmatch-family-of-features-are-now-experimental&#34;&gt;heard&lt;/a&gt;, &lt;code&gt;smartmatch&lt;/code&gt; (and thus &lt;code&gt;given/when&lt;/code&gt;) have been sort of deprecated in &lt;a href=&#34;https://metacpan.org/module/RJBS/perl-5.18.0&#34;&gt;Perl 5.18&lt;/a&gt;. Well, there not really deprecated, but converted to an &lt;a href=&#34;https://metacpan.org/module/RJBS/perl-5.18.0/pod/perldelta.pod#New-mechanism-for-experimental-features&#34;&gt;experimental feature&lt;/a&gt; and thus issue a warning.&lt;/p&gt;

&lt;p&gt;While I understand that some cases of &lt;code&gt;smartmatch&lt;/code&gt; might be fuzzy / hard to understand, some cases are very simple, straightforward and lead to cleaner code. Especially if combined with &lt;code&gt;give/when&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But as I did not participate in the discussions on p5p regarding the perceived problems with &lt;code&gt;smartmatch&lt;/code&gt;, it&#39;s a bit late and lame to complain now (c.f. &lt;a href=&#34;https://www.youtube.com/watch?v=AxD21w3xiLk&#34;&gt;Fresse halten, selber machen&lt;/a&gt;).&lt;/p&gt;

&lt;h4&gt;Anyways...&lt;/h4&gt;

&lt;p&gt;Here is an example of some nice and simple code powered by &lt;code&gt;smartmatch&lt;/code&gt; (from &lt;a href=&#34;https://github.com/domm/Blio/blob/master/lib/Blio/Node.pm#L78-93&#34;&gt;Blio::Node&lt;/a&gt;)&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;  given ($converter) {
      when (&#39;html&#39;) { return $raw_content }
      when ([qw(textile markdown bbcode)]) {
          my $o = Markup::Unified-&#38;gt;new();
          return $o-&#38;gt;format($raw_content, &#39;textile&#39;)-&#38;gt;formatted;
      }
      default {
          my $method = &#39;convert_&#39;.$converter;
          if ($self-&#38;gt;can($method)) {
              return $self-&#38;gt;$method($raw_content);
          }
          else {
              return &#38;quot;No such converter: $converter&#38;quot;.$raw_content;
          }
      }
  }
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Here I compare a string against a string (or a list of strings, in the second &lt;code&gt;when&lt;/code&gt;). Turning this into an old-school &lt;code&gt;if-else&lt;/code&gt; block is of course possible &#38;amp; easy, but ugly.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;  if ($converter eq &#39;html&#39;) {
      return $raw_content
  }
  elsif (   $converter eq &#39;textile&#39;
         || $converter eq &#39;markdown&#39;
         || $converter eq &#39;bbcode&#39;) {
      my $o = Markup::Unified-&#38;gt;new();
      return $o-&#38;gt;format($raw_content, &#39;textile&#39;)-&#38;gt;formatted;
  }
  else {
      my $method = &#39;convert_&#39;.$converter;
      if ($self-&#38;gt;can($method)) {
          return $self-&#38;gt;$method($raw_content);
      }
      else {
          return &#38;quot;No such converter: $converter&#38;quot;.$raw_content;
      }
  }

&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;So I decided to keep the &lt;code&gt;given/when&lt;/code&gt; and use the also new(?) conditional no warnings thingy:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;no if $] &#38;gt;= 5.018, &#39;warnings&#39;, &#38;quot;experimental::feature_name&#38;quot;;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Unfortunately, there&#39;s a small error in the relevant section of perldelta, where it says&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;no if $] &#38;gt;= 5.018, &#38;quot;experimental::smartmatch&#38;quot;;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;But it should say&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;no if $] &#38;gt;= 5.018, &#39;warnings&#39;, &#38;quot;experimental::smartmatch&#38;quot;;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;I&#39;ve already submitted a &lt;a href=&#34;https://rt.perl.org/rt3//Public/Bug/Display.html?id=118249&#34;&gt;patch&lt;/a&gt; (my first contribution to the Perl core, albeit a very tiny one..)&lt;/p&gt;

&lt;h4&gt;So what&#39;s the point?&lt;/h4&gt;

&lt;p&gt;Hm, well, I just wanted to say that &lt;strong&gt;I&lt;/strong&gt; like &lt;code&gt;smartmatch&lt;/code&gt; and &lt;code&gt;given/when&lt;/code&gt; and for now will rather use the no-warnings hack than downgrade back to &lt;code&gt;if/else&lt;/code&gt;. Maybe this opinion can be considered in future discussions on &lt;code&gt;smartmatch&lt;/code&gt;.&lt;/p&gt;</content></entry><entry><title>4 TPF Grant Proposals are waiting for some review</title><link href="http://domm.plix.at/perl/2013_05_tpf_grant_proposals.html"/><id>http://domm.plix.at/perl/2013_05_tpf_grant_proposals.html</id><updated>2013-05-05T13:17:21+02:00</updated><category term="perl"/><summary type="html">&lt;p&gt;Alberto just published the 4 &lt;span class=&#34;caps&#34;&gt;TPF&lt;/span&gt; Grant proposals for Q2/2013:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span class=&#34;caps&#34;&gt;YACT &lt;/span&gt;- Yet Another Conference Tool by Torsten Raudssus (Getty)&lt;/li&gt; ...</summary><content type="html">&lt;p&gt;Alberto just published the &lt;a href=&#34;http://news.perlfoundation.org/2013/05/2013q2-grant-proposals-1.html&#34;&gt;4 &lt;span class=&#34;caps&#34;&gt;TPF&lt;/span&gt; Grant proposals for Q2/2013&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span class=&#34;caps&#34;&gt;YACT &lt;/span&gt;- Yet Another Conference Tool by Torsten Raudssus (Getty)&lt;/li&gt;
&lt;li&gt;rpm.perl.it by Jozef Kutej&lt;/li&gt;
&lt;li&gt;Review of Perl Web Frameworks by Neil Bowers&lt;/li&gt;
&lt;li&gt;Next Release of Pinto With Key Features by Jeffrey Ryan Thalhammer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It makes the life of the members of the &lt;span class=&#34;caps&#34;&gt;TPF&lt;/span&gt; Grants committee easier if the proposals get some community feedback. So please go to the &lt;span class=&#34;caps&#34;&gt;TPF &lt;/span&gt;site and leave some comments at the respective proposal pages. The grant committee has to vote until mid of May, so please submit your feedback before that.&lt;/p&gt;</content><category term="TPF"/><category term="grants"/></entry><entry><title>Bread::Board is the right tool for this job</title><link href="http://domm.plix.at/perl/2013_04_bread_board_is_the_right_rool_for_this_job.html"/><id>http://domm.plix.at/perl/2013_04_bread_board_is_the_right_rool_for_this_job.html</id><updated>2013-04-21T11:33:54+02:00</updated><category term="perl"/><summary type="html">&lt;p&gt;... with a big emphasis on &lt;strong&gt;this&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Maybe you remember my question from last week, where I asked if Bread::Board is the right tool for a project we are currently starting. ...</summary><content type="html">&lt;p&gt;... with a big emphasis on &lt;strong&gt;this&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Maybe you remember my &lt;a href=&#34;/perl/2013_04_is_bread_bord_the_right_tool.html&#34;&gt;question from last week&lt;/a&gt;, where I asked if &lt;a href=&#34;https://metacpan.org/module/Bread::Board&#34;&gt;Bread::Board&lt;/a&gt; is the right tool for a project &lt;a href=&#34;http://www.validad.com/&#34;&gt;we&lt;/a&gt; are currently starting. (If not, I&#39;ll wait until you&#39;ve read it..)&lt;/p&gt;

&lt;p&gt;I&#39;ve got some good feedback via &lt;span class=&#34;caps&#34;&gt;IRC &lt;/span&gt;and in the comments, and building on that feedback we hacked together a system that seems to work. And which I will describe now, so you might also understand Bread::Board (and most notably Parameterized Containers) better. But also to get even more feedback on potential design errors and gross misunderstandings of Bread::Board concepts that might hide in our solution.&lt;/p&gt;

&lt;h4&gt;&#34;this job&#34;&lt;/h4&gt;

&lt;p&gt;For our newest project we want to use a new approach. Instead of building a very big, monolithic &lt;a href=&#34;http://www.catalystframework.org&#34;&gt;Catalyst&lt;/a&gt; application we want to implement lots of small(-ish) apps. Each app does one thing, and does it well and well-tested. The apps talk to each other over &lt;a href=&#34;http://zeromq.org&#34;&gt;ZeroMQ&lt;/a&gt;. The apps depend on various components (0mq, &lt;span class=&#34;caps&#34;&gt;DB, &lt;/span&gt;templates, caches, ...). The components need to be initiated slightly differently in different environments (prod, dev, testing, ..).&lt;/p&gt;

&lt;p&gt;As you can see, this is a rather complex setup. And Bread::Board is the (a) right tool for complex setups.&lt;/p&gt;

&lt;h4&gt;Parameterized Containers&lt;/h4&gt;

&lt;p&gt;I took me a while to fully understand &lt;a href=&#34;https://metacpan.org/module/STEVAN/Bread-Board-0.25/lib/Bread/Board/Manual/Concepts/Advanced.pod#Parameterized-Containers&#34;&gt;parameterized containers&lt;/a&gt;. For me, the most important part was to see that you sort of &#34;pass in&#34; a container into another container, thereby naming the passed-in container. The containing container can depend on services that will be provided by the passed-in container (sort of like a method that takes a callback as an argument).&lt;/p&gt;

&lt;p&gt;Maybe a bit of code is clearer:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;my $apps = container $class =&#38;gt; [&#39;Environment&#39;] =&#38;gt; as {
        container &#39;App&#39; =&#38;gt; as {
            service &#39;renderservice_worker&#39; =&#38;gt; (
                class        =&#38;gt; &#39;OurApp::RenderService::Worker&#39;,
                dependencies =&#38;gt; {
                    coder         =&#38;gt; &#39;/Environment/json_coder&#39;,
                    renderer      =&#38;gt; &#39;/Component/Renderer/TTnowrap&#39;,
                }
            );
        };
        container &#39;Component&#39; =&#38;gt; as {
            container &#39;Renderer&#39; =&#38;gt; as {
                service &#39;TTnowrap&#39; =&#38;gt; (
                    lifecycle =&#38;gt; &#38;quot;Singleton&#38;quot;,
                    class     =&#38;gt; &#39;Template::AutoFilter&#39;,
                    block     =&#38;gt; sub {
                        return Template::AutoFilter-&#38;gt;new( ... );
                    },
                );
            };
        };
   };
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Or maybe not, so I&#39;ll explain that a bit...&lt;/p&gt;

&lt;p&gt;In the above code snippet, I have set up Bread::Board container. A container is some sort of namespace that includes services. A service defines a way to initiate an object that is needed by the application.&lt;/p&gt;

&lt;p&gt;Here I only define on app, &#34;OurApp::RenderService::Worker&#34;. This app is a worker process that can render something. We plan to start lots of those (on different machines), so we can easily scale our app. The RenderService::Worker (well, the trimmed down version I use for this example) needs two objects: a &lt;code&gt;coder&lt;/code&gt; to en/decode &lt;span class=&#34;caps&#34;&gt;JSON &lt;/span&gt;and a &lt;code&gt;renderer&lt;/code&gt; (in this case Template::Toolkit).&lt;/p&gt;

&lt;p&gt;Besides the &lt;code&gt;App&lt;/code&gt;-namespace we also define a &lt;code&gt;Component&lt;/code&gt;-namespace (i.e. container). This container contains another container, containing a service, &lt;code&gt;TTnowrap&lt;/code&gt; (this service has some more dependencies (eg &lt;span class=&#34;caps&#34;&gt;INCLUDE&lt;/span&gt;_PATH) that I removed for the sake of a &#34;simple&#34; example).&lt;/p&gt;

&lt;p&gt;In other parts of our Bread::Board, we can address this service as &lt;code&gt;/Component/Renderer/TTnowrap&lt;/code&gt;. We can get to the RenderService::Worker via &lt;code&gt;/App/renderservice_worker&lt;/code&gt;. And there we can depend on &lt;code&gt;TTnowrap&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But we also depend on something called &lt;code&gt;/Environment/json_coder&lt;/code&gt;. Which is nowhere to be found (yet). Well, in fact parts of it are already found (if you look at the first line of my example):&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;my $apps = container $class =&#38;gt; [&#39;Environment&#39;] =&#38;gt; as {
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Here we tell Bread::Board that the container we&#39;re setting up takes another container as a parameter, and that the services defined in the container shall be accessible as &lt;code&gt;/Environment&lt;/code&gt; in the containers and services we&#39;re just going to set up.&lt;/p&gt;

&lt;p&gt;So we &lt;strong&gt;promise&lt;/strong&gt; the container that later there will be a container named &lt;code&gt;Environment&lt;/code&gt;, but just now we&#39;re very sorry, and we just don&#39;t know what exactly this container will contain.&lt;/p&gt;

&lt;h4&gt;The Parameter Container&lt;/h4&gt;

&lt;p&gt;So let&#39;s fulfill that promise:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;my $env = container $self =&#38;gt; as {
    service &#39;json_coder&#39; =&#38;gt; (
        class     =&#38;gt; &#39;JSON::XS&#39;,
        lifecycle =&#38;gt; &#39;Singleton&#39;,
        block     =&#38;gt; sub {
            return JSON::XS-&#38;gt;new-&#38;gt;utf8-&#38;gt;pretty-&#38;gt;allow_nonref;
        },
    );
};
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Now we create our final Bread::Board (i.e. the mix of general definitions and the environment):&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;my $bb = $apps-&#38;gt;create( &#39;Environment&#39; =&#38;gt; $env );&lt;/code&gt;&lt;/pre&gt;



&lt;h4&gt;Running the App&lt;/h4&gt;

&lt;p&gt;To initiate a new RenderService::Worker, we can now do:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;my $worker = $bb-&#38;gt;resolve( service =&#38;gt; &#38;quot;App/renderservice_worker&#38;quot; );
$worker-&#38;gt;run;
&lt;/code&gt;&lt;/pre&gt;



&lt;h4&gt;Putting it all together&lt;/h4&gt;

&lt;p&gt;We have on class, &lt;code&gt;OurApp::BreadBoard&lt;/code&gt;. In this class we define all our &lt;code&gt;Apps&lt;/code&gt; and all our &lt;code&gt;Components&lt;/code&gt; in one big Bread::Board that expects one container as a parameter. This container is named &lt;code&gt;Environment&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For each environment, we have a class (eg &lt;code&gt;OurApp::BreadBoard::Env::Dev&lt;/code&gt;). In this class we provide the services that are &#34;missing&#34; in the general Bread::Board. They are missing because they are different for each environment.&lt;/p&gt;

&lt;p&gt;Again in &lt;code&gt;OurApp::BreadBoard&lt;/code&gt; we have a method called &lt;code&gt;setup&lt;/code&gt; that looks sort of like this:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;sub setup {
    my ( $class, $env_class_name) = @_;

    my $env_class = &#39;OurApp::BreadBoard::Env::&#39; . $env_class_name;
    Class::Load::load_class($env_class);
    my $env = $env_class-&#38;gt;new( name =&#38;gt; $env_class_name );

    my $apps = container $class =&#38;gt; [&#39;Environment&#39;] =&#38;gt; as {
        ... # define all Apps and all Components
    }

    return $apps-&#38;gt;create( &#39;Environment&#39; =&#38;gt; $env );
}
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;So in our scripts we can do:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;use OurApp::BreadBoard;

my $env = $ARGV[0] || $ENV{BB} || &#39;Dev&#39;;

my $bb  = OurApp::BreadBoard-&#38;gt;setup( $env );
my $app = $bb-&#38;gt;resolve( service =&#38;gt; &#38;quot;App/render_worker&#38;quot; );
$app-&#38;gt;run;
&lt;/code&gt;&lt;/pre&gt;



&lt;h4&gt;Problem: Command Line Params&lt;/h4&gt;

&lt;p&gt;There is still one problem that I have: We can now no longer use &lt;a href=&#34;https://metacpan.org/module/MooseX::Getopt&#34;&gt;MooseX::Getopt&lt;/a&gt; to make different options needed by different apps settable from the command line. It might be possible to solve that via &lt;code&gt;parameters&lt;/code&gt; in Bread::Board (something completely different than parameterized containers!), but I haven&#39;t looked into this yet.&lt;/p&gt;

&lt;h4&gt;But there&#39;s more&lt;/h4&gt;

&lt;p&gt;Even though this example isn&#39;t really simple, it is still to simple to see the real benefit of Bread::Board. I will go into further detail in some future blog posts. &lt;/p&gt;

&lt;p&gt;I also did not cover how we are using &lt;code&gt;alias&lt;/code&gt; for fun and profit. Another nice side effect of Bread::Board is that we unified our scripts (and in fact replaced all of them with one script to rule them all) (which also explains why the services in &lt;code&gt;Apps&lt;/code&gt; have lowercase names instead of CamelCase).&lt;/p&gt;

&lt;p&gt;Stay tuned...&lt;/p&gt;</content><category term="Bread::Board"/><category term="architecture"/></entry><entry><title>Is Bread::Board the right tool for this job?</title><link href="http://domm.plix.at/perl/2013_04_is_bread_bord_the_right_tool.html"/><id>http://domm.plix.at/perl/2013_04_is_bread_bord_the_right_tool.html</id><updated>2013-04-12T11:28:23+02:00</updated><category term="perl"/><summary type="html">&lt;p&gt;This post is a question / cry for help!&lt;/p&gt;

&lt;p&gt;We&#39;re currently working on a new app that&#39;s going to need several components (web frontend, web admin interface, lots of small to big workers ...</summary><content type="html">&lt;p&gt;This post is a question / cry for help!&lt;/p&gt;

&lt;p&gt;We&#39;re currently working on a new app that&#39;s going to need several components (web frontend, web admin interface, lots of small to big workers connected via &lt;a href=&#34;/tags/ZeroMQ.html&#34;&gt;ZeroMQ&lt;/a&gt;, cron jobs, ...). These components need to access various other services (DB, logging, templates, caches, ..). &lt;br /&gt;
So instead of defining these services in lazy_build attributes that live in roles and are applied to the components, we though we&#39;d give &lt;a href=&#34;https://metacpan.org/module/Bread::Board&#34;&gt;Bread::Board&lt;/a&gt; a try. We also consider to use &lt;a href=&#34;https://metacpan.org/module/OX&#34;&gt;OX&lt;/a&gt; instead of &lt;a href=&#34;http://www.catalystframework.org&#34;&gt;Catalyst&lt;/a&gt;, and OX uses (no, is) Bread::Board.&lt;/p&gt;

&lt;p&gt;Our idea is to define a set of services (DB, templates, ..) and their dependencies. Each component would also be a service (or a container?) and depend on the services it needs.&lt;/p&gt;

&lt;p&gt;In a script that runs a worker, we could then do:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;use OurApp::BreadBoard;
my $bb = OurApp::BreadBoard-&#38;gt;new( name=&#38;gt;&#39;SomeWorker&#39; );
my $app = $bb-&#38;gt;resolve( service =&#38;gt; &#39;Apps/some_worker&#39; );
$app-&#38;gt;run;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This seems to work.&lt;/p&gt;

&lt;h4&gt;But...&lt;/h4&gt;

&lt;p&gt;We have different environments: &lt;code&gt;production&lt;/code&gt;, &lt;code&gt;development&lt;/code&gt;, &lt;code&gt;testing&lt;/code&gt;, ...&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;production&lt;/code&gt;, the workers are distributed over several different machines. They use some fancy 0mq service discovery to figure out where to connect to. &lt;/p&gt;

&lt;p&gt;In &lt;code&gt;development&lt;/code&gt; we want all the workers to run on the same machine. So we need a trimmed-down version of the service discovery. We also want to use different databases. Log somewhere else. etc&lt;/p&gt;

&lt;p&gt;So how can we tell Bread::Board to use different services (or to create the same services differently)?&lt;/p&gt;

&lt;h4&gt;Parameters&lt;/h4&gt;

&lt;p&gt;You can pass parameters to a service when you resolve it:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;https://metacpan.org/source/STEVAN/Bread-Board-0.25/t/041_parameter_cache_handling.t
line 41:   $c-&#38;gt;resolve( service =&#38;gt; &#39;foo&#39;, parameters =&#38;gt; { bar =&#38;gt; 10 } );
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;But it does not seem to be possible to pass a parameter to &lt;span class=&#34;caps&#34;&gt;ALL &lt;/span&gt;services, at least if I understand &lt;a href=&#34;https://rt.cpan.org/Public/Bug/Display.html?id=77229&#34;&gt;Bug #77229&lt;/a&gt; correctly.&lt;/p&gt;

&lt;p&gt;Stevans suggestion to just also resolve the dependency might work, but is sure very ugly (especially if you need to do it on several services/deps). I could just as well generate the objects myself and pass them around...&lt;/p&gt;

&lt;h4&gt;Bread::Board::Container::Parameterized&lt;/h4&gt;

&lt;p&gt;I cannot even tell is this might be a solution because it lacks docs, and I cannot figure out what it should do from the tests.&lt;/p&gt;

&lt;h4&gt;Moose attribute&lt;/h4&gt;

&lt;p&gt;Bread::Board is based on Moose. So we can add a regular attribute to our Bread::Board class and use this to discern the environments:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;package Our::BreadBoard;
use Moose;
use Bread::Board::Declare;
has &#39;+name&#39; =&#38;gt; ( is =&#38;gt; &#39;ro&#39;, default =&#38;gt; &#38;quot;DefaultName&#38;quot; );

has &#39;environment&#39; =&#38;gt; (
    is      =&#38;gt; &#39;ro&#39;,
    isa     =&#38;gt; &#39;Str&#39;,
    default =&#38;gt; &#39;production&#39;,
    service =&#38;gt; 0,
);
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;&lt;code&gt;service =&#38;gt; 0&lt;/code&gt; seems to be crucial here, because this tells Bread::Board::Declare that this attribute is just a plain Moose attrib and no Bread::Board service.&lt;/p&gt;

&lt;p&gt;Now I can access this attribute in the blocks building my objects (but accessing it isn&#39;t that easy, either..):&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;package OurApp::BreadBoard;
use Moose;
use Bread::Board::Declare;

has &#39;zmq_service_discovery&#39; =&#38;gt; (
    is    =&#38;gt; &#39;ro&#39;,
    isa   =&#38;gt; &#39;OurApp::ServiceDiscovery&#39;,
    block =&#38;gt; sub {
        my ($service, $container) = @_;
        my $root = $container-&#38;gt;fetch(&#39;/&#39;);

        if ($root-&#38;gt;environment eq &#39;production&#39;) {
            return OurApp::ServiceDiscovery::Distributed;
            # or:
            # return OurApp::ServiceDiscover-&#38;gt;new(
            #     mode =&#38;gt; &#39;distributed&#39;
            # );
        }
        else {
            return OurApp::ServiceDiscovery::Local;
        }
    },
);

has &#39;some_worker&#39; =&#38;gt; (
    is  =&#38;gt; &#39;ro&#39;,
    isa =&#38;gt; &#39;OurApp::Some::Worker&#39;,
    dependencies =&#38;gt; {
        service_discoverer =&#38;gt; &#39;zmq_service_discovery&#39;
    }
);

# regular script launching the worker
use OurApp::BreadBoard;
my $bb = OurApp::BreadBoard-&#38;gt;new( name=&#38;gt;&#39;SomeWorker&#39; );
my $app = $bb-&#38;gt;resolve( service =&#38;gt; &#39;Apps/some_worker&#39; );
$app-&#38;gt;run;

# a &#38;quot;meta&#38;quot; script that starts all components, each running in a fork
# this should also start the web front/backend (via plackup)
use OurApp::BreadBoard;
my $bb = OurApp::BreadBoard-&#38;gt;new(
    name=&#38;gt;&#39;MetaRunner&#39;,
    environment=&#38;gt;&#39;devel&#39;
);
foreach my $app (qw[some_worker]) {
    if (my $pid = fork()) {
        # parent, manage childs etc
    }
    else {
        my $app = $bb-&#38;gt;resolve( service =&#38;gt; &#39;Apps/&#39;.$app );
        $app-&#38;gt;run;
    }
}
&lt;/code&gt;&lt;/pre&gt;



&lt;h4&gt;The Questions&lt;/h4&gt;

&lt;p&gt;Is this approach sane? Are there better / native ways to pass options deep into a Bread::Board stack? Is Bread::Board the completely wrong tool? We&#39;d really appreciate any feedback / comments!&lt;/p&gt;</content><category term="Bread::Board"/><category term="architecture"/><category term="Moose"/><category term="OX"/><category term="Catalyst"/></entry><entry><title>Acme::ReturnValue 1.001</title><link href="http://domm.plix.at/perl/2013_03_acme_returnvalues_1_001.html"/><id>http://domm.plix.at/perl/2013_03_acme_returnvalues_1_001.html</id><updated>2013-03-30T11:03:45+01:00</updated><category term="perl"/><summary type="html">&lt;p&gt;At the German Perl Workshop I did a lightning talk on Acme::ReturnValue and in the process of preparing the talk started to rework the module. I have now finished the slight modernization of the ...</summary><content type="html">&lt;p&gt;At the &lt;a href=&#34;/perl/2013_03_things_i_learned_at_gpw2013.html&#34;&gt;German Perl Workshop&lt;/a&gt; I did a lightning talk on &lt;a href=&#34;https://metacpan.org/module/Acme::ReturnValue&#34;&gt;Acme::ReturnValue&lt;/a&gt; and in the process of preparing the talk started to rework the module. I have now finished the slight modernization of the code (eg using Path::Class and Moose coercion) and fixed some issues (eg handling of &lt;code&gt;__PACKAGE__-&#38;gt;meta-&#38;gt;make_immutable&lt;/code&gt;). I switched to Dist::Zilla, which (on the one hand) is very nice, but (on the other hand) caused me to upload a tarball to &lt;span class=&#34;caps&#34;&gt;CPAN &lt;/span&gt;that included not only the rendered website but thousands of &lt;span class=&#34;caps&#34;&gt;JSON &lt;/span&gt;files. Then I figured out how to configure the &lt;code&gt;GatherDir&lt;/code&gt; plugin...&lt;/p&gt;

&lt;p&gt;I&#39;ve also did some modification to the &lt;a href=&#34;http://returnvalues.useperl.at&#34;&gt;website&lt;/a&gt;. The list of &lt;a href=&#34;http://returnvalues.useperl.at/values.html&#34;&gt;cool values&lt;/a&gt; is now arranged more clearly (the list of packages per return value is hidden via JQuery, so you can scroll through the funny values more easily). I&#39;ve also added a disqus-powered comment box and fixed some minor &lt;span class=&#34;caps&#34;&gt;HTML &lt;/span&gt;errors.&lt;/p&gt;

&lt;p&gt;I still haven&#39;t set up a cronjob yet, but it should be much easier now, because I now remember which dists I already checked between each run. This changed the run-time from a few hours to a few minutes.&lt;/p&gt;

&lt;p&gt;When my &lt;a href=&#34;http://hollerbusch.at&#34;&gt;son&lt;/a&gt; asked me what I was doing (while I was working on the website), I explained the concept to him and showed him the &lt;a href=&#34;http://returnvalues.useperl.at&#34;&gt;site&lt;/a&gt;. He found it very funny! This reminded me that this whole return values &#34;hacking&#34; is a good representation of one of the core qualities of the Perl community: &lt;strong&gt;Fun!&lt;/strong&gt;&lt;/p&gt;</content><category term="release"/><category term="Acme::ReturnValue"/></entry></feed>