[Thamesvalley-pm] Mojolicious and Catalyst

Oliver Gorwits oliver at cpan.org
Thu Apr 14 08:58:49 PDT 2016


On 2016-04-14 13:21, Andrew wrote:
> my perl code is just going in the controller folder. I don't yet 
> understand
> why a bit of code goes in a view folder or model folder - it's not the 
> model
> or the view, it's still processing, it's still code.

I think it's down to how you want to separate the parts of your 
application. The idea is that one part of code should not [need to] know 
too much about how another part gets its job done. You make the point 
already in your "hot swapping" comment but it's also about the ability 
to make small changes to code more easily, to test code in isolation, to 
limit the impact of bugs, and so on.

In Mojolicious the View (Output) and Controller (Processing) are sort of 
mushed together, which is why you might be missing the View code.

For the Model, what I tend to do is write "wrapper" or "helper" 
subroutines that take friendly parameters, perform basic sanity checks, 
execute the necessary SQL, and return some sort of data structure. For 
example get_user($id) or whatever, running SELECT ... FROM and returning 
a hash. If you go for something more involved such as DBIx::Class then 
you can get fancy with its Virtual Table (~view) feature and embed quite 
a lot into the [data-]model.

regards,
oliver.


More information about the Thamesvalley-pm mailing list