Things to think about when migrating from Mojolicious::Lite to Mojolicious

I started prototyping with Mojolicious::Lite at work and migrated to Mojolicious, but at that time I wrote that it was easier to describe Mojolicious::Lite like this. increase. Most of the steps are fine by looking at Mojolicious::Guides::Growing. After all, the maintainability will improve when you try to migrate.

Keep the URL in two pairs, controller and action

If you're thinking of migrating to Mojolicious, it's a good idea to define it as follows: The route name is set automatically, but it will be easier to see if it is separated by a hyphen.

#Mojolicious::Lite
get'/ foo / bar'=> sub {...} =>'foo-bar';

#Mojolicious
$r->get('/ foo / bar')->to('foo # bar')->name('foo-bar');

Of course, you can include the parameters in the URL. It has no effect on actions and controllers.

#Mojolicious::Lite
get'/ foo / bar /: id'=> sub {...} =>'foo-bar';

#Mojolicious
$r->get('/ foo / bar /: id')->to('foo # bar')->name('foo-bar');

If you make three as below, it will be difficult to migrate to Mojolicious.

#Mojolicious::Lite
get'/ foo / bar / baz' => sub {...} =>'foo-bar-baz';

On the other hand, if there is no action name, it is better to correspond to the action called index.

#Mojolicious::Lite
get'/ foo' => sub {...} =>'foo';

#Mojolicious
$r->get('/ foo')->to('foo # index')->name('foo');

Embedded template files can be automatically output to a file

The embedded template file can be automatically output to a file. You don't have to write it yourself.

__DATA__

@@foo-bar.html.ep
<html> <body> Hello </body> </html>

Use the inflate command.

perl myapp.pl inflate

The output file is separated by hyphens like "foo-bar.html.ep", so create a directory with the controller name like "foo / bar.html.ep" and the action name in it. Put the file of.

Associated Information