<div dir="ltr"><div>I wanted to note something (before the week gets started and time vanishes) about how Catalyst is behaving, and see if it's expected.</div><div><br></div><div>I asked about this on the Moose list, so sorry if you already saw this.</div><div><br></div><div>A Catalyst app extends Catalyst::Component, which has a BUILDARGS sub to merge in class configuration when creating instances of components.</div><div><br></div><div>This is how configuration can set initial values on attributes in Models, Views, Controllers, and the application class itself. </div><div><br></div><div>If a (non-role) Moose-based plugin is loaded (which is common) it's added to the app's inheritance like this:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(80,0,80);font-size:12.8px">$meta->superclasses($plugin, $meta->superclasses);</span></div></blockquote><div><br></div><div> Which can be thought of like this:</div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>@App::ISA = ( qw/ Catalyst::Plugin::Foo Catalyst / );</div></blockquote></div><div><br></div><div>The result then is that BUILDARGS in Catalyst::Component is no longer called, and then attributes in the App class are no longer populated from the config.</div><div><br></div><div>So, the behavior changes depending on what plugins are brought in.</div><div><br></div><div><br></div>Another odd issue I came against is that <span style="font-size:12.8px">MooseX::Emulate::Class::</span><span style="font-size:12.8px">Accessor::Fast causes odd behavior of Moose attributes. This role is widely used in Catalyst.</span><div><span style="font-size:12.8px"><br></span></div><div><div><span style="font-size:12.8px">In the code below note how the "foo" attribute has init_arg => undef to prevent it from being initialized. With the the role not only is it initialized, but with a value that isn't an "Int".</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><br></div><div><blockquote style="font-size:12.8px;margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote">package Foo;</div></div><div class="gmail_extra"><div class="gmail_quote">use Moose;</div></div><div class="gmail_extra"><div class="gmail_quote"><br></div></div><div class="gmail_extra"><div class="gmail_quote">with 'MooseX::Emulate::Class::Accessor::Fast';</div></div><span class="im"><div class="gmail_extra"><div class="gmail_quote"><br></div></div><div class="gmail_extra"><div class="gmail_quote">has foo => (</div></div><div class="gmail_extra"><div class="gmail_quote"> is => 'ro',</div></div></span><div class="gmail_extra"><div class="gmail_quote"> isa => 'Int', # for error</div></div><div class="gmail_extra"><div class="gmail_quote"> init_arg => undef,</div></div><div class="gmail_extra"><div class="gmail_quote">);</div></div><span class="im"><div class="gmail_extra"><div class="gmail_quote"><br></div></div><div class="gmail_extra"><div class="gmail_quote"><br></div></div><div class="gmail_extra"><div class="gmail_quote">package main;</div></div><div class="gmail_extra"><div class="gmail_quote">use strict;</div></div><div class="gmail_extra"><div class="gmail_quote">use warnings;</div></div><div class="gmail_extra"><div class="gmail_quote"><br></div></div></span><div class="gmail_extra"><div class="gmail_quote">my $foo = Foo->new( { foo => 'bar' } );</div></div><div class="gmail_extra"><div class="gmail_quote"><br></div></div><div class="gmail_extra"><div class="gmail_quote">use Data::Dumper;</div></div><div class="gmail_extra"><div class="gmail_quote">print Dumper $foo->foo;</div></div></blockquote><div class="gmail_extra" style="font-size:12.8px"><div class="gmail_quote"><div><br></div><div>Generates 'bar', which is not an Int.</div><div><br></div></div></div><blockquote style="font-size:12.8px;margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote">$VAR1 = 'bar';</div></div></blockquote><div class="gmail_extra" style="font-size:12.8px"><div class="gmail_quote"></div></div><div><div><br></div><div><div><span style="font-size:12.8px">Comment out "</span><span style="font-size:12.8px">with 'MooseX::Emulate::Class::</span><span style="font-size:12.8px">Accessor::Fast';" and it behaves as expected. Also comment out "init_arg" and Moose will complain about the string not begin an Int.</span></div><div><div class="gmail_extra" style="font-size:12.8px"><div class="gmail_quote"></div></div></div></div><div><br></div><div><br></div>-- <br><div class="gmail_signature">Bill Moseley<br><a href="mailto:moseley@hank.org" target="_blank">moseley@hank.org</a></div>
</div></div></div></div>