Web Development with Perl
Total Page:16
File Type:pdf, Size:1020Kb
Web Development with Perl Paul Fenwick Jacinta Richardson Kirrily Robert Web Development with Perl by Paul Fenwick, Jacinta Richardson, and Kirrily Robert Copyright © 1999-2000 Netizen Pty Ltd Copyright © 2000 Kirrily Robert Copyright © 2001 Obsidian Consulting Group Pty Ltd Copyright © 2001-2006 Perl Training Australia Pty Ltd Copyright © 2001-2006 Paul Fenwick ([email protected]) Copyright © 2001-2006 Jacinta Richardson ([email protected]) Open Publications License 1.0 This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). Distribution of this work or derivative of this work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder. This document includes content from the CGI Programming with Perl training notes originally created by Kirrily Robert and Netizen Pty Ltd. All additional material written by Paul Fenwick and Jacinta Richardson. Copies of the Netizen training manuals can be found at http://sourceforge.net/projects/spork This training manual is maintained by Perl Training Australia. This is version 1.2 of Perl Training Australia’s "Web Development with Perl" training manual. Table of Contents 1. Introduction..................................................................................................................................... 1 Introduction................................................................................................................................. 1 Course outline ............................................................................................................................. 1 Assumed knowledge ................................................................................................................... 1 Web standards....................................................................................................................1 What we don’t cover ................................................................................................................... 1 Platform and version details........................................................................................................1 The course notes.......................................................................................................................... 2 2. What is CGI?................................................................................................................................... 3 In this chapter.............................................................................................................................. 3 Clients and servers ...................................................................................................................... 3 HTTP basics................................................................................................................................ 3 The CGI request.......................................................................................................................... 4 HTTP Methods............................................................................................................................ 4 GET ................................................................................................................................... 5 HEAD................................................................................................................................ 5 POST ................................................................................................................................. 5 HTTP Responses......................................................................................................................... 5 Chapter summary ........................................................................................................................ 6 3. Classical CGI programming.......................................................................................................... 7 In this chapter.............................................................................................................................. 7 CGI setup .................................................................................................................................... 7 Anatomy of a CGI program ........................................................................................................7 Hello World .......................................................................................................................8 Exercises............................................................................................................................ 8 The CGI.pm module ................................................................................................................... 8 An alternative ....................................................................................................................8 Functional versus object-oriented......................................................................................9 header() ....................................................................................................................................... 9 start_html() and end_html() ......................................................................................................10 Exercise ...........................................................................................................................11 Debugging CGI programs.........................................................................................................11 Failing gracefully with CGI::Carp...................................................................................11 Fatal errors .............................................................................................................12 Warnings ................................................................................................................12 Exercises..........................................................................................................................12 Environment values .........................................................................................................13 Exercises ................................................................................................................13 Chapter summary ......................................................................................................................13 4. HTML Forms................................................................................................................................15 Introduction...............................................................................................................................15 HTML generation with CGI .....................................................................................................15 The form element......................................................................................................................16 GET vs POST..................................................................................................................17 GET........................................................................................................................17 POST......................................................................................................................18 Form elements...........................................................................................................................18 Submit..............................................................................................................................18 Perl Training Australia (http://perltraining.com.au/) iii Exercises..........................................................................................................................18 Text ..................................................................................................................................19 Exercises..........................................................................................................................19 Hidden .............................................................................................................................19 Exercise..................................................................................................................19 Password..........................................................................................................................19 Exercise..................................................................................................................20 Checkbox.........................................................................................................................20 Checkbox groups ...................................................................................................20 Exercises ................................................................................................................21 Radio button groups.........................................................................................................22 Select ...............................................................................................................................22 Exercises ................................................................................................................23