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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值