Mojolicious-8.12 > Mojolicious::Guides::FAQ
Mojolicious-8.12

名前

Mojolicious::Guides::FAQ - Frequently Asked Questions

Mojolicious::Guides::FAQ - 頻繁に尋ねられる質問

説明

This document contains answers for the most frequently asked questions about Mojolicious.

このドキュメントはMojoliciousに関してもっとも頻繁に尋ねられる質問と答えをふくんでいます。

質問

We hope these answers are to your satisfaction.

これらの答えがあなたを満足させるものであることを望んでいます。

Mojoliciousは他のPerlのWebフレームワークとどのように比較することができますか

The short answer is "it doesn't", because we interpret the term "web framework" much more literally than others. With the emergence of the real-time web and new technologies such as WebSockets, we are facing new challenges that go way beyond what commonly used modules like LWP were designed for. Because of this, Mojolicious contains a whole new HTTP client/server stack called Mojo, which was heavily inspired by the original LWPng effort and carefully designed with these new requirements in mind. So while some of the higher abstraction layers might look similar to other web frameworks, it is more of a web toolkit and can even be used as the foundation for more advanced web frameworks.

「Webフレームワーク」という言葉は、他のよりもより逐語的に解釈されるので、 短い答えとしては「できない」というものです。 リアルタイムWebやWebSocketのような新しいテクノロジーが出現して、 LWPのように一般的に利用されてきたモジュールが設計されたことを超えた、 新しい挑戦に直面しています。 このために、Mojoliciousは、Mojoと呼ばれる完全に新しいHTTPクライアント/サーバースタックを含んでいいます。これは、もともとはLWPngの努力によって強く鼓舞され、注意深く新しい要求のためにデザインされたものです。 それで、上位の抽象レイヤーのいくつかは、他のWebフレームワークと似ているように見えますが、 実際は完全に新しいカテゴリーとして定義され、未来のより進んだカテゴリーとして、 基礎付けられるのではないかとさえ考えています。

なぜMojoliciousはまったく依存を持たないのですか

We are optimizing Mojolicious for user-friendliness and development speed, without compromises. While there are no rules in Mojolicious::Guides::Contributing that forbid dependencies, we do currently discourage adding non-optional ones in favor of a faster and more painless installation process. And we do in fact already use several optional CPAN modules such as Cpanel::JSON::XS, EV, IO::Socket::Socks, IO::Socket::SSL, Net::DNS::Native, Plack and Role::Tiny to provide advanced functionality if possible.

私たちは妥協することなく使いやすさと開発スピードに焦点をあててMojoliciousを最適化しています。 Mojolicious::Guides::Contributingには依存を禁止するルールはありませんが、 すばやい苦労のないインストール処理を好むので、今のところオプショナルなものではないものを 追加する気持ちは起きません。 実際はすでに、高度な機能を提供するために、もしインストールされているのであれば、 Cpanel::JSON::XS, EV,IO::Socket::Socks,IO::Socket::SSL,Net::DNS::NativePlack,Role::Tinyなどのいくつかのオプショナルなモジュールを利用しています。

なぜ再発明をするのですか

Because we can make them rounder. Components specifically designed for user-friendliness and development speed are not easy to come by. We are strong believers of the Perl mantra "There is more than one way to do it", and our quest is to develop the best possible solutions for these two criteria.

それらを応用可能なものにできるからです。 使いやすさと開発スピードを焦点にあててデザインされたコンポーネントを 手に入れるのは簡単ではありません。 「ひとつ以上のやり方がある」というPerlのマントラを強く信じていますが、 よくデザインされたデフォルトはユーザーの経験によりよい楽しさをもたらすものである ということも信じています。 両方のよい部分がほしいのです。

後方互換性についてはどうですか

In conformance with Mojolicious::Guides::Contributing, we will always deprecate a feature for 3 months, before removing or changing it in incompatible ways between major releases. New features can however be marked as experimental to explicitly exclude them from these rules. This gives us the necessary freedom to ensure a healthy future for Mojolicious. So, as long as you are not using anything marked experimental, untested or undocumented, you can always count on backwards compatibility, everything else would be considered a bug. However, to completely avoid any risk of accidental breakage, we do recommend following current best practices for version pinning with Carton for production setups.

