名前¶
Mojolicious::Lite - Micro real-time web framework
Mojolicious::Lite - 小さなリアルタイムWebフレームワーク
使い方¶
# Automatically enables "strict", "warnings", "utf8" and Perl 5.10 features
use Mojolicious::Lite;
# Mojolicious::Liteを使うと"strict","warnings","utf8","Perl 5.10 機能"が有効になる
use Mojolicious::Lite;
# Route with placeholder
get '/:foo' => sub {
my $c = shift;
my $foo = $c->param('foo');
$c->render(text => "Hello from $foo.");
};
# プレースホルダーを使ったルーティング
get '/:foo' => sub {
my $c = shift;
my $foo = $c->param('foo');
$c->render(text => "Hello from $foo.");
};
# Start the Mojolicious command system
app->start;
# Mojoliciousのコマンドシステムの開始
app->start;
説明¶
Mojolicious::Lite is a tiny domain specific language built around Mojolicious, made up of only about a dozen Perl functions.
Mojolicious::Liteは、10 個ほどの Perl 関数で作る、Mojoliciousを中心にして構築された小さなドメイン指定言語です。
On Perl 5.20+ you can also use a -signatures
flag to enable support for subroutine signatures.
Perl 5.20以上の場合は、-signatures
フラグを使うことによりsubroutine signaturesを有効にできます。
use Mojolicious::Lite -signatures;
get '/:foo' => sub ($c) {
my $foo = $c->param('foo');
$c->render(text => "Hello from $foo.");
};
app->start;
See Mojolicious::Guides::Tutorial for more!
より多くを知りたい場合は、Mojolicious::Guides::Tutorialを見てください。
成長¶
While Mojolicious::Guides::Growing will give you a detailed introduction to growing a Mojolicious::Lite prototype into a well-structured Mojolicious application, here we have collected a few snippets that illustrate very well just how similar both of them are.
Mojolicious::Guides::Growingは、Mojolicious::Liteプロトタイプをよく構成されたMojoliciousに成長させるための詳細なイントロダクションとなっていますが、それが、どれくらいよく似ているかを示すために、いくつかのスニペットを集めました。
ルーティング¶
"get", "post" 関数とその仲間は、まったく同じです。
# Mojolicious::Lite
get '/foo' => sub {
my $c = shift;
$c->render(text => 'Hello World!');
};
# Mojolicious
sub startup {
my $self = shift;
my $routes = $self->routes;
$routes->get('/foo' => sub {
my $c = shift;
$c->render(text => 'Hello World!');
});
}
アプリケーション¶
The application object you can access with the function "app" is the first argument passed to the startup
method.
"app" 関数でアクセスできるアプリケーションオブジェクトは startup
メソッドに渡される最初の引数です。
# Mojolicious::Lite
app->max_request_size(16777216);
# Mojolicious
sub startup {
my $self = shift;
$self->max_request_size(16777216);
}
プラグイン¶
Instead of the "plugin" function you just use the method "plugin" in Mojolicious.
"plugin" 関数の代わりに、"plugin" in Mojolicious メソッドを使うだけです。
# Mojolicious::Lite
plugin 'Config';
# Mojolicious
sub startup {
my $self = shift;
$self->plugin('Config');
}
ヘルパー¶
Similar to plugins, instead of the "helper" function you just use the method "helper" in Mojolicious.
プラグインと似ていて、"helper" 関数の代わりに "helper" in Mojolicious メソッドを使うだけです。
# Mojolicious::Lite
helper two => sub {
my $c = shift;
return 1 + 1;
};
# Mojolicious
sub startup {
my $self = shift;
$self->helper(two => sub {
my $c = shift;
return 1 + 1;
});
}
アンダー¶
Instead of sequential function calls, we can use methods to build a tree with nested routes, that much better illustrates how routes work internally.
後に続く関数の呼び出しの代わりに、ネストされたルートで木を構築するためのメソッドを使うことができます。
# Mojolicious::Lite
under '/foo';
get '/bar' => sub {...};
# Mojolicious
sub startup {
my $self = shift;
my $routes = $self->routes;
my $foo = $routes->under('/foo');
$foo->get('/bar' => sub {...});
}
関数¶
Mojolicious::Lite implements the following functions, which are automatically exported.
Mojolicious::Liteは次の関数を実装しています。
any¶
my $route = any '/:foo' => sub {...};
my $route = any '/:foo' => sub {...} => 'name';
my $route = any '/:foo' => {foo => 'bar'} => sub {...};
my $route = any '/:foo' => [foo => qr/\w+/] => sub {...};
my $route = any ['GET', 'POST'] => '/:foo' => sub {...};
my $route = any ['GET', 'POST'] => '/:foo' => [foo => qr/\w+/] => sub {...};
my $route = any
['GET', 'POST'] => '/:foo' => (agent => qr/Firefox/) => sub {...};
Generate route with "any" in Mojolicious::Routes::Route, matching any of the listed HTTP request methods or all. See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
"any" in Mojolicious::Routes::Routeによるルーティングを 生成し、リストされたHTTPのリクエストメソッドにマッチします。 さらなる引数のバリエーションについてはMojolicious::Guides::Tutorialを見てください。
app¶
my $app = app;
Returns the Mojolicious::Lite application object, which is a subclass of Mojolicious.
Mojolicious::Liteアプリケーションです; これは、Mojoliciousのサブクラスです。
# Use all the available attributes and methods
app->log->level('error');
app->defaults(foo => 'bar');
# すべての利用可能な属性とメソッドが利用できます
app->log->level('error');
app->defaults(foo => 'bar');
del¶
my $route = del '/:foo' => sub {...};
my $route = del '/:foo' => sub {...} => 'name';
my $route = del '/:foo' => {foo => 'bar'} => sub {...};
my $route = del '/:foo' => [foo => qr/\w+/] => sub {...};
my $route = del '/:foo' => (agent => qr/Firefox/) => sub {...};
Generate route with "delete" in Mojolicious::Routes::Route, matching only DELETE
requests. See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
"delete" in Mojolicious::Routes::Routeによるルーティングを生成し、DELETE
リクエストにだけマッチします。 さらなる引数のバリエーションについてはMojolicious::Guides::TutorialとMojolicious::Guides::Routing を見てください。
get¶
my $route = get '/:foo' => sub {...};
my $route = get '/:foo' => sub {...} => 'name';
my $route = get '/:foo' => {foo => 'bar'} => sub {...};
my $route = get '/:foo' => [foo => qr/\w+/] => sub {...};
my $route = get '/:foo' => (agent => qr/Firefox/) => sub {...};
Generate route with "get" in Mojolicious::Routes::Route, matching only GET
requests. See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
"get" in Mojolicious::Routes::Routeによるルーティングを生成し、GET
リクエストにだけマッチします。 さらなる引数のバリエーションについてはMojolicious::Guides::TutorialとMojolicious::Guides::Routingを見てください。
group¶
group {...};
Start a new route group.
新しいルーティングのグループを開始します。
helper¶
helper foo => sub {...};
Add a new helper with "helper" in Mojolicious.
"helper" in Mojoliciousを使って新しいヘルパーを追加します。
hook¶
hook after_dispatch => sub {...};
Share code with "hook" in Mojolicious.
"hook" in Mojoliciousと同じです。
options¶
my $route = options '/:foo' => sub {...};
my $route = options '/:foo' => sub {...} => 'name';
my $route = options '/:foo' => {foo => 'bar'} => sub {...};
my $route = options '/:foo' => [foo => qr/\w+/] => sub {...};
my $route = options '/:foo' => (agent => qr/Firefox/) => sub {...};
Generate route with "options" in Mojolicious::Routes::Route, matching only OPTIONS
requests. See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
"options" in Mojolicious::Routes::Routeによるルーティングを生成し、OPTIONS
リクエストにだけマッチします。 さらなる情報については Mojolicious::Guides::TutorialとMojolicious::Guides::Routingを見てください。
patch¶
my $route = patch '/:foo' => sub {...};
my $route = patch '/:foo' => sub {...} => 'name';
my $route = patch '/:foo' => {foo => 'bar'} => sub {...};
my $route = patch '/:foo' => [foo => qr/\w+/] => sub {...};
my $route = patch '/:foo' => (agent => qr/Firefox/) => sub {...};
Generate route with "patch" in Mojolicious::Routes::Route, matching only PATCH
requests. See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
"patch" in Mojolicious::Routes::Routeによるルーティングを生成し、PATCH
リクエストにだけマッチします。 さらなる情報については Mojolicious::Guides::TutorialとMojolicious::Guides::Routingを見てください。
plugin¶
plugin SomePlugin => {foo => 23};
Load a plugin with "plugin" in Mojolicious.
"plugin" in Mojoliciousを使ってプラグインをロードします。
post¶
my $route = post '/:foo' => sub {...};
my $route = post '/:foo' => sub {...} => 'name';
my $route = post '/:foo' => {foo => 'bar'} => sub {...};
my $route = post '/:foo' => [foo => qr/\w+/] => sub {...};
my $route = post '/:foo' => (agent => qr/Firefox/) => sub {...};
Generate route with "post" in Mojolicious::Routes::Route, matching only POST
requests. See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
"post" in Mojolicious::Routes::Routeによるルーティングを生成し、POST
リクエストにだけマッチします。 さらなる情報については Mojolicious::Guides::TutorialとMojolicious::Guides::Routingを見てください。
put¶
my $route = put '/:foo' => sub {...};
my $route = put '/:foo' => sub {...} => 'name';
my $route = put '/:foo' => {foo => 'bar'} => sub {...};
my $route = put '/:foo' => [foo => qr/\w+/] => sub {...};
my $route = put '/:foo' => (agent => qr/Firefox/) => sub {...};
Generate route with "put" in Mojolicious::Routes::Route, matching only PUT
requests. See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
"put" in Mojolicious::Routes::Routeによるルーティングを生成し、PUT
リクエストにだけマッチします。 さらなる情報については Mojolicious::Guides::TutorialとMojolicious::Guides::Routingを見てください。
under¶
my $route = under sub {...};
my $route = under '/:foo' => sub {...};
my $route = under '/:foo' => {foo => 'bar'};
my $route = under '/:foo' => [foo => qr/\w+/];
my $route = under '/:foo' => (agent => qr/Firefox/);
my $route = under [format => 0];
Generate nested route with "under" in Mojolicious::Routes::Route, to which all following routes are automatically appended. See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
"under" in Mojolicious::Routes::Routeでブリッジを生成し、すべての続くルーティングに自動的に処理が追加されます。 さらなる情報については Mojolicious::Guides::TutorialとMojolicious::Guides::Routingを見てください。
websocket¶
my $route = websocket '/:foo' => sub {...};
my $route = websocket '/:foo' => sub {...} => 'name';
my $route = websocket '/:foo' => {foo => 'bar'} => sub {...};
my $route = websocket '/:foo' => [foo => qr/\w+/] => sub {...};
my $route = websocket '/:foo' => (agent => qr/Firefox/) => sub {...};
Generate route with "websocket" in Mojolicious::Routes::Route, matching only WebSocket handshakes. See Mojolicious::Guides::Tutorial and Mojolicious::Guides::Routing for more information.
"websocket" in Mojolicious::Routes::Routeでルーティングを生成し、WebSocket ハンドシェイクにだけマッチします。 さらなる情報については Mojolicious::Guides::TutorialとMojolicious::Guides::Routingを見てください。
属性¶
Mojolicious::Lite inherits all attributes from Mojolicious.
Mojolicious::LiteはMojoliciousからすべての属性を継承しています。
メソッド¶
Mojolicious::Lite inherits all methods from Mojolicious.
Mojolicious::LiteはMojoliciousからすべてのメソッドを継承しています。