zoukankan      html  css  js  c++  java
  • MojoliciousLite: 实时的web框架 概述

    MojoliciousLite:  实时的web框架:
    
    SYNOPSIS 简介:
    
     #  Automatically enables "strict", "warnings", "utf8" and Perl 5.10 features
        use Mojolicious::Lite;
      
           # Route with placeholder
            get '/api/:foo' => sub {
            my $c   = shift;
            my $foo = $c->param('foo');
            $c->render(text => "Hello from $foo.");
                   };
      
                        # Start the Mojolicious command system
            app->start;
    
    
    zjzc01:/root/mojo# curl http://127.0.0.1:3000/api/xx
    Hello from xx.
    
    zjzc01:/root/mojo# curl http://127.0.0.1:3000/api/abc123
    Hello from abc123.zjzc01:/root/mojo# 
    
    描述:
    
    Mojolicious::Lite 是一个微型实时框架:
    
    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 {...};
    
    
    声明 route 为any 在Mojolicious::Routes::Route, 匹配所有的HTTP 请求方法或者all.
    
    app
    
    my $app=app;
    
    返回Mojolicious::Lite 应用对象
    
      # Use all the available attributes and methods
      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 {...};
    
    
    匹配DELETE 请求
    
    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 {...};
    
    
    只匹配get请求
    
    
    group 
    
      group {...}
    
    开始一个route group
    
    
    
    Routes:
    
    Routes 只是对请求过来的路径指向不同的函数,可以在路径中包含不同的占位符,
    
    传进来的一个参数是$c  是 Mojolicious::Controller 对象本身,它也包含着HTTP request和HTTP reponse的对象:
    
    
    GET/POST 传进来的参数:
    
    use Mojolicious::Lite;
    
    # /foo?user=sri
    get '/foo' => sub {
      my $c = shift;
      my $user = $c->param('user');
      $c->render(text => "Hello $user.");
    };
    
    app->start;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

  • 相关阅读:
    OpenGL第十节:彩色键控与混合
    OpenGL第九节:操作像素点去更新纹理
    OpenGL第八节:非二次幂的纹理渲染处理
    OpenGL第七节:纹理绘制裁剪图片的指定部分
    OpenGL第六节:加载png图片
    OpenGL第五节:纹理贴图和像素操作
    OpenGL第四节:滚动和矩阵栈
    OpenGL第三节:Viewport视口
    OpenGL第二节:绘制多个颜色四边形
    TextView关键字高亮
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350908.html
Copyright © 2011-2022 走看看