Mojolicious::Guides::Contributingとの一致において、 互換性のない方法において、削除や変更がある前に、 最新のひとつのメジャーリリースのなかで、その機能を いつも廃止予定にします。 しかしながら、新しい機能は実験的なものとマークされ、このルールの除外になっています。 これはMojoliciousの健全な未来を保証するために、必要な自由を与えます。 それで、実験的でない機能、試験されていない機能、ドキュメントされていない機能を使っていない限りは、 後方互換性をいつも期待することができ、そうでないものはバグと考えられます。 ただし、偶発的な破損のリスクを完全に回避するには、 バージョン固定の現在のベストプラクティスに従うことをお勧めします 生産セットアップ用のCarton

なぜMojoliciousは多くの小さなディストリビューションに分割されないのですか

Because there are no advantages, it drastically increases maintenance costs and installation times without giving us anything in return. It would only make sense if we wanted to pass ownership of a module to a new maintainer, which we already have done in the past.

利点がないからです。 それを行うことは、わたしたちにメリットはないですが、メンテナンスコストを大幅に情報させ、 インストールの時間を増加させます。 モジュールの所有を新しいメンテナに渡せるときだけ意味があるかもしれませんが、 わたしたちはすでに過去にそれを行っています。

Mojoliciousのパッチについてどこで議論できますか?

We'd love to discuss your contributions to Mojolicious on our official IRC channel #mojo on irc.freenode.net (chat now!).

公式IRCでMojoliciousへの貢献を議論したいと思います irc.freenode.netのチャネル#mojo((chat now!))。

どのバージョンのPerlをMojoliciousはサポートしていますか。

First of all, you need to be aware that according to the perlpolicy, only the two most recent stable release series of Perl are supported by the community and receive bug fixes, which are currently 5.28.x and 5.26.x. Mojolicious follows this model and fully supports these two release series. In addition we will also keep the distribution installable (and that means passing all tests) up to a certain legacy version that the core team deems worthy of supporting, but not specifically optimize for it, this is currently 5.10.1.

最初に、perlpolicyに関することに気がつく必要があります。 コミュニティは最近のふたつの安定したリリースだけを サポートします。これは現在は、5.28.x and 5.26.xです。 Mojoliciousはこのモデルにしがたい、これらのふたつのリリースを 完全にサポートします。 加えて、サポートする価値があると考えるある古いバージョンまで、 Mojoliciousのディストリビューションをインストールできるようにしています。 最適化はされません。これは現在は5.10.1です。

Note that Perl versions 5.10.x and 5.12.x are known to work very poorly with Mojolicious, and we strongly suggest you do not use them, to avoid stability and security issues. If it wasn't for a very vocal minority within the community we would not support these versions at all.

Perlバージョン5.10.xおよび5.12.xは、 Mojolicious、安定性を避けるためにそれらを使用しないことを強くお勧めします およびセキュリティの問題。コミュニティ内の非常にボーカルな少数派ではない場合 これらのバージョンはまったくサポートしません。

WindowsはMojoliciousでどの程度サポートされていますか?

Windows is not officially supported by Mojolicious, even though we try to keep the distribution installable. There may be serious security and/or reliability issues. Some of the more advanced features, such as subprocesses and the Hypnotoad web server, will also require the use of the Windows Subsystem for Linux.

ディストリビューションをインストール可能な状態にするよう努力しますが、 Windowsは、Mojoliciousによって公式にサポートされていません。 。深刻なセキュリティがあるか、または信頼性の問題があります。 次のようなより高度な機能の一部subprocesses and the Hypnotoad。 Webサーバーでは、次の使用も必要です。 Windows Subsystem for Linux

Mojoliciousをテストする前に、環境をクリーンにする必要がありますか

Mojolicious uses many environment variables both internally and externally, notably (but not exclusively) those starting with the prefix MOJO_* and PLACK_ENV. The test suite expects a clean environment; testing with a non-standard environment is unsupported and is unlikely to succeed. Therefore when installing or upgrading Mojolicious and when running its tests, we highly recommend using an environment which does not set these variables.

Mojoliciousは、内部的にも外部的にも、多くの環境変数を使用しています。 これらは MOJO_*PLACK_ENVというプレフィックスを持ちます。 テストケースは、クリーンな環境を想定しています。 標準ではない環境で試験を行う場合は、サポートしていません。 テストは成功しないかもしれません。 それゆえ、Mojoliciousをインストールまたはアップグレードすし、 テストを実行するときは、これらの変数を設定しない環境で、 行うことを推奨します。

ファイル拡張子は、どこに行ってしまったのですか。

