<br><br>On Monday, January 2, 2012, Jason Galea  wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><div><br></div><div>I think I&#39;ve added another layer but I&#39;m not sure where you draw the line.. I have a model layer over DBIC pulling together related result classes under a single model class. Then the app? layer uses the model layer to get things done. So I&#39;d probably have one &quot;distribution&quot; that is our DBIC wrapped in a model layer layer and use that in a number of apps.. 8) Each app can then be used as the single model in a Catalyst app or script or whatever.. (I think I need more names for the parts..)</div>
</div></div></blockquote><div><br></div><div>Yes, where to draw the line is difficult to know.   I&#39;ve only had a few hours to work on this but already I feel like I&#39;m reinventing Catalyst -- mostly because my model layer is pulling in much of the components that my Catalyst app would normally do -- DBIC, caching, even some concept of the &quot;current user&quot;.   Access control is another topic.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><div><div>I have &quot;Sets&quot; in lu of ResultSets and &quot;Models&quot; for Results. Although in most instances a Model will actually cover the usage of multiple Results. Each Set gets the dbic schema object and knows it&#39;s resultset name. Each model has a data attribute which contains a dbic row object and &quot;handles&quot; any methods I don&#39;t need to override via the Moose &quot;handles&quot; attribute attribute!?</div>

<div><br></div><div>Set-&gt;create($hash) creates the dbic object and stuffs it into a model class and returns that.</div></div></div></div></blockquote><div><br></div><div>So you are mirroring DBICs class structure a bit.  I need to consider that approach more as currently my model layer returns the DBIC row object directly.  So, I have something like this:<br>
<br></div><div>my $user_model = Model::User-&gt;new;</div><div>my $new_user = $user-&gt;new_user( $user_data );</div><div><br></div><div>Not as flexible as your approach but my goal currently is to just abstract out the ORM so that Model::User can hide the specifics of the database.   Actually, it&#39;s not that hard to do directly with DBIC, either.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><div><div>Each result class that has a model class overrides it&#39;s inflate_result method which again stuffs the dbic row object into the model object so searches on the related dbic resultsets return my model objects.</div>
</div></div></div></blockquote><div><br></div><div>Can you show a code example of that?  I&#39;m not sure I&#39;m following why you use that approach instead of having your layer on top of DBIC do that.</div><div><br></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><div>
<div><br></div><div>Each model class has a validation class based on.. Validation::Class and create &amp; update run their input through that. If there are errors I stuff the errors into a very basic exception object and return that. This way I can return the same exception object no matter where the error comes from, eg a dbic exception..</div>
</div></div></div></blockquote><div><br></div><div>Yes, I&#39;m doing something very similar where validation happens before the method in the model and on validation errors and exception is thrown (if you are on the Moose list you may have seen my example).</div>
<div><br></div><div>Thanks for the feedback and the ideas,</div><div> </div><br><br>-- <br>Bill Moseley<br><a href="mailto:moseley@hank.org" target="_blank">moseley@hank.org</a><br>