Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

If I understand it right, you have multi-directory application with many scripts in them. If that is so, then every directory that your CGI application have will become Mojolicious::Controller, every script will become URL, and all logic will go to appropriate Controller.

If you have something like this in your application directory:

.. index.pl dir1/somescript1 dir1/somescript2 dir2/somescript3 dir3/somescript4
then your Mojolicious application will have something like this inside:
script/app.pl lib/App.pm lib/App/Controller/Main.pm lib/App/Controller/Dir1.pm lib/App/Controller/Dir2.pm templates/layouts/default.html.ep templates/main/index.html.ep
script/app.pl:
#!perl use strict; use warnings; use FindBin; BEGIN { unshift @INC, "$FindBin::Bin/../lib" } use Mojolicious::Commands; Mojolicious::Commands->start_app('App');
lib/App.pm:
package App; use Mojo::Base 'Mojolicious'; sub startup { my $self = shift; my $r = $self->routes; $r->get('/')->to('main#index'); $r->get('/dir1/somescript1')->to('dir1#somescript1'); $r->get('/dir1/somescript2')->to('dir1#somescript2'); $r->get('/dir2/somescript3')->to('dir2#somescript3'); $r->get('/dir2/somescript4')->to('dir2#somescript4'); } 1;
lib/App/Controller/Main.pm:
package App::Controller::Main; use Mojo::Base 'Mojolicious::Controller'; sub index { my $self = shift; # will render templates/main/index.html.ep # logic from index.pl $self->render(); } 1;
lib/App/Controller/Dir1.pm:
package App::Controller::Dir1; use Mojo::Base 'Mojolicious::Controller'; sub somescript1 { my $self = shift; my $params = $self->req->params->to_hash; # logic from dir1/somescript1.pl # all HTML goes to templates/dir1/somescript1.html.ep $self->render(); } # etc... 1;
Then you run it from root of your application like this:
perl script/app.pl
update: I thought that you might want to read the docs: Mojolicious Tutorial, Growing Guide

In reply to Re^3: Mojo app running IIS CGI by alexander_lunev
in thread Mojo app running IIS CGI by WookieeJeff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2021-06-15 19:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (73 votes). Check out past polls.

    Notices?