Standard route placeholders will not match the . character, however Mojolicious routes automatically take file extensions like .html, remove the leading ., and store the result in the format stash value. This can be useful for URL-based content negotiation, such as automatically rendering different templates based on the file extension. See "Formats" in Mojolicious::Guides::Routing for information on customizing format detection, or consider using relaxed placeholders to allow matching of the . character.

標準のルートプレースホルダーは、.文字にはマッチしません。 しかしながら、 Mojoliciousのルートは、.htmlのようなファイル拡張子を見、 続く.を除去し、formatスタッシュ値の中に、結果を保存します。 これは、ファイル拡張子に基づいた、 自動的に描画される異なるテンプレートのような URLベースのコンテントネゴシエーションで便利です。 フォーマットのカスタマイズの情報は "フォマット" in Mojolicious::Guides::Routingを見てください。 また、"リラックスプレースホルダー" in Mojolicious::Guides::Routing を使うことを考慮してください。 これは、.文字のマッチを許可します。

コマンドラインからHypnotoadを設定できますか?

No, you can't, Hypnotoad is a bit special in this regard. Because when you initiate a zero downtime software upgrade (hot deployment), you are only really sending a USR2 signal to the already running server, and no other information can be passed along. What you can do instead, is to use a Mojolicious::Plugin::Config or Mojolicious::Plugin::JSONConfig configuration file.

いいえ、できません、Hypnotoadは、この点で少し特別です。 ダウンタイムのないソフトウェアアップグレード(ホット デプロイメント)を始めるときに、既に実行中のサーバーに対して、USR2シグナルのみを送信していますので、 他の情報を渡すことはできません。代わりに設定のために Mojolicious::Plugin::ConfigまたはMojolicious::Plugin::JSONConfigを使用してください

  # myapp.conf
  {
    hypnotoad => {
      listen  => ['http://*:8080'],
      workers => 10
    }
  };

Or if you don't actually need zero downtime software upgrades, just use Mojolicious::Command::prefork instead, which is otherwise almost identical to Hypnotoad.

または、ダウンタイムのないソフトウェアアップグレードが実際に必要ない場合は、 Mojolicious::Command::preforkを代わりに使ってください。それ以外はHypnotoadと同じです。

  $ ./myapp.pl prefork -m production -l http://*:8080 -w 10

エラー「... certificate verify failed」はどういう意味ですか?

There are many variations of this error, but most of them mean that TLS certificate verification in Mojo::UserAgent failed. This usually happens for two reasons. The most common one is that the peer certificate is simply invalid. If that's the case and you are certain that no MITM attack is being attempted, you can use the attribute "insecure" in Mojo::UserAgent or MOJO_INSECURE environment variable to disable certificate verification. And if that's not the case you might be missing the Mozilla::CA module, which is often required by IO::Socket::SSL to be able to verify certificates.

このエラーには多くのバリエーションがありますが、それらのほとんどはTLS Mojo::UserAgentでの証明書の検証に失敗したということです。これは通常 2つの理由で起こります。最も一般的なのは、ピア証明書が単に無効であることです。 その場合、MITM攻撃が試行されていないことが確実な場合、 属性"insecure" in Mojo::UserAgentまたは証明書の検証を無効にする環境変数MOJO_INSECUREを使用できます。それ以外に、Mozilla::CAモジュールが欠落している場合があります。これは多くの場合、IO::Socket::SSLによって、証明書を検証することが必要とされます。

"Maximum message size exceeded."のエラーは何を意味していますか

To protect your applications from excessively large requests and responses, our HTTP parser has a cap after which it will automatically stop accepting new data, and in most cases force the connection to be closed. The limit is 16MiB for requests, and 2GiB for responses by default. You can use the attributes "max_request_size" in Mojolicious and "max_response_size" in Mojo::UserAgent to change these values.

アプリケーションをとても大きなリクエストとレスポンスから 守るために、HTTPパーサーは、自動的に新しいデータを受け付けるのを停止する 上限を設けており、ほとんどの場合接続を切断します。 デフォルトの制限は、リクエストは16MiB、レスポンスは2GiBです。これらの値を変更するために"max_request_size" in Mojolicious"max_response_size" in Mojo::UserAgent 属性が使えます。

"Maximum start-line size exceeded."のエラーは何を意味していますか

This is a very similar protection mechanism to the one described in the previous answer, but a little more specific. It limits the maximum length of the start-line for HTTP requests and responses. The limit is 8KiB by default, you can use the attribute "max_line_size" in Mojo::Message or MOJO_MAX_LINE_SIZE environment variable to change this value.

