Introduction to Mojolicious Perl Web Framework
An introduction to web development using Mojolicious, Perl's flagship framework. Learn the basics of installing Mojolicious and creating web applications with Mojollicious.
use Mojolicious::Lite; get '/' => {text =>'Hello World!'}; app->start;
It works on Windows, Linux and any environment. For those who think "I didn't like CGI", now there is "Mojolicious".
1. Features of Mojolicious
I think there is such a question, "Is Mojolicious only a small website?" In fact, Mojolicious can start from a small website and grow steadily.
Mojolicious
- Creating a website easily and quickly
- Provides a set of functions required for website creation
- Supports large-scale web application development
It has the feature.
Mojolicious provides "a set of features needed to create a website".
- Template, parameter acquisition, form processing, URL creation
- Sessions, cookies, WebSockets, asynchronous I / O, authentication
- SSL, JSON, web server
You can write HTML quickly using the "template function". "Parameters" are also easy to get, and "Sessions" are also supported by default. Since it supports "asynchronous I / O", it can handle even if the load becomes high after the service starts.
Is there a web service you want to create? If you want to create efficient and maintainable web apps, Mojolicious is for you.
2. Introduction to Mojolicious
Let's start by installing Mojolicious. After that, I will actually run Mojolicious.
2.1 Installing Mojolicious
I will explain the procedure to install Mojolicious.
2.2 Let's display "Hello World" in Mojolicious
Let's create the simplest Hello World application with Mojolicious.
use Mojolicious::Lite; get '/' => sub { my $self = shift; $self->render(text =>'Hello World'); }; app->start;
See Smallest Web Application for a description and how to execute it.
In the introduction to Mojolicious, I will write articles on the assumption that I have knowledge of "HTML" and "CSS". If you don't know the minimum "HTML" or "CSS" yet, HTML basics and CSS Basics.
2.3 Publication on the Internet
"I want to publish a website as soon as I create it!"
The easiest way is to publish your application using "Sakura Rental Server Standard". If you want to publish it immediately, please see Publish the app on Sakura Rental Server Standard. If you want to move on without publishing it yet, you can read it later.
The joy of running a site I created on the Internet is exceptional. Please give it a try!
Web application basics
I will explain the basics of Web applications using Mojolicious.
- How to receive parameters
- Template basics
- Application and controller features
- Routing basics
- Template helper
- Using forms
- Handling of Japanese
- Database basics
- Database and program linkage
Installation
- Installing Mojolicious --Installing Mojolicious on Windows, Mac OS X, Unix / Linux
- Hello World! Application
Creating a template
Route
- Describe various routes with Mojolicious::Lite
- Describe the process to be executed before all processes under under
- Check the list of routes
- Use reserved words such as colon (:) in URLs
Controller
- Get the value of the parameter
- Convert parameters to hash reference
- Get HTTP method
- Get HTTP headers
- Setting default values for stash
- Set a passphrase for signed cookies
- Pass the required values in common for multiple controllers
Drawing templates and JSON
Character code
File upload
- Get the size of the uploaded file
- Get the content type of the uploaded file
- Validation of multiple file uploads
Utilities
Tag helper
Session
URL
Plugins
Introducing how to use Mojolicious plugins and modules.
- Add plugin namespace
- Mojolicious::Plugin::AutoRoute --Mojolicious plugin for automatically generating routes
- Mojolicious::Plugin::SQLiteViewerLite --Plugin for viewing SQLite table information from a browser
- Mojolicious::Plugin::MySQLViewerLite --Plugin for viewing MySQL table information from a browser
Exam
Deploy
- morbo --Mojolicious development server
- Deploy the PSGI app with Starman
- Resolve URL issues when connecting via a proxy server
- What to do if you get a "Service Temporarily Unavailable" error when using Apache mod_proxy
- hypnotoad command
- How to check when hypnotoad does not start
- Test::Perform tests that cannot be performed by Mojo
- Operate Mojolicious in a subdirectory
- Check if hypnotoad is running properly
- How to manage Mojolicious applications from the root user
- Run hypnotoad with specific user privileges (or group privileges)
- How to switch to a general user and execute commands while you are the root user
Cooperation with SSL
Web scraping
Performance
hypnotoad prefork server
Non-blocking IO
Others
- Mojolicious templates can be dangerous to import functions
- Convenient API
- Things to consider when migrating from Mojolicious::Lite to Mojolicious
- Use Mojolicious and AnyEvent at the same time
Release information
Sakura rental server
An article useful for using Mojolicious on Sakura's rental server.
- The procedure from starting Mojolicious development on Windows to publishing it on Sakura's rental server
- Use static files such as CSS with Mojolicious
- What to do if a "505 Internal Server" error occurs on Sakura's rental server
- Script to install CPAN module with Sakura rental server light plan
Mojolicious sample
Introducing a sample using Mojolicious.
- A word message board --Easy bulletin board
- Image board --Easy image board
- Search application --Simple search application
- Simple real-time clock --Real-time clock using WebSocket
- Simple real-time chat --Real-time chat using WebSocket
- Portable BBS --Sample for creating a portable web app
- Gitweb Lite --Git repository viewer. Porting gitweb.cgi to Mojolicious.
Mojolicious documentation
The official document of Mojolicious. This document describes all the features of Mojolicious. If you don't know, always refer to this.
Mojolicious related courses
This is a Mojolicious related course.
Web development environment construction
It is a site for building a web development environment on Ubuntu to run Mojolicious in a production environment.
Web application development
Explains how to develop web apps with Perl and Mojolicious.