tercoz has asked for the wisdom of the Perl Monks concerning the following question:

When I started to play with MVC, having CGI::Application as a tool, I used this approach: Any runmode was my controller, I made another class-model which interacted with DB and returned raw data - array of hashrefs. I made another class-view which got the raw_data and reorganized that into some structure, that was turned to JSON string. After all, controller got that stuff from view and returned it back to web client. So view did all the job to rearrange model-given raw data and turn it json. Okay. Now I am trying to get understanding of Catalyst. Here I have to restructure raw data somewhere else, stash it, and forward all that mess to Catalyst::View::JSON. The question: WHERE I should rearrange/restructurize raw data if there are no any additional calculations planned, but simply preparing data for some jQuery widget in the end. I doubt it must be done in model or controller. What you think?

Replies are listed 'Best First'.
Re: Catalyst. View. How to use?
by Anonymous Monk on Jun 08, 2015 at 07:58 UTC

    What you think?

    Try stuff, try both the first thing you were thinking of, and the second , Try both ;)

    Then try a third thing ... write down any questions that pop up into your head as you start and finish each example

    Its the only way to figure it out , whatever the mental block, getting short working example, a few different ways, is as useful ,

    even more useful than talking it out with a fellow developer -- the internet just adds lag to a very short exercise

    after completing said exercise you'll have a better idea of what you're trying to ask :) You'll have an actual example scenario you can share

Re: Catalyst. View. How to use?
by stonecolddevin (Parson) on Jun 09, 2015 at 21:20 UTC

    Why wouldn't it be done in a model?

    Models are specifically for handling data. It seems like it would be pretty prudent to create your data structure in your model and have the controller pass said data structure to the view to be serialized as JSON. Other than that, it seems like you'd just be making life hard on yourself.

    Three thousand years of beautiful tradition, from Moses to Sandy Koufax, you're god damn right I'm living in the fucking past