On Mon, Oct 25, 2010 at 10:48 PM, Hans Dieter Pearcey <h...@pobox.com> wrote: > On Mon, 25 Oct 2010 16:23:45 -0500, Evan Carroll <m...@evancarroll.com> wrote: >> I'll go ahead and >> show you what I wanted to do with this. I have a Class, it should >> accept either a "company_id", or a hash of "attributes" if you provide >> a company_id the attribute hash is lazy when it is needed. If you >> provide a hash of company attributes, then the value is immediately >> entered into the DB, and the company_id gets set appropriately: > > Using new() for this seems wrong to me. Your object constructor should > construct objects, not construct objects and sometimes insert data but other > times retrieve it. For example, in DBIC this is find_or_create, which is > itself built on top of other predicates that are built on top of object > construction; it's a complex operation, and trying to make it all an > inextricable part of calling new is a code smell.
I found this: http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/ to be a very clear explanation of why this is a code smell :) -- Zbigniew Lukasiak http://brudnopis.blogspot.com/ http://perlalchemy.blogspot.com/