Learn Web.Development of Perl

#####
#Overview of Web.Development related modules.
#Note that, below codes can not be executed just for overview intention.
#####

#!/usr/bin/perl

#CGI::FormBuilder::Source::Perl

#Dancer, A lightweight yet powerful web application framework

#HTML::FormHandler, HTML forms using moose

#MIME::Types, Definition of MIME types

#Mojolicious, Real-time web framework

#Plack, Flexible superglue between web servers and perl web frameworks or code

#Task::Catalyst, The elegant MVC web application framework.

#Template, Template processing system

#XML::Atom, atom feed and API implementation

#XML:RSS, Creates and updates RSS files

#####
#Dancer
#If you don't want to write CGI scripts by hand, and find Catalyst too big or
#cumbersome for your project, Dancer is what you need.
#####

use Dancer;

get '/hello/:name' => sub {
  return "why, hello here" . param('name');
};

dance;

#####
#HTML::Formhandler
#####

#arributes and methods
#-creating a form
#-processing the form
#-getting data out
#-accessing and setting up fields
#-constraints and validation
#-accessing errors
#-clear form state
#-miscellaneous atrributes
#-Flags

use HTML::FormHandler; #or a custom form: use MyApp::Form::User;

my $form = HTML::FormHandler->new( ... );
$form->process( params => $params );
my $rendered_form = $form->render;
if ($form->validated) {
  #perform validated form actions
}
else {
  #perform non-validated actions

  #or, return a result
  $result->render;
}

#a dynamic form
my $form = HTML::Formhandler->new(
  name => 'user_form',

  field_list => [
    'username' => {
      type => 'Text',
      apply => [ { check => qr/^[0-9a-z]*\z/,
        message => 'contains invalid characters' } ],
    },

    'select_bar' => {
      type => 'select',

      options => \@select_options,
      multiple => 1,
      size => 4,
    }
    ,
  ],
);

#####
#MIME::Types
#####

use MIME::Types;

my $mt = MIME::Types->new(...);  # MIMI::TYpes object
my $type = $mt->type('text/plain');  # MIMI::Type object
my $type = $mt->mimeTypeOf('gif');
my $type = $mt->mimeTypeOf('picture.jpg');
my $type = $mt->httpAccept('text/html, application/json;q=0.1');

#####
#Mojolicious, real-time web framwork.
#####

#hooks
#atrributes
#methods
#autoload
#bundled files

# Application
package MyApp;
use Mojo::Base 'Mojolicious';

# Route
sub startup {
  my $self = shift;
  $self->routes->get('/hello')->to('fool#hello');
}

# Controller
package MyApp::Controller::Foo;
use Mojo::Base 'Mojolicious::Controller';

# Action
sub hello {
  my $self = shift;
  $self->render(text => 'hello world!');
}

##hooks

#after_build_tx
$app->hook(after_build_tx =>sub {
  my ($tx, $app) = @_;
  ...
});

#before_dispatch
$app->hook( before_dispatch => {
  my $c = shift;
  ...
});

#after_static
$app->hook(after_static => sub {
  my $c = shift;
  ...
});

#before_routes
$app->hook(before_routes => sub {
  my $c = shift;
  ...
});

#around_action
#before_render
#after_render
#after_dispatch
#around_dispatch

#####
#Plack, perl superglue for web frameworks and web servers(PSGI toolkit)
#####

#modules and utilities

#plack::handler

#plack::loader

#plack::util

#psgi files

#plackup, plack::runner

#plack::middleware

#plack::request, plack::response

#plack::test

#plack:test::suite

>>
More of Perl Web.Development

Mars

时间: 2024-11-05 16:11:35

Learn Web.Development of Perl的相关文章

Learn Web.Crawling of Perl

##### #Overview of Web.Crawling related modules. #Note that, below codes can not be executed just for overview intention. ##### #!/usr/bin/perl ##### #HTTP::Thin ##### use 5.12.1; use HTTP::Request::Common; use HTTP::Thin; say HTTP::Thin->new()->req

Plan for Perl Web Development

Plan for Perl Web Development [2015/2/8 to 2015/4/1] Perl Foundation (Task::Kensho,DBDev: Database Development,XML: XML Development) Web Foundation (Task::Kensho::WebCrawling: Web Crawling) Web Development (Task::Kensho::WebDev: Web Development) Web

Flask Web Development - Flask 模板1 - 模板机制&Jinja2引擎

节选自PartI Chapter3,这个chapter主要讲模板工作原理,这里讲的就是Jinja2这个模板,另外还提到了Flask-Bootstrap及Flask-Moment两个插件,前者对Flask使用Bootstrap做了些封装,后者对moment.js做了些封装.内容较多,估计分开搞. 模板存在的意义 可维护性高的代码是结构良好且整洁的. 当用户在网站注册一个账户时,他在表单里填入邮箱跟密码,并点击提交按钮.在server端就收到一个包含这些数据的request,再由Flask分发到相应

Flask Web Development - Flask插件机制&Flask-Script

本节取自part I chapter 2的后半部分,跳过了关于request与response具体交互设计细节内容.主要通过Flask-Script插件让读者对于插件系统有个简单认识. Flask注重拓展性,社区里已经有很多插件可供选择,当然也可以使用python标准库或者其他的各种库. Flask-Script Flask-Script这个插件,是用来增加Flask应用的命令行参数的,它本身自带了一些通用的选项,也支持自定义的命令.这功能可能类似于python标准库中的argparse. 之前

web development blog(转)

Top 10 jQuery Mobile Code Snippets that you need to know jQuery Mobile is a framework for mobile web apps and mobile websites with an aim to provide a unified user interface system across many mobile device platforms such iPhone, BlackBerry, Android

《Flask Web Development》学习笔记---chapter4 Web Forms

1.  我们用 wrapper了WTForms的Flask-WTF扩展来处理表单生成和验证. 2.  Cross-Site Request Forgery (CSRF) 保护 配置config,'SECRET_KEY' 3. Form class definition from flask.ext.wtf import Form from wtforms import StringField, SubmitField from wtforms.validators import Required

flask web development 阅读笔记

在flask应用中,所有的flask应用都必须创建一个应用实例.web服务器把它接收的来自客户端的请求通过WSGI的协议传递给这个对象以进行处理.这时候,它会提供一种叫上下文的神奇环境,它能让一些对象可以全局可见,这样你的视图函数就可以去访问这些对象做些处理,而又在同时有那么多请求时确保线程安全. flask里有两种上下文,应用上下文和请求上下文,这两种上下文里暴露出了4种变量: 应用上下文 current_app 活动应用程序的应用实例 应用上下文 g 在处理请求时临时存储数据,每次请求都会被

<flask web development>学习记录

1 @app.route('/', methods=['GET', 'POST']) 2 def index(): 3 name = None 4 form = NameForm() #将form设置为NameForm类 5 if form.validate_on_submit(): #如果有数据提交的话 6 name = form.name.data #就让name=提交的数据 7 form.name.data = '' #并且把submit栏清空 8 return render_templa

Node with React: Fullstack Web Development 课程手记(二)——Google OAuth

OAuth OAuth是一个关于授权(authorization)的开放网络标准,在全世界得到广泛应用,目前的版本是2.0版.常见的采用微信.QQ.微博.Facebook.Google账号登陆网站的过程都是采用了OAuth技术.这一章我们会以使用Google账号登陆第三方网站为例,展示如何使用这项技术. Google OAuth工作流程 整个OAuth过程主要设计三个方面,客户端(对于网站而言则是浏览器).第三方服务器(对应网站的服务器)和Google服务器.当用户点击使用Google账号登陆网