Hi, As a few may remember I brought this up a while ago and after working with this for a while I just want to make sure we are really understanding and using this correctly...
Postulates: 1) Ideally all the business code should be abstracted into models and more ideally these models should be classes that are independent from Catalyst. We shall call these business model classes to differentiate them from Catalyst Model classes. 2) The Catalyst model as such (script/xx_create.pl model yyy) should be a thin wrapper to the business model classes from postulate 1. 3) Catalyst Models may be classes or instances. Design Patterns: 1) If the Catalyst model will be a class, the pattern is very simple: The catalyst model class uses the business object class just like any other library. As I understand it, the controller code would have to invoke new() on the model class to create a new instance of the class that will die with the request (will lose scope from the controller method that created it). 2) If the Catalyst model will be an instance, the design pattern is a per-request object factory. The fat code should be kept in the instance class, and the ACCEPT_CONTEXT method should be used to instantiate a leaner class and return _that_ to the controller. The idea of an instance, is that most of the heavy duty code remain instantiated and the code is purely functional. Assumptions and Questions 1) Is the assumption that in the first design pattern the controller has to call new() correct? (I have always worked with the second pattern, so I don't know for sure). 2) For Catalyst instance models, the request classes should not contain any heavy duty code. So forcibly the request class needs a reference to the parent model class (the factory). This is so the request class is able to use the methods of the factory class. Is this assumption correct? 3) It is written somewhere (I couldn't find it before writing this but I know is in the POD somewhere) that it is not a good idea to pass the complete $c reference to the per-request object, but rather only the necessary pieces of $c. What are the implications of passing the complete $c ? Any other comments greatly appreciated. I think this could make an interesting article for the Wiki so I want to get all the real experts opinions on this before I attempt to create it. Thanks, -- Alejandro Imass _______________________________________________ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/