Quote from amazing ModernPerl book http://modernperlbooks.com/

"Perl's default object system is minimal but flexible. Its syntax is a little clunky, and it exposes /how/ an object system works. You can build great things on top of it, but it doesn't give you what many other languages do by default.

/Moose/ is a complete object system for Perl. It's a complete distribution available from the CPAN—not a part of the core language, but worth installing and using regardless. Moose offers both a simpler way to use an object system as well as advanced features of languages such as Smalltalk and Common Lisp."


If you find Moose to heavy for start, you can use Moo + Types::Standard libraries. It combination provides almost same syntaxis, but has much less dependecies and a bit easy to install.


25.04.17 5:57, Chas. Owens пишет:
The main benefits I see are

1. You have to write less code
2. Roles provide the benefits of multiple inheritance without the insanity
3. Introspection of Moose classes is easier
4. Type safety (which is really just points 1 and 3 again)

The biggest one is 1. Moose is basically a declarative language for creating classes. It creates a lot of the code for you based on what you say you want. Sure you could write that code, but it is all boilerplate stuff and I would rather spend my time working logic than boilerplate. It also provides nice abstract concepts like before, after, and around methods. Sure, you could just use $self-SUPER::method(@_) at the right, but the new keywords provide a more self documenting way of expressing the relationship.

Sure, Moose can't do anything that Perl 5's OO can't do because Moose it's written using Perl 5's OO, but, in the end, Moose is already written and provides a lot of shortcuts (once you learn how to use it)


On Mon, Apr 24, 2017, 20:40 Peng Yonghua <p...@vodafonemail.de <mailto:p...@vodafonemail.de>> wrote:

    Hi,

    I saw many modules begin to write with Moose.

    For me I wrote my perl modules most time with OO style, I think perl's
    native OO works just fine.

    So why needs moose? thanks.

    --
    To unsubscribe, e-mail: beginners-unsubscr...@perl.org
    <mailto:beginners-unsubscr...@perl.org>
    For additional commands, e-mail: beginners-h...@perl.org
    <mailto:beginners-h...@perl.org>
    http://learn.perl.org/



Reply via email to