Mojolicious::LiteでPOSTメソッドを使う

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env perl
use Mojolicious::Lite;

get '/' => sub {
    my $c    = shift;
    $c->render(template => 'index');
};

post '/' => sub {
    my $c    = shift;
    my $user = $c->param('user');
    $c->stash(hello => qq{Hello $user!});
    $c->render(template => 'index');
};

app->start;
__DATA__
@@ index.html.ep
<!DOCTYPE html>
<html>

<head>
    <title>title</title>
</head>

<body>
    %= form_for '/', method => 'post', begin
        %= text_field 'user'
        %= submit_button 'Submit!'
    % end
    <p><%= $hello %></p>
</body>

</html>
1
2
3
4
get '/' => sub {
    my $c    = shift;
    $c->render(template => 'index');
};
1
2
3
4
5
6
post '/' => sub {
    my $c    = shift;
    my $user = $c->param('user');
    $c->stash(hello => qq{Hello $user!});
    $c->render(template => 'index');
};
1
2
3
4
    %= form_for '/', method => 'post', begin
        %= text_field 'user'
        %= submit_button 'Submit!'
    % end

Comments

comments powered by Disqus