[Catalyst] how to reuse Catalyst Schema for non-web purposes?

kakimoto at tpg.com.au kakimoto at tpg.com.au
Thu Apr 23 02:59:39 GMT 2009


>From the Catalyst tutes, I seem to get the impression that pretty much a
lot of the business logic is done in the controller.

I might be wrong but in
http://search.cpan.org/~hkclark/Catalyst-Manual-5.7020/lib/Catalyst/Manual/Tutorial/BasicCRUD.pod#___top
("Add a Method to Process Form Values and Update Database"),
it seems that the task of creating a new entry for books in the database
and establishing the right relationships to the book_authors  db table
is done in the sub form_create_do in the Controller.

i suppose if a batch script were to be used to add in amany books, the
logic there would be trapped in the controller.
 
How do we put that logic into the Model? very interesting and I would
like to hear more since I cant find any examples for putting business
logic in the Model for catalyst on google.

thank you.

k. akimoto



Quoting kakimoto at tpg.com.au:

> Hello, Simon,
> 
>   Your points have good weight for thoughts. In fact, coming from
> many
> backgrounds pre-Catalyst and pre-MVC (ie many a times, the
> templating
> system ie Mason would do the job of both controller and view
> incorporating the business logic), I have been able to write
> regression
> tests to test methods within an ORM.
> 
>  When I first started using Catalyst, I looked at the tutes and so
> forth
> and it seemed to me that the only form of testing is just web based
> (ie
> using web robots like Test::WWW::Mechanize::Catalyst).
> Whilst that allowed a good test of the interface and functionality as
> a
> whole(akin a blackbox), I missed the days when I had to develop
> something without the web front end and have it work for both web
> and
> back end(ie via scripts).
> 
> 
>  Your arguments here have raised a direction for me to put my
> business
> logic into the model component of my app.
> Nevertheless, can I ask for some references to examples of business
> logic being written in the model? I can't seem to observe any from
> the
> Catalyst tutes.
> 
> thank you
> 
> K. akimoto
> 
> 
> Quoting Simon Wilcox <simonw at digitalcraftsmen.net>:
> 
> > On 22/4/09 23:03, kakimoto at tpg.com.au wrote:
> > > IMO the best place for your business logic is the controller.
> > 
> > Then you're wrong, at least in the eyes of many people.
> > 
> > http://en.wikipedia.org/wiki/Model-view-controller
> > 
> > The Controller is just a layer that converts the input to
> something
> > that 
> > can be passed to the Model and then sends the output back to the
> user
> > 
> > via a View.
> > 
> > You *can* put all your logic in the controller but typically you
> will
> > 
> > end up with two problems:
> > 
> > 1. Your app is tightly bound to a web framework and adding some
> other
> > 
> > sort of user interaction, or extending the application code
> elsewhere
> > 
> > becomes difficult, which is what started this thread isn't it ?
> > 
> > 2. It becomes hard to test as you need to have the web framework
> > running 
> > to run the tests. You should be able to test all of the use cases &
> 
> > business interactions outside of the web framework. If you can't,
> > then 
> > that's a code smell and an indicator that you have too much going
> on
> > in 
> > your Controller classes.
> > 
> > The Catalyst Model classes should really be a very thin shim over
> the
> > 
> > top of your DBIx::Class Schema objects which is where all the
> 'heavy
> > 
> > lifting' of the business process takes place.
> > 
> > Hope that makes sense,
> > 
> > Simon.
> > 
> > 
> > 
> 
> 
> 
> 
> _______________________________________________
> List: Catalyst at 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/
> 
> 
> 






More information about the Catalyst mailing list