Download presentation
Presentation is loading. Please wait.
Published byHilda Wheeler Modified over 8 years ago
1
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to Object-Oriented Perl and CGI.pm Instructor: Dr. Joseph DiVerdi
2
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC 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
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC 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
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC 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
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC 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
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC 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
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC 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
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC 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
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC 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
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC 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” Simple web page This is a web page. Use web browser to access URL “http://www.verinet.com/~web0/
11
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC 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
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC Simple CGI (continued) #!/usr/bin/perl -w print <<__HTML__ Content-type: text/html Simple web page This is a web page. __HTML__
13
CSU - DCE 0791 - Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC Simple CGI (continued) Use web browser to access URL “http://www.verinet.com/cgi-bin/cgiwrap/web0/first.pl
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.