Perl

From OpenWetWare

(Difference between revisions)
Jump to: navigation, search
(CGI::Application)
Current revision (16:45, 13 April 2007) (view source)
(Toolkits)
 
(37 intermediate revisions not shown.)
Line 1: Line 1:
-
==CGI==
+
__NOTOC__
-
===Modules===
+
*[http://cpan.org/ CPAN]: Comprehensive Perl Archive Network
-
====CGI::Application====
+
*[http://www.perl.org/ The Perl Directory] - perl.org
-
*builds upon CGI adding a structure for writing truly reusable Web-applications
+
**[http://perldoc.perl.org/ Perl documentation]
-
*"run-mode" - single screen of an application
+
**[http://www.perldoc.com/perl5.8.0/pod/perlintro.html Introduction to Perl]
-
*"Mode Parameter" is used to store (and retrieve) the current run-mode of your application
+
**[http://faq.perl.org/ FAQs]
-
*maps each run-mode to a specific Perl subroutine ("Run-Mode Method") that implements the behavior of a single run-mode
+
*[http://www.perl.com/ Perl.com]
-
*an "abstract class", and is only used via inheritance
+
**[http://www.perl.com/pub/q/faqs FAQs]
-
package Your::Web::Application;
+
*[http://www.cs.cmu.edu/People/rgs/pl-exp-op.html Perl 4 operators]
-
use base 'CGI::Application';
+
*[http://use.perl.org/~ziggy/journal/26131 Manipulexity and Whipuptitude]
-
*setup() method defines a map between run-modes and run-mode methods
+
*[http://www.perl.com/pub/a/2006/01/12/what_is_perl_6.html perl.com: What Is Perl 6]
-
*run-mode methods are responsible for setting up the HTTP and HTML output
+
*[http://stuff.mit.edu/iap/perl/ SIPB IAP 2006 Perl Programming]
-
*run-mode methods should never print() anything to STDOUT
+
*[http://perldoc.perl.org/index-language.html Language reference] - perldoc.perl.com
-
*run() method is singularly responsible for actually sending all HTTP headers and HTML content to the Web browser
+
**[http://perldoc.perl.org/perlsyn.html perlsyn]
-
*your run-mode method is called by the run() method, and your code is expected to return a scalar containing all your HTML content
+
*[http://stein.cshl.org/genome_informatics/ Genome Informatics lectures] by Lincoln Stein
-
*header_type() and header_props() allow to change the default HTTP headers
+
**[http://stein.cshl.org/cgi-bin/perlref Perl Function Documentation] - lookup function description by its name
-
*"Instance Script" manages a single "instance" of your "Application Module"
+
-
*widgetview.cgi - instance script
+
-
#!/usr/bin/perl -w
+
-
use WidgetView;
+
-
my $app = WidgetView->new();
+
-
$app->run();
+
-
*WidgetView.pm - application module, must be in Perl's search path (@INC)
+
-
<pre><nowiki>
+
-
  package WidgetView;
+
-
  use base 'CGI::Application';
+
-
  use strict;
+
-
  # Needed for our database connection
+
==Recipes==
-
  use DBI;
+
*[http://sedition.com/perl/code-index.html Code index]
 +
*[http://www.perlcircus.org/ Perl Circus] - Perl Tricks, Tips And Traps
 +
*[[Perl/Closures|Closures]]
 +
*[[Perl/Modules|Modules]]
 +
*[http://sial.org/howto/perl/ Perl howto] @ sial.org
 +
*[http://www.perl.com/pub/a/2006/03/02/ajax_and_perl.html Using Ajax from Perl] @ perl.com
 +
*[http://www.perl.com/pub/a/2005/07/14/bestpractices.html Ten Essential Development Practices] @ perl.com
-
  sub setup {
+
==Toolkits==
-
my $self = shift;
+
*[[Perl/CGI|CGI]]
-
$self->start_mode('mode1');
+
**[http://perldoc.perl.org/CGI.html CGI - perldoc.perl.org]
-
$self->run_modes(
+
**[http://search.cpan.org/dist/CGI.pm/ CGI.pm - Lincoln D. Stein]
-
'mode1' => 'showform',
+
**[http://search.cpan.org/~markstos/CGI-Application-4.05/lib/CGI/Application.pm CGI::Application] - Framework for building reusable web-applications
-
'mode2' => 'showlist',
+
**[http://www.perl.com/pub/a/2001/06/05/cgi.html Using CGI::Application]
-
'mode3' => 'showdetail'
+
*[[Perl/DBI|DBI]]
-
);
+
*[[BioPerl]]
-
# Connect to DBI database
+
===Web development frameworks===
-
$self->param('mydbh' => DBI->connect());
+
*[http://www.catalystframework.org/ Catalyst]
-
  }
+
**[http://www.perl.com/pub/a/2005/06/02/catalyst.html perl.com: Catalyst]
 +
*[http://jifty.org/ Jifty]
 +
**[http://stuff.mit.edu/iap/webapps/ MIT IAP 2007 class]
-
  sub teardown {
+
===GUI===
-
my $self = shift;
+
*[http://www.perl.com/pub/a/2001/03/gui.html Writing GUI Applications in Perl/Tk]
 +
*[http://www.perl.com/pub/a/2001/09/12/wxtutorial1.html wxPerl: Another GUI for Perl]
-
# Disconnect when we're done
+
==Books==
-
$self->param('mydbh')->disconnect();
+
*[http://www.cs.cf.ac.uk/Dave/PERL/perl_caller.html Practical Perl Programming]
-
  }
+
*[http://en.wikibooks.org/wiki/Programming:Perl Programming:Perl] - a wikibook
-
 
+
*[http://freecomputerbooks.com/langPerlBooks.html Misc Perl books online]
-
  sub showform {
+
*[http://www.unix.org.ua/perl/ Введение в Perl]
-
my $self = shift;
+
-
 
+
-
# Get CGI query object
+
-
my $q = $self->query();
+
-
 
+
-
my $output = '';
+
-
$output .= $q->start_html(-title => 'Widget Search Form');
+
-
$output .= $q->start_form();
+
-
$output .= $q->textfield(-name => 'widgetcode');
+
-
$output .= $q->hidden(-name => 'rm', -value => 'mode2');
+
-
$output .= $q->submit();
+
-
$output .= $q->end_form();
+
-
$output .= $q->end_html();
+
-
 
+
-
return $output;
+
-
  }
+
-
 
+
-
  sub showlist {
+
-
my $self = shift;
+
-
 
+
-
# Get our database connection
+
-
my $dbh = $self->param('mydbh');
+
-
 
+
-
# Get CGI query object
+
-
my $q = $self->query();
+
-
my $widgetcode = $q->param("widgetcode");
+
-
 
+
-
my $output = '';
+
-
$output .= $q->start_html(-title => 'List of Matching Widgets');
+
-
 
+
-
## Do a bunch of stuff to select "widgets" from a DBI-connected
+
-
## database which match the user-supplied value of "widgetcode"
+
-
## which has been supplied from the previous HTML form via a
+
-
## CGI.pm query object.
+
-
##
+
-
## Each row will contain a link to a "Widget Detail" which
+
-
## provides an anchor tag, as follows:
+
-
##
+
-
##  "widgetview.cgi?rm=mode3&widgetid=XXX"
+
-
##
+
-
##  ...Where "XXX" is a unique value referencing the ID of
+
-
## the particular "widget" upon which the user has clicked.
+
-
 
+
-
$output .= $q->end_html();
+
-
 
+
-
return $output;
+
-
  }
+
-
 
+
-
  sub showdetail {
+
-
my $self = shift;
+
-
 
+
-
# Get our database connection
+
-
my $dbh = $self->param('mydbh');
+
-
 
+
-
# Get CGI query object
+
-
my $q = $self->query();
+
-
my $widgetid = $q->param("widgetid");
+
-
 
+
-
my $output = '';
+
-
$output .= $q->start_html(-title => 'Widget Detail');
+
-
 
+
-
## Do a bunch of things to select all the properties of 
+
-
## the particular "widget" upon which the user has
+
-
## clicked.  The key id value of this widget is provided
+
-
## via the "widgetid" property, accessed via the CGI.pm
+
-
## query object.
+
-
 
+
-
$output .= $q->end_html();
+
-
 
+
-
return $output;
+
-
  }
+
-
</nowiki></pre>
+
-
References
+
-
*[http://www.perl.com/pub/a/2001/06/05/cgi.html Using CGI::Application]
+
-
*[http://search.cpan.org/~markstos/CGI-Application-4.05/lib/CGI/Application.pm CPAN]
+
-
*[http://cgiapp.erlbaum.net/cgi-bin/cgi-app/index.cgi Wiki]
+
-
 
+
-
====CGI::Builder====
+
-
*[http://search.cpan.org/~domizio/CGI-Builder-1.35/lib/CGI/Builder.pm CPAN]
+

Current revision

Recipes

Toolkits

Web development frameworks

GUI

Books

Personal tools