Perl Modules Darby Tien-Hao Chang Department of Electrical Engineering, National Cheng Kung University.

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

Adding Dynamic Content to your Web Site
CGI Programming.
CGI Programming Part 2. Input Tags Many different ways of getting data from the user. The tag is used most often. has a type attribute –Specifies the.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
How the web works: HTTP and CGI explained
PZ15A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ15A - The Internet Programming Language Design and.
Hypertext Transport Protocol CS Dick Steflik.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Common Gateway Interface
1 ‘Dynamic’ Web Pages So far, we have developed ‘static’ web-pages, e.g., cv.html, repair.html and order.html. There is often a requirement to produce.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
CS 1704 Introduction to Data Structures and Software Engineering.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
Overview A plain HTML document is static A CGI program is executed in real-time, so that it can output dynamic information. CGI (Common Gateway Interface)
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
CGI with Perl Darby Tien-Hao Chang (a.k.a. dirty) Department of Electrical Engineering, National Cheng Kung University.
CGI programming Using Apache. Concepts Browser prepares parameter list List is attached to name of program to run on server "submit" button sends string.
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
Topic 9: The World Wide Web CSE2395/CSE3395 Perl Programming Camel3 page 878 LWP, lwpcook, CGI manpages.
CP476 Internet Computing CGI1 CGI is a common way to provide for specific computations on server side, interactions with users, or access to databases.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
USING PERL FOR CGI PROGRAMMING
Tcl/2k Conference, slide 1 TclHttpd The Tcl Web Server Brent Welch ftp.scriptics.com/pub/tcl/httpd.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
CSU - DCE Advanced Perl CGI Operation - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) on the.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
Hélène kay Webdiva Consultants Dreamweaver Week 8 hélène kay hélène kay.
CGI Programming. What is it? CGI –Common Gateway Interface Standard way to pass information back to the Web Server –GET Query String –POST Standard Input.
1 Basic Perl CGI Programming. 2 Issues How and when your program is invoked. Generating Response –HTTP Headers –HTML (or whatever document type you want)
Chapter 9: Perl and CGI Programming CGI Programming Acknowledgement: Some materials are taken from Teach Yourself CGI Programming with PERL 5 in a Week.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Perl CGI What is "CGI"? Common Gateway Interface A means of running an executable program via the Web. Perl have a *very* nice interface to create CGI.
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
Form Data Encoding GET – URL encoded POST – URL encoded
WWW: an Internet application Bill Chu. © Bei-Tseng Chu Aug 2000 WWW Web and HTTP WWW web is an interconnected information servers each server maintains.
Google Application Engine Introduction Jim Eng with thanks to Charles Severance
Sending data, forms and variables Please use speaker notes for additional information!
Why my iPhone sucks: Screen Scraping the O2 Website Simon Lewis -
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
 2001 Prentice Hall, Inc. All rights reserved. Chapter 17 - Web Automation and Networking Outline 17.1Introduction 17.2Introduction to LPW 17.3 LPW Commands.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Three Instructor:
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 1 Intermediate Perl Programming Class Two Instructor:
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring Forms, HTML5 layout.
Introduction to CGI PROG. CGI stands for Common Gateway Interface. CGI is a standard programming interface to Web servers that gives us a way to make.
1 Using Perl Modules. 2 What are Perl modules?  Modules are collections of subroutines  Encapsulate code for a related set of processes  End in.pm.
CSU - DCE Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to Object-Oriented Perl and CGI.pm Instructor:
Sending data with CGI/Perl Please use speaker notes for additional information!
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
1 The Internet Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
CGI I: Basics Web Programming.
Introduction to Programming the WWW I
CGI Programming Part II UNIX Security
Advanced Topics Web Programming.
CGI II: Cookies & Stuff Web Programming.
CGI I: Basics Web Programming.
CGI II: Cookies & Stuff Web Programming.
CGI II: Cookies & Stuff Web Programming.
Presentation transcript:

Perl Modules Darby Tien-Hao Chang Department of Electrical Engineering, National Cheng Kung University

CPAN Comprehensive Perl Archive Network

CGI.pm Simple Common Gateway Interface class You can find some resources from CPAN:  Source  Typical usage  Function-by-function description How do I know the module name “CGI”?

LWP::Simple Simple procedural interface to LWP So, what is LWP?  The World-Wide Web library for Perl get($url)  How do we get a POST web page? head($url) getprint($url) getstore($url, $file) mirror($url, $file) is_success($rc) is_error($rc)

How to POST? #!/usr/bin/perl -w # dependent modules use strict; use LWP::UserAgent; my $url = " = { "pdbcode" => "1bck" }; my $ua = new LWP::UserAgent; my $response = $ua->post( $url, ); if ( $response->is_success ) { print $response->content; # or whatever } else { die $response->status_line; }

Compare to the GET example #!/usr/bin/perl -w # dependent modules use strict; use LWP::Simple; my $url = " my $web = &get( $url ); print "$web“;

What is LWP::UserAgent? It’s a browser! It contain almost everything of your browser… if Perl can mimic LWP Library version number and documentation LWP::MediaTypes MIME types configuration (text/html etc.) LWP::Debug Debug logging module LWP::Simple Simplified procedural interface for common functions HTTP status code (200 OK etc) Date parsing module for HTTP date formats HTTP content negotiation calculation File::Listing Parse directory listings HTML::Form Processing for s in HTML documents

LWP, LWP::Simple and LWP::UserAgent, what a mess! You can include LWP directly  use LWP; There are some clues in the CPAN  /lib/LWP/Simple.pm /lib/LWP/Simple.pm  /lib/LWP.pm /lib/LWP.pm

Multi-steps extraction #!/usr/bin/perl -w use LWP::Simple; my $term = “ 棒球 "; my $url = " my $web = &get( $url ); $web =~ /href=([^>"]+)>$term/ or die; $url = " $web = &get( $url );

A more browser-like Perl module WWW::Mechanize use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get( $url ); $mech->follow_link( n => 3 ); $mech->follow_link( text_regex => qr/download this/i ); $mech->follow_link( url => ' ); $mech->submit_form(  form_number => 3,  fields => { username => 'mungo', password => 'lost-and-alone',  } ); $mech->submit_form(  form_name => 'search',  fields => { query => 'pot of gold',  },  button => 'Search Now‘ );

Consider a CGI program to show some server information #!/usr/bin/perl -w print “Content-type: text/html\n\n”; print “ ”; print “ Test Template ”; print “ ”; print “My Home Directory is $ENV{HOME} ”; print “My Path is set to $ENV{PATH}”; print “ ”;

Now suppose that we have a wizard-like web application Step1.html  Input your first name, last name and Step2.pl  Validate the and one more question Step3.pl  Show the final page

How will you design the three page? They are supposed to be very similar And there could be numerous redundant code

One more Perl module to help CGI.pm HTML::Template  Test Template  My Home Directory is My Path is set to  #!/usr/bin/perl -w use HTML::Template; # open the html template my $template = HTML::Template->new(filename => 'test.html'); # fill in some parameters $template->param(HOME => $ENV{HOME}); $template->param(PATH => $ENV{PATH}); # send the obligatory Content-Type and print the template output print "Content-Type: text/html\n\n", $template->output;

The tags TMPL_VAR  TMPL_LOOP  Name: Job:   $template->param(EMPLOYEE_INFO => [ { name => 'Sam', job => 'programmer' }, { name => 'Steve', job => 'soda jerk' },  ] );  print $template->output(); TMPL_IF, TMPL_ELSE