What, besides declarative syntax and auto-generated accessors--which are both available at far less cost from other modules--does Moose buy the application programmer, that makes it worth the not inconsiderable costs?
Moose is much more than "declarative syntax and auto-generated accessors" it also provides:
- A base class (Moose::Object) that provides a sensible default constructor and controlled object initialization (through BUILD/BUILDALL) and just as controlled destruction (through DEMOLISH/DEMOLISHALL). This may not seem like much, but is eliminates a whole lot of boilerplate.
- A formal system for managing object attributes/properties/slots that allows the programmer to not have to worry about any details such as inheritance, etc. (basically this means you don't have to remember to call SUPER::new in your constructor and/or worry about initialization order).
- A complete role system, which provides very useful ways in which you can re-use code that would otherwise not be as easily re-used. (Really once you get hang of roles, you will love them).
- A powerful AOP-ish set of method modifiers (before/after/around).
- A powerful and extensible type-constraint system.
- A set of very useful extensions in the MooseX:: namespace.
- A complete meta-programming environment, which means that everything above is introspectable, manipulatable and extensible.
- ... and lastly, all the above components are built on a single platform and is guaranteed to always work well together (this fact should not be underestimated).
Basically, everything any other modern object oriented language would give you (and then some).
For (my) best interest, I'm not looking for a straight list of features--which I have found around.
Okay, the "list of features" not what you want, here is a "list of benefits" for Moose.
- Less testing - Why test what Moose already tests? Because Moose writes a lot of code for you and we very thoroughly test that code writing, there is no need to test simple things like accessors and such.
- Less boilerplate - You can get up and running with a simple package Foo; use Moose; and Foo is now a full fledged class instead of just a plain perl package. One more line package Foo; use Moose; has baz => (is => 'ro', isa => 'Int'); and you can have access controlled attributes which have type checking and a constructor that accepts named parameters.
- Less Tedium - Moose takes care of a whole lot of very repetitive and tedious tasks for you (managing inheritance, generating accessors, etc). By taking care of the boring bits for you, Moose eliminates a whole class of typo errors and other hard-to-track-down problems.
- More Consistency - Moose respects the Perl motto of TIMTOWTDI, but does it's best to inject a level of consistency to the otherwise chaotic world of Perl OOP. The results of this is that it becomes easier to do basic OO things like inheritance because you can be sure of how the extended class will behave. Of course in isolation this is not that interesting, but when you realize this doesn't just apply within your project, but applies to anything else written in Moose. Which means that you no longer need to wonder if CPAN modules will be amenable to subclassing, if they are written in Moose, it should Just Work.
- More Readability - This is not always true at first, but once you get familiar with the Moose way of doing things, it is very easy to pick up any Moose code and understand it in a relatively short period of time. No longer do you need to figure out how they have implemented their OO or what kind of accessors they are using, etc etc etc.
- More Maintainability - With Moose you write less code, so therefore you have less to maintain. This leads back again to the point about consistency, because consistent code is easier to maintain, especially when you program in the large.
I'm more looking for examples of how people have used those features, to implement something that they would have had to implement anyway, had they used some other OO framework.
Here are 382 examples :)
Honestly, I think perhaps the best way to answer this question is to try out Moose for yourself. You have been dancing around Moose for years now and (as best I know) have not just sat down and tried to solve a problem with it. There is no better way to know if Moose is useful for you then to just give it a try.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.