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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。