Architectural question - Best practice?

107 views
Skip to first unread message

Pablo IaCo

unread,
Sep 30, 2015, 5:05:22 PM9/30/15
to Mojolicious
Hi Folks,

I just wanted to share with you something that I'm trying to figure out.

I'm currently building a small App for my own and it's build like follows
1) The App itself (with login and stuff)
2) A Back-Office (with login and more stuff and creation of information for the main app)

The question that I want to ask is, that currently I've started to build the main application.pl file, with Mojolicious::Lite, with most of the routes and stuff inside of it.

But my question is, how should I approach to develop the back office? I mean, shall I write the whole thing INSIDE the main application.pl or is it better to create a sepparated application just to handle the back office.

My concern with the second approach is, how to handle those packages that are common to each part? 

Thanks in advance and I'm just doing my first steps into a bigger mojolicious app, so that's why I created this post
Regards
Pablo

Richard Sugg

unread,
Oct 1, 2015, 8:18:57 AM10/1/15
to Mojolicious
Mojolicious lets you write plugins for sharing code across controllers, or in the case of a mojo lite app, callbacks.

Another solution is to just write plain old perl modules and include them. This is the approach I have taken -- sometimes I write functionality in Mojolicious plugins, then realize I need it in something unrelated, so I end up refactoring to a standard perl module, and include it in my mojolicious app. In general, I try to make my controllers extremely lite -- check the input parameters, call out to a mojo plugin or perl module to accomplish what is asked, and in the controller, return an appropriate response.

Pablo IaCo

unread,
Oct 1, 2015, 8:23:02 AM10/1/15
to Mojolicious
Thanks Richard, that was something that I started to work later after creating this post in order to gain some time. I've started to create my modules as usual and include them...but I was unaware of mojos plugins. That's a reflection of how much I've researched the site, that's something that I need to improve.

Much appreciated your response!

Jan Henning Thorsen

unread,
Oct 2, 2015, 8:21:48 AM10/2/15
to Mojolicious
In this case, I don't think I would go for a lite app, but rather create controller classes and a full app. You can then do things like:

    package MyApp::Controller::User;
    use Mojo::Base "Mojolicious::Controller";
    sub some_action {
      my $c = shift;
      $c->render(text => "both apps");
    }

    package MyBackOfficeApp::Controller::User;
    use Mojo::Base "MyApp::Controller::User";
    sub more_stuff {
      my $c = shift;
      $c->render(text => "just in this app");
    }

That way, you have isolated the code, which means that it is impossible to access "more_stuff()" from the MyApp.

Pablo IaCo

unread,
Oct 2, 2015, 8:28:02 AM10/2/15
to Mojolicious
Thanks Jan, that was the thing that I wanted to achieve. I started with the *lite* approach and unfortunately now...my app it's no longer a *lite* one :(

I'll have to migrate a buch of code into a full Mojo app, but I think that it worth the effort. Thanks a lot for your suggestion!
Reply all
Reply to author
Forward
0 new messages