これは、リクエスト行、ステータス行、ヘッダーなどの、HTTPメッセージの\r\nで終わる部分の最大の長さの制限です。 この制限はデフォルトで8KiBですが、"max_line_size" in Mojo::Message属性かMOJO_MAX_LINE_SIZE環境変数を使って、この値を変更することができます。

"Maximum header size exceeded"のエラーは何を意味していますか?

Almost the same as the previous answer, but this protection mechanism limits the number and maximum length of HTTP request and response headers. The limits are 100 headers with 8KiB each by default, you can use the attributes "max_lines" in Mojo::Headers and "max_line_size" in Mojo::Headers or the MOJO_MAX_LINES and MOJO_MAX_LINE_SIZE environment variables to change these values.

これは前の答えで説明されたものとほぼ同じですが、 HTTPリクエストとHTTPレスポンスのヘッダーの最大の長さの制限です。 制限は、デフォルトで、8KiB で100のヘッダです。 "max_lines" in Mojo::Headers"max_line_size" in Mojo::Headers あるはMOJO_MAX_LINESMOJO_MAX_LINE_SIZE環境変数で、 変更することができます。

"Maximum buffer size exceeded"のエラーは何を意味していますか

This protection mechanism limits how much content the HTTP parser is allowed to buffer when parsing chunked, compressed and multipart messages. The limit is around 256KiB by default, you can use the attribute "max_buffer_size" in Mojo::Content or MOJO_MAX_BUFFER_SIZE environment variable to change this value.

この保護のメカニズムは前のふたつの答えとよく似ています。 HTTPパーサーは、チャンク化、圧縮、マルチパートメッセージを解析しますが、 どれくらいの量のコンテンツをバッファリングするかの制限です。 この制限はデフォルトでは 256KiB ですが、MOJO_MAX_BUFFER_SIZE環境変数 を使って変更することができます。

"Your secret passphrase needs to be changed"は何を意味していますか

Mojolicious uses secret passphrases for security features such as signed cookies. It defaults to using "moniker" in Mojolicious, which is not very secure, so we added this log message as a reminder. You can change the passphrase with the attribute "secrets" in Mojolicious. Since some plugins also depend on it, you should try changing it as early as possible in your application.

Mojoliciousは暗号化クッキーのようなセキュリティの機能のための秘密のパスフレーズを使用します。 デフォルトではアプリケーション名ですが、これはあまり安全とはいえません。 ですので記憶しておいてもらうために、デフォルトのログメッセージ追加しています。 "secrets" in Mojolicious属性でこのパスフレーズを変更することができます。

  $app->secrets(['My very secret passphrase.']);

"What does "Nothing has been rendered, expecting delayed response"は何を意味していますか

Mojolicious has been designed from the ground up for non-blocking I/O and event loops. So when a new request comes in and no response is generated right away, it will assume that this was intentional and return control to the web server, which can then handle other requests while waiting for events such as timers to finally generate a response.

MojoliciousはノンブロッキングI/Oとイベントループの上に構築されるように設計されています。 それで、リクエストが入ってきてすぐにレスポンスが返ってこないときは、 それは意図的なものだと解釈してWebサーバーに応答を返します。 Webサーバーは、タイマーのようなイベントを待っている間に、他のリクエストを処理し、 レスポンスを生成します。

"Inactivity timeout."は何を意味していますか。

To protect your applications from denial-of-service attacks, all connections have an inactivity timeout which limits how long a connection may be inactive before being closed automatically. It defaults to 20 seconds for the user agent and 15 seconds for all built-in web servers, and can be changed with the attributes "inactivity_timeout" in Mojo::UserAgent and "inactivity_timeout" in Mojo::Server::Daemon or the MOJO_INACTIVITY_TIMEOUT environment variable. In Mojolicious applications you can also use the helper "inactivity_timeout" in Mojolicious::Plugin::DefaultHelpers to change it on demand for each connection individually. This timeout always applies, so you might have to tweak it for applications that take a long time to process a request.

