<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>I found a minor bug in Catalyst today. &nbsp;It showed up in our development environment, and made me crazy trying to track it down.</div><div><br></div><div>If you have a MyApp::Script::Server class, when you run myapp_server.pl, it will sometimes miss checking the values for MYAPP_PORT and MYAPP_RELOAD from the environment.</div><div><br></div><div>It's the "sometimes" that made this hard to sort out.</div><div><br></div><div>As far as I can tell, the values from the constructor to the Server object are being set up in a different order. &nbsp;Sometimes application_name is set up before port or reload, in which case the right app-specific environment variables are checked. &nbsp;Sometimes port or reload (or both) are set up before application_name is initialized, and in those cases 'MyApp' isn't sent to env_value, so the MYAPP variant of the environment block isn't checked.</div><div><br></div><div>I never did figure out what caused the order to be different. &nbsp;I can guess wildly, but don't really know for sure.</div><div><br></div><div>The solution - already used in one of the accessors in Catalyst::Script::Server - is to make port and reload lazy, so application_name will always be set before they're called. &nbsp;Any of the accessors that use env_value in their default should be lazy so you can depend on application_name. &nbsp;It's a trivial change.</div><div><br></div><div>It did break one of the tests, though, as the test uses direct hash access to test retrieved values. &nbsp;For, as far as I can tell, no good reason. &nbsp;Changing the test to a method call fixes it.</div><div><br></div><div>I couldn't figure out how to write a test to trigger this every time, so I have no idea how I'd write a test to prove it's really fixed.</div><div><br></div><div>Here, as requested on the web site, are diffs. &nbsp;If there's a better way to get them to you, I do have this checked out in git and could push them someplace or something.</div><div><br></div><div>Let me know and I'll be happy to do so, so no one else has to spend half a day scratching their head over this one.</div><div><br></div><div><div style="margin: 0px; font-family: Menlo;">diff -u -b lib/Catalyst/Script/Server-orig.pm lib/Catalyst/Script/Server.pm&nbsp;</div><div style="margin: 0px; font-family: Menlo;">--- lib/Catalyst/Script/Server-orig.pm<span class="Apple-tab-span" style="white-space:pre">        </span>2014-05-26 20:03:00.000000000 -0700</div><div style="margin: 0px; font-family: Menlo;">+++ lib/Catalyst/Script/Server.pm<span class="Apple-tab-span" style="white-space:pre">        </span>2014-05-26 20:02:23.000000000 -0700</div><div style="margin: 0px; font-family: Menlo;">@@ -37,6 +37,7 @@</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; cmd_aliases &nbsp; =&gt; 'p',</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; isa &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; 'Int',</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; is&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; 'ro',</div><div style="margin: 0px; font-family: Menlo;">+&nbsp; &nbsp; lazy&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; 1,</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; default &nbsp; &nbsp; &nbsp; =&gt; sub {</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Catalyst::Utils::env_value(shift-&gt;application_name, 'port') || 3000</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; },</div><div style="margin: 0px; font-family: Menlo;">@@ -107,6 +108,7 @@</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; cmd_aliases &nbsp; =&gt; 'r',</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; isa &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; 'Bool',</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; is&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; 'ro',</div><div style="margin: 0px; font-family: Menlo;">+&nbsp; &nbsp; lazy&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; 1,</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; default &nbsp; &nbsp; &nbsp; =&gt; sub {</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Catalyst::Utils::env_value(shift-&gt;application_name, 'reload') || 0;</div><div style="margin: 0px; font-family: Menlo;">&nbsp;&nbsp; &nbsp; },</div></div><div style="margin: 0px; font-family: Menlo;"><br></div><div style="margin: 0px; font-family: Menlo;"><div style="margin: 0px;">diff -u -b t/aggregate/unit_core_script_server-orig.t t/aggregate/unit_core_script_server.t&nbsp;</div><div style="margin: 0px;">--- t/aggregate/unit_core_script_server-orig.t<span class="Apple-tab-span" style="white-space:pre">        </span>2014-05-26 20:13:25.000000000 -0700</div><div style="margin: 0px;">+++ t/aggregate/unit_core_script_server.t<span class="Apple-tab-span" style="white-space:pre">        </span>2014-05-26 20:13:34.000000000 -0700</div><div style="margin: 0px;">@@ -151,7 +151,7 @@</div><p style="margin: 0px; min-height: 21px;">&nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px;">&nbsp;&nbsp; &nbsp; ## Check a few args</div><div style="margin: 0px;">&nbsp;&nbsp; &nbsp; is_deeply $app-&gt;{ARGV}, $argstring;</div><div style="margin: 0px;">-&nbsp; &nbsp; is $app-&gt;{port}, '3000';</div><div style="margin: 0px;">+&nbsp; &nbsp; is $app-&gt;port, '3000';</div><div style="margin: 0px;">&nbsp;&nbsp; &nbsp; is($app-&gt;{background}, 1);</div><div style="margin: 0px;">&nbsp;}</div><p style="margin: 0px; min-height: 21px;">&nbsp;<br class="webkit-block-placeholder"></p><div><br></div><div><br></div></div><div style="margin: 0px; font-family: Menlo;"><br></div><div><br></div></body></html>