My Perl Libs


NAME

     EL::cgi - Perl API to CGI an mod_perl programing


SYNOPSIS

     use EL::cgi;
     my $cgi = EL::cgi->new;


DESCRIPTION

     This lib  retry parameters  send by  HTTP POST  and GET  form submit
     method, valid and then create HTML out using a template. It do other
     things too, as embeded parameters in URL and redirection.
     This lib  uses the template  paradigm, therefore  I think to  be the
     more organized and productive way to CGI programing.

METHODS

     $cgi->get($param) or $cgi->get()
         Get parameters send by HTTP POST and GET form submit method.
     
     
     $cgi->set($param,$value) or $cgi->set(%params)
         Set parameters that will be include in template file. Parameters
         receive  by  HTTP  POST  and  GET form  submit  method  are  set
         automatically.
     $cgi->file($param,$info)
         Get files submitted by '<input type="file">', where $info is:
             name: name of the file, the same that $cgi->get($param)
             size: size (in bytes) of the file
             type: type (ex.: text/html) of the file
             data: data of the file
     
     
     $cgi->url($name,$value)
         Embeded parameters in URLs.
     
     
     $cgi->redirect($url)
         Redirect HTTP request to URL especified in `$url'.
     
     
     $cgi->valid({ %rex })
         Valid  parameters with  base in  regular expressions  defined in
         hash.
     
     
     $cgi->out($template')
         Send HTML output.


EXAMPLE

     -- PERL FILE: calc.pl
     use strict;
     use EL::cgi;
     my $cgi = EL::cgi->new;
     my %h = (
         op1 => {
             dsc => 'Operator 1',
             rex => '\d+',
             msg => 'Type any number !!',
         }
         ope => {
             dsc => 'Operation',
             rex => '[+-*/]',
             msg => 'Operation are "+", "-", "*", "/"',
         }
         ope2 => {
             dsc => 'Operator 2',
             rex => '\d+',
             msg => 'Type any number',
         }
     );
     if (not $cgi->valid({%h})) {
         $cgi->set('error_msg',$cgi->error_msg);
     }
     else {
         my $r = eval '$r = ' $cgi->get('op1') . $cgi->get('ope') . $cgi->get('op2');
         $cgi->set('result',$r);
     }
     $cgi->out('calc.html');
     >
     -- TEMPLATE FILE: calc.html
     <form action="calc.pl" method="post">
         <input type="text" name="op1" value="<TMPL_VAR op1>">
         <select name="ope">
             <option value="+">
             <option value="-">
             <option value="*">
             <option value="/">
         </select>
         <input type="text" name="op2" value="<TMPL_VAR op2>">
         =
         <b>
         <TMPL_VAR result>
         </b>
     </form>


AUTHORS

     Ednardo Lobo <ednardo@elobo.cjb.net>


SEE ALSO

     EL::lib, HTML::Template