perl web Mojolicious::Lite

youtube cpan 官方文档

hello world

#!/use/bin/perl
use v5.26;
# use utf8;
use autodie;
use warnings;
use Mojolicious::Lite;

get '/' =>  { text => "Hello world" };
app->start;

morbo main.perl
Server available at http://127.0.0.1:3000

路由

#!/use/bin/perl

use v5.26;
# use utf8;
use autodie;
use warnings;

use Mojolicious::Lite;
 
# Route with placeholder
#get '/' => sub {
  #text => "Hello world";
#};


get '/' =>  { text => "Home page" };
 
# get '/echo' => {
#   # 直接返回一个 html字符串
#   text => q{
#     <form method='post'>
#       <input type=text name =username />
#       <input type=submit value =Echo />
#     </form>
# }};
get '/echo' => sub {
  my $c = shift;
  $c->render('echo'); # 渲染html模板
};

# 返回字符窜
# post '/echo' => sub {
#   my $c = shift;
#   $c->render(text => $c->param('username'));
# };
post '/echo' => sub {
  my $c = shift;
  $c->render('res', username => $c->param('username'));
};

# Start the Mojolicious command system
app->start;

__DATA__

@@ echo.html.ep
% my $btnText = 'Click me~';
<h2> hi~ </h2>
<form method='post'>
  <input type=text name =username />
  <input type=submit value ='click me' />
</form>

@@ res.html.ep
<p>hello <%= $username %></p>
posted @ 2018-09-13 20:18  Ajanuw  阅读(202)  评论(0编辑  收藏  举报