Fayland 林 > Book-Chinese-MasterPerlToday-0.02 > Book::Chinese::MasterPerlToday::Moose

Download:
Book-Chinese-MasterPerlToday-0.02.tar.gz

Annotate this POD

View/Report Bugs
Source  

NAME ^

Book::Chinese::MasterPerlToday::Moose - Moose, OO

DESCRIPTION ^

Perl 的面对对象系统很强大(Moose 是由 Perl 编写),但并不是很好使用。建议使用 Moose

学习 Moose 最好的方法是阅读 Moose::Manual

对象系统

如果没有 Moose,Perl5 的 OO 应该是比较繁琐的。

  package Person;

  use strict;
  use warnings;

  sub new {
      my $class = shift;
      my %p = ref $_[0] ? %{ $_[0] } : @_;
      
      return bless \%p, $class;
  }

基本上你在写一些无用的东西,没有任何一行代码是跟实际应用的代码有关的。bless 是什么?这样的代码让人很迷惑。

Moose 的意义在于它可以让你专注于写什么(what),而不是怎么写(how)。

  package Person;
  
  use Moose;

概念

细节例子

MooseX

Moose 所开发的软件

但你在写一个小脚本的时候,你可能不会觉得 Moose 怎么有用。但当你写一个很大的系统的时候,你会由衷地为自己选择 Moose 而感到幸运。

资源

SEE ALSO ^

Moose, Moose::Manual

AUTHOR ^

Fayland Lam, <fayland at gmail.com>

COPYRIGHT & LICENSE ^

Copyright (c) 2009 Fayland Lam

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

syntax highlighting: