I probably do it backwards, i dont use dbix::class just mojo::pg and like
you my app is a big one. I think the Plugin route is a good way to do it
but I didnt go that way. I'm using Mojo::Base for my model classes.

I made a models folder so lib/Models/mymodelclass.pm
my controllers handle the views and the requests and create new objects of
my models (i know i should use helpers...), my models handle anything that
requires a database connection or something related to the table or view. I
pass in the session, db, and anything else needed when making the object.
So for an employee listing page for example, if i was getting a list of
employees but needed to manipulate them, i would run my query, alter the
data, return it. my controller picks it up and shoots it to the template
view.

My models aren't always a db connection though sometimes I need small
tweaks and I'll just make a subroutine in that model because it's still
related in a way. Is this bad blending my model with a non database
subroutine probably but its related to the database table/controller/view
so i'm going to keep it how it is.

Hope this gives an idea.

On Wed, Jul 29, 2020 at 11:14 AM James Szinger <jszin...@gmail.com> wrote:

> Hi,
>
> I'm writing a fairly large Mojolicious app and I'd like some advice on
> where to place the logic of the display or view.  My model queries a
> database and returns a data stucture with the results.  Then my
> templates pull the data from the structure and format it.  I think
> this is all fairly normal.
>
> The problem is that some of the display logic is fairly complicated:
> one of my templates has a 30 line <% %> block before anything can be
> displayed.  It strikes me that these 30 lines (and others) are better
> off in a subroutine or method.  But where?  MyApp::View?  How would I
> call it from a template?  None of the documentation I can find
> addresses this.  I appreciate any pointers or examples.
>
> Thanks,
> Jim
>
> P.S. The templates look something like:
> <%
> my @foobar;
> for my $foo ( @row->{foo}) {
>     my $foobar;
>     $foobar .= "$foo->{baz}: " if $foo->{baz};
>     $foobar .= $foo->{bar}->join( ', ');
>     push @foobar, $foobar;
> }
> my $foobars = join '; ', @foobar;
> %>
> % if ($foobars) {
> <p>Foobar is <%= $foobars %>.<p>
> %>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/20200729111238.1f86ccdc%40doliolum.thaliacea.lan
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CAM%2Bc73YpYZY-RjqEpmEQM1ae4ChTFU53-hynAcQrgLtaVKNVLA%40mail.gmail.com.

Reply via email to