Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

第 7 章 Perl OOP

目錄

7.1. Moose - A postmodern object system for Perl 5

Person.pm

		
package Person;s
use strict;

sub new {
	my $self = {};
	$self->{NAME} = undef;
	$self->{AGE} 	= undef;
	$self->{PEERS}= [];
	bless($self);
	return $self;
}

sub name {
	my $self = shift;
	if(@_) {$self->{NAME}=shift}
	return $self->{NAME};
}

sub age {
	my $self = shift;
	if(@_) {$self->{AGE} = shift}
	return $self->{AGE};
}

sub peers {
	my $self = shift;
	if(@_) { @{$self->{PEER}} = @_}
	return @{$self->{PEERS}};
}


1;
		
	
		
use Person;

$person = Person->new();
$person->name('name');

print  $person->{NAME}		
		
	

7.1. Moose - A postmodern object system for Perl 5

MooseX::Declare - Declarative syntax for Moose