Form プラグイン

Form プラグインは、HTML::AutoForm を利用した HTML フォームの構築と検証機能を提供します。
package myapp::start;

use strict;
use warnings;
use utf8;

use plugin::form;

use base qw(NanoA);

define_form(
    fields => [
        title => {
            type       => 'text',
            label      => 'タイトル',
            # validation
            required   => 1,
            max_length => 16,
        },
        body  => {
            type       => 'textarea',
            label      => 'メッセージ',
            # validation
            required   => 1,
        },
    ],
);

sub run {
    my $app = shift;
    
    if ($query->request_method eq 'POST' && $app->validate_form) {
        # フォーム投稿を処理して、自分自身にリダイレクト
        ...
        $app->redirect;
    }
    
    # 情報を表示
}