'perl class'에 해당되는 글 1건

  1. 2009.01.15 [펌]Perl OOP

[펌]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


CONTENTS
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; 로 끝나야 한다는거.. ㅎㅎ

: