I'm still relatively new to Perl Programming, but I know how Perl 5 OO basically works. However, I have never created any project with Perl 5 OO, so I'm quite sure I will run into many pitfalls.
Recently I discovered the hype about the Moose module. I checked out some documentation on CPAN and I found it to be quite interesting and helping me as a developer a lot. Additionally, it seems to be very stable and reliable.
Should I rather intensify working with the basic Perl 5 OO syntax until I feel very familiar with it (to know what's going on behind the stages), or do you think I should rather go ahead and directly start developing applications using Moose? Or should I even give Mouse a try?
Any thoughts and experiences on that are appreciated.
Thanks in advance!
Moose is useful, but you may still want to learn about perl OO proper to shield yourself from the leaky abstraction problem.
Perl OO itself is rather hairy, but this book makes it very easy to digest: Intermediate Perl. Highly recommended.
As everyone else has pointed out learning the basics of how OO in Perl is done will help you, not only with most non-moose packages out there but also with Moose itself since deep down Moose basically just uses a standard Perl OO layout. Basically once you're comfortable you understand what Moose::Manual::Unsweetend is showing you'll have a reasonable grasp of the OO principles in Perl. Damian Conway's Object Oriented Perl book is an excellent introduction to Object Orientation period not just Perl's flavor(s). I'd highly suggest reading it, or at least the first half of it.
Finally there is no reason to use Mouse (an alternative to Moose) unless you fall into two very specific categories, you have hard start up time constraints or hard dependency requirements. If you don't fall into those two places Moose will almost always be a better answer.
Disclosure: I'm a core Moose developer, and have worked on and with Mouse.
Honestly, I am not sure how valuable knowledge of Perl's raw OO primitives is for writing new code anymore. I have not used @ISA or "use base" or "bless" in my code for a very long time; any OO I do is via the Moose MOP. (I do rebless instances, of course, but I use $meta->rebless_instance instead of just "bless". Much cleaner!)
Anyway, I would teach yourself Moose first. It is easy to get started and get productive right away, and you can pick up the details as you become more proficient in Perl and programming in general.
As an example:
Notice how there is no more fighting with the details of Perl's implementation. You can easily worry about the details of your program instead of how to do OO in Perl. You don't even have to make a "Point.pm" file, you can have the class definition inline.
I also think this code would be immediately understandable to almost any programmer -- even ones not familiar with the details of Perl or Moose (or MooseX::Declare).
(BTW, this example worked out a bit oddly with the ":" syntax in the method signatures. Normally, you get an instance of yourself called $self as the first arg. If you supply something else before a : in the signature, you can change the type and name of the variable. I also wrote "new_from_ordered_pair" so that you wouldn't have to type
x => $x, y => $y
as the arguments to new every time. This is just sugar that I think is nice; nothing magical is happening here.)Finally, you get a lot here "for free". Try these, and note the helpful error messages:
You get all this for free, and it makes debugging your program easier. There is no reason to avoid it, it really makes programming more enjoyable (and it makes your program more reliable... for free!)
Oh, one more thing. With Moose, you can introspect your classes. This might not be important right away, but it can be nice to have. Open Devel::REPL, type 'do "test.pl"' to load the Point class, and then say something like:
The result is
['x', 'y']
. Without having the source code, you can find out what attributes the class has. Try doing that with "plain" Perl OO. (This sort of thing is what makes the rich MooseX:: namespace possible. You might not need introspection, but you will enjoy the ability to use reliable modules from CPAN.)Lots of useful answers above. The only thing I can add is that the Moose manual is now available to buy as a book or PDF. If you're learning or just using Moose, its a useful reference guide and it's printed in pretty typography.
Disclosure: we created the book (Mr Monkey), though we didn't write it (that was Dave Rolsky and Stevan Little).
Moose is good, but the decision about learning it depends on what your goals are.
If you just want to write your own programs using OO techniques, then it could very well be worth diving into Moose (and worrying about other OO techniques later)
If you want to become "a Perl programmer", then you'll encounter more non-Moose OO code then Moose OO code, so you should learn to deal with coding without Moose first. I suggest Object Oriented Perl by Damian Conway as a good starting point.