1 / 13

Introduction to Object-Oriented Perl and CGI.pm

Introduction to Object-Oriented Perl and CGI.pm. Instructor: Dr. Joseph DiVerdi. Object-Oriented Perl. Not a class in Object-Oriented Programming Emphasis is on use of Object-Oriented Perl Modules rather than on the creation of them

Download Presentation

Introduction to Object-Oriented Perl and CGI.pm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Object-Oriented Perl and CGI.pm Instructor: Dr. Joseph DiVerdi

  2. Object-Oriented Perl • Not a class in Object-Oriented Programming • Emphasis is on use of Object-Oriented Perl Modules rather than on the creation of them • Perhaps the most important component of Object-Oriented Programming • Encapsulation - the hiding of actual data structures, exposing instead a limited, well-documented interface: a set of actions which can manipulate these data structures

  3. Some Definitions • object:: a data structure with a collection of behaviors that can be performed on it • method: a behavior performed on an object • class: a definition of methods • inherit: receive definitions

  4. Some Definitions (con’t) • attribute: a property of an object • Identity: each object, although a member of a class and possessing similar attributes, is unique and unto itself • constructor: a behavior which sets up an object and initializes its data structures • destructor: a behavior which performs clean up on an object before the object is destroyed

  5. An Example • My Miata is an object • It is a member of the class - Car • It has attributes - red, convertible • It is capable of behaviors - steering, forward motion, backward motion

  6. Another Example • A particular rectangle is a member of a class rectangle, it has attributes such as lower-left and upper-right corners, and a color, it is capable of certain behaviors like calculating its area

  7. References • Objects are generally (but not exclusively) identified by references • References are easy to sling around - independent of the size of the referred structure • Typical syntax: • “class method” my $object = Class_name->new_method(); my $object = Class_name->new_method(arg1); • “object method” $return_value = $object->method_name(); $return_value = $object->method_name(arg1, arg2);

  8. Using Net::FTP.pm • Bad module! • Cannot run under “-w” • Can run under “use strict” #!/usr/bin/perl use strict; use Net::FTP; my $port = Net::FTP->new("ftp.verinet.com"); die "'new' failed because $@\n" unless $port; $port->login('anonymous', ‘your_address@your_domain.top_domain’) or die "Can't login.\n";

  9. Using Net::FTP.pm (con’t) print "\nCurrent working directory is '", $port->pwd(), "'.\n"; print join("\n", $port->dir()), "\n"; $port->cwd('pub') or die "Can't change working directory.\n"; print "\nCurrent working directory is '", $port->pwd(), "'.\n"; print join("\n", $port->dir()), "\n"; $port->cwd('linux/www/browsers/netscape/4.04/base_install') or die "Can't change working directory.\n"; print "\nCurrent working directory is '", $port->pwd(), "'.\n"; print join("\n", $port->dir()), "\n"; $port->get('README.txt') or die "Can't get a file.\n"; $port->quit() or die "Can't quit.\n"; exit;

  10. Simple HTML • Create a directory named “html” in top level directory, e.g., “/users/web0/html” and change mode to “755” • In “html” create a file named “index.html” and change mode to “644” <html> <head> <title>Simple web page</title> </head> <body> This is a web page. </body> </html> • Use web browser to access URL “http://www.verinet.com/~web0/

  11. Simple CGI • Create a directory named “cgi-bin” in top level directory, e.g., “/users/web0/cgi-bin” and change mode to “755” • In “cgi-bin” create a file named “first.pl” and change mode to “755”

  12. Simple CGI (continued) #!/usr/bin/perl -w print <<__HTML__ Content-type: text/html <html> <head> <title>Simple web page</title> </head> <body> This is a web page. </body> </html> __HTML__

  13. Simple CGI (continued) • Use web browser to access URL “http://www.verinet.com/cgi-bin/cgiwrap/web0/first.pl

More Related