アプリケーションをDoS攻撃から守るために、 すべての接続は非アクティブタイムアウトを持っています。 自動的にドロップする前に、どの程度の時間接続が非アクティブでいることができるかを制限 するものです。 デフォルトでは、ユーザーエージェントのために20秒が、すべての組み込みサーバーのために 15秒が設定されています。そしてこれは"inactivity_timeout" in Mojo::UserAgent"inactivity_timeout" in Mojo::Server::Daemon 属性またはMOJO_INACTIVITY_TIMEOUT 環境変数で変更できます。 Mojolicious アプリケーションは、それぞれの接続毎にオンデマンドでこれを変更するために"inactivity_timeout" in Mojolicious::Plugin::DefaultHelpers ヘルパーも使えます。 このタイムアウトはいつでも適用されるので、 リクエストを処理するために、長い時間が必要となるアプリケーションのために、 微調整する必要があるかもしれません。

"Premature connection close."は何を意味していますか

This error message is often related to the one above, and means that the web server closed the connection before the user agent could receive the whole response or that the user agent got destroyed, which forces all connections to be closed immediately.

このエラーメッセージは、上記のひとつに関連して発生します。 ユーザーエージェントが完全なレスポンスを受け取る前に、 Webサーバーが接続を閉じたということを意味しています。 あるいは、ユーザーエージェントが破棄されたということを意味しています。 こうなった場合は、すべてのコネクションが強制的に閉じられます。

  # The variable $ua goes out of scope and gets destroyed too early
  Mojo::IOLoop->timer(5 => sub {
    my $ua = Mojo::UserAgent->new;
    $ua->get('https://mojolicious.org' => sub {
      my ($ua, $tx) = @_;
      say $tx->result->dom->at('title')->text;
    });
  });

"Worker 31842 has no heartbeat (30 seconds), restarting"は何を意味していますか。

As long as they are accepting new connections, worker processes of all built-in pre-forking web servers send heartbeat messages to the manager process at regular intervals, to signal that they are still responsive. A blocking operation such as an infinite loop in your application can prevent this, and will force the affected worker to be restarted after a timeout. This timeout defaults to 30 seconds and can be extended with the attribute "heartbeat_timeout" in Mojo::Server::Prefork if your application requires it.

Hypnotoadワーカープロセスは、マネージャプロセスに、まだ応答可能かどうかを調べるために 定期的な間隔でハートビートメッセージを送ります。 アプリケーションの無限ループのようなブロッキング操作がこれによって防止され、 影響を受けたワーカーがタイムアウトの後にリスタートされます。 "heartbeat_timeout" in Mojo::Server::Preforkのデフォルトは30秒で アプリケーションが必要とすれば、増加させることができます。

What does "Transaction already destroyed" mean?

This error message usually appears after waiting for the results of a non-blocking operation for longer periods of time, because the underlying connection has been closed in the meantime and the value of the attribute "tx" in Mojolicious::Controller is no longer available. While there might not be a way to prevent the connection from getting closed, you can try to avoid this error message by keeping a reference to the transaction object that is not weakened.

基礎となる接続が、接続時間経過で、閉じられ、"tx" in Mojolicious::Controllerがもはや利用可能でないため、 このエラーメッセージは通常、ノンブロッキング操作の結果を長く待った後に表示されます。 接続が閉じられないよう回避する方法はないですが、このエラーメッセージをトランザクションのリファレンスを 弱参照しないで、維持することによって避けるようにすることができます。

  # Keep a strong reference to the transaction object
  my $tx = $c->render_later->tx;
  $c->ua->get_p('https://mojolicious.org')->then(sub {
    $c->render(text => 'Visited mojolicious.org');
  })->catch(sub {
    my $err = shift;
    $tx;
    $c->reply->exception($err);
  });
  # トランザクションオブジェクトへの強い参照を保持する
  my $tx = $c->render_later->tx;
  $c->ua->get_p('https://mojolicious.org')->then(sub {
    $c->render(text => 'Visited mojolicious.org');
  })->catch(sub {
    my $err = shift;
    $tx;
    $c->reply->exception($err);
  });

より学ぶには

You can continue with Mojolicious::Guides now or take a look at the Mojolicious wiki, which contains a lot more documentation and examples by many different authors.

Mojolicious::Guidesを学び続けてください。また<a href="http://github.com/kraih/mojo/wiki" class="podlinkurl" >Mojolicious wiki</a>を見ることもできます。wikiには多くのユーザーによる多くのドキュメントやサンプルがあります。

サポート

If you have any questions the documentation might not yet answer, don't hesitate to ask on the mailing list or the official IRC channel #mojo on irc.freenode.net (chat now!).

ドキュメントに答えが見つからなくって質問があるときは、mailing listか 公式のIRCチャンネルであるirc.perl.org#mojo(chat now!)でためらわずに質問してください。