mojolicious perl web 框架学习一
以前是通过传统模式安装的,以下是通过perlbrew 安装以及使用
安装perlbrew
安装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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.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端代码