Object-Oriented Programming In Perl
Length: 3 days
Prerequisites: Students should have taken Intermediate
Topics in Perl or should be familiar with Perl modules,
namespaces, and references.
Description
This introduction to scalable programming covers in Perl all basic
principles of OOP including discussing classes, objects, methods,
single and multiple inheritance, and Perl syntax for these. The class
also includes sections on object-oriented design and more specialized
topics such as autoloading and conditional loading of modules.
Outline
- 0: Review of references and coumpound data structures (if necessary)
- Why References?
- Reference Syntax
- Make Rules 1 and 2; use rules 1 and 2
- Two-Dimensional Arrays; arrow rule
- City-Country Problem
- Hash of arrays
- Printing out a Reference
- Symbolic References
- strict refs
- Finding the Type of a Reference
- Copying vs. Aliasing
- Code References
- Schwartzian Transform
- I: Basic Object-Oriented Programming
- Why OOP?
- Methods
- Classes
- Typical OO Program
- Inside the Person Class
- Constructors
- Object methods
- Accessor methods
- croak
- Class vs. Object Methods
- "Indirect Object" Style
- Dynamic method calls
- Change of implementation; broken encapsulation boundaries
- Review of OO Concepts
- Lab 1
- II: Inheritance
- Summary of OOP
- Inheritance; jargon
- Setting up Inheritance in Perl; @ISA
- Multiple Inheritance
- Constructors revisited
- The empty subclass test
- Overridden methods; partial inheritance
- Delegation
- Refactoring
- Abstract Classes: HTML::Parser example
- Lab 2
- III: Advanced Topics A
- IIIa: Named Parameters
- Hashes as Lists; reverse Trick
- Named Parameter Style
- IIIb: Autoloading
- What is Autoloading?
- Simple AUTOLOAD Example
- Magic goto
- Case-Insensitive Function Calls
- Typical AUTOLOAD Use: Accessor Methods
- Direct Emulation of Accessors
- Globs
- Caching Accessor Methods
- Autoloading From a File
- IIIc: Conditional Module Loading
- Conditional Module Loading
- use vs. require
- BEGIN blocks
- IV: Advanced Topics B
- IVa: Destruction and Garbage Collection
- Memory management in Perl
- Reference counts; reference loops
- When Reference Counting Doesn't Work
- DESTROY; chained DESTROY
- END blocks
- UNIVERSAL methods
- IVb: Polymorphism
- IVc: Encapsulation strategies
- V: Error Handling
- The Perl Builtin Debugger
- $!
- Exceptions; catching exceptions
- Conditional module loading again
- Object exceptions
- CPAN exception modules
- strict; strict vars; strict subs; bareword maintenance problem
- Warnings; perldiag; problems with warnings
- confess; caller
- Common Subtle Errors: $_; my-if; @array[$n]
Return to:
Universe of Discourse main page |
Perl Paraphernalia |
Other Classes and Talks
mjd-perl-yak+@plover.com