mojolicious perl web 框架学习一

以前是通过传统模式安装的,以下是通过perlbrew 安装以及使用

安装perlbrew

参考https://perlbrew.pl/

安装perl

注意选择需要5.20 以及的版本

perlbrew install perl-5.32.0
perlbrew switch perl-5.32.0

安装mojolicious

基于以上配置的perl 环境

curl -L https://cpanmin.us | perl - -M https://mirrors.tuna.tsinghua.edu.cn/CPAN/ -n Mojolicious

使用cli 命令

  • 支持的cli
Usage: APPLICATION COMMAND [OPTIONS]
  mojo version
  mojo generate lite-app
  ./myapp.pl daemon -m production -l http://*:8080
  ./myapp.pl get /foo
  ./myapp.pl routes -v
Tip: CGI and PSGI environments can be automatically detected very often and
     work without commands.
Options (for all commands):
  -h, --help          Get more information on a specific command
      --home <path>   Path to home directory of your application, defaults to
                      the value of MOJO_HOME or auto-detection
  -m, --mode <name>   Operating mode for your application, defaults to the
                      value of MOJO_MODE/PLACK_ENV or "development"
Commands:
 cgi       Start application with CGI
 cpanify   Upload distribution to CPAN
 daemon    Start application with HTTP and WebSocket server
 eval      Run code against application
 generate  Generate files and directories from templates
 get       Perform HTTP request
 inflate   Inflate embedded files to real files
 prefork   Start application with pre-forking HTTP and WebSocket server
 psgi      Start application with PSGI
 routes    Show available routes
 version   Show versions of available modules
See 'APPLICATION help COMMAND' for more information on a specific command.
  • 创建一个项目
mojo generate lite-app demoapp

效果

 

 

 


 

 

 

  • 运行
 
morbo demoapp
  • 部署
    推荐基于hypnotoad
 
hypnotoad ./demoapp
  • 容器部署模式
    参考
 
FROM perl:5.26
RUN cpan install  Mojolicious::Lite \
    && mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY demoapp /usr/src/app/
ENTRYPOINT [ "sh","/usr/src/app/demoapp","daemon","-m","production","-l","http://*:8080" ]

参考资料

https://perlbrew.pl/
https://mojolicious.org/
http://mirrors.ustc.edu.cn/
https://docs.mojolicious.org/Mojo/Server/Hypnotoad

posted on   荣锋亮  阅读(471)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-12-20 perfview微软开源的cpu以及内存性能分析工具
2018-12-20 How_Require_Extensions_Work
2018-12-20 nodejs-hook 开发
2016-12-20 rabiitmq集群完整安装
2014-12-20 Mysql 批量插入数据的方法
2013-12-20 silverlight 进行本地串口调用的一种可行的解决方法 之silverlight端代码

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示