[펌]Perl OOP
ITWeb/개발일반 2009. 1. 15. 19:27급해서.. 스크랩 부터.. ^^;
원본문서 : http://www.bjnet.edu.cn/tech/book/perl/ch19.htm
Chapter 19
Object-Oriented Programming in Perl
by Kamran Husain
- An Introduction to Modules
- Classes in Perl
- Creating a Class
- Blessing a Constructor
- Methods
- Exporting Methods
- Invoking Methods
- Overrides
- Destructors
- Inheritance
- Overriding Methods
- A Few Comments About Classes and Objects in Perl
- Summary
- Q&A
- Workshop
Listing 19.1. The initial Cocoa.pm package. package Cocoa;
sub new { my $this = {}; # Create an anonymous hash, and #self points to it. bless $this; # Connect the hash to the package Cocoa. return $this; # Return the reference to the hash. } 1;
Listing 19.2. Creating the constructor.
1 #!/usr/bin/perl 2 push (@INC,'pwd'); 3 use Cocoa; 4 $cup = new Cocoa; sub new { my $class = shift; # Get the request class name my $this = {}; bless $this, $class # Use class name to bless() reference $this->doInitialization(); return $this; }
더 자세한 건 사이트 들어가서 보삼.. ㅎㅎ
perl 로 class 만드는 것 중 기본은.. package 를 만드는 것이고 pacakge 의 끝은 1; 로 끝나야 한다는거.. ㅎㅎ