[SP-pm] Conexão Catalyst com o Banco de dados Postgre

Wallace Reis wallace at reis.org.br
Thu Nov 11 06:51:16 PST 2010


On 11/11/2010, at 11:09, Nelson Ferraz wrote:
> O que poderia ser mais simples?
> 
> http://mojolicious.org/
> 
> http://search.cpan.org/dist/Mojolicious/lib/Mojolicious/Lite.pm

package MyForm;

use Web::Simple;

dispatch {
  sub (GET) {
    $self->show_form;
  },
  sub (POST + %name=) {
    $self->save_data($_[1]);
  }
};

sub show_form {
  use HTML::Tags;
  my ($self) = @_;
  [ 200, [ 'Content-Type' => 'text/html' ], [ HTML::Tags::to_html_string(
    <html>, <head>, <title>, "My form", </title>, </head>,
    <body>,
      <form method="POST">,
        "Name: ", <input type="text" name="name"/>,
        <input type="submit">
      </form>,
    </body>,
    </html>
  ) ] ];
}

sub save_data {
  my ($self, $name ) = @_;
  # coloque código para inserir dado na base de dados aqui
}

__PACKAGE__->run_if_script;

Tem mais linhas de código, mas você pode usar Plack e fazer deploy usando
CGI, FCGI, Starman, etc, sem precisar escrever mais nada:

$ plackup -s Starman -p 3000 MyForm

--
   wallace reis/wreis  http://wallace.reis.org.br/


More information about the SaoPaulo-pm mailing list