Telephone +44(0)1524 64544
Email: info@shadowcat.co.uk

mstpan 12 - Object Orientation

Tue Dec 16 21:15:00 2014

mstpan 12 - Object Orientation

$ perl -Moo
 ______
< Moo! >
 ------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Moose

The one, the only, the original, the awesome. I tend to refer to the various Moose clones as the M* ecosystem, though this being perl I should probably call it the M.* ecosystem.

The manual is probably the best learning resource for M* systems in general, and if you need to do metaprotocol stuff you basically need Moose.

There is a significant startup overhead to using Moose because of building out the metaclasses, but once all your classes have got as far as make_immutable runtime's basically as fast as anything else.

Conceptualising roles as "an interface with an optional (partial) default implementation" may help your brain.

Moo

Written to be a pure perl (with optional XS for speed) implementation of a reasonable subset of the non-meta functionality of Moose. Basically exists because I wanted to be able to write fatpackable command line scripts and still get the shiny.

Somewhere along the line, it seems to've also become "Moose for CPAN" because it has sufficiently fewer dependencies that if you don't need the full Moose feature set it's easier to use Moo than to argue with people about it.

If you need to be able to do metamodel reflection, or you need an extension that's only available for Moose, use Moose. If you need fatpackability or fast startup, use Moo. If neither of those applies to you, flip a coin.

Mouse

Originally written as a learning project by somebody who wanted to understand Moose core better, spent a while being the closest to Moose-in-pure-perl that exists, and is now largely still used by things that want its ridiculously optimised XS constructor/accessor implementation more than they want compatibility with the rest of the ecosystem, or need a mostly-Moose-like meta API without the overhead of Moose.

It's amazing code, mind.

Just don't touch Any::Moose, which has been deprecated in favour of Moo for very good reasons. If you're going to use Mouse, use Mouse.

Type::Tiny

This (and Types::Standard and Type::Library and etc.) effectively replace the Moose core type system, the MooseX::Types type library system, and MooX::Types::MooseLike.

It has the types-as-exports nature of the type library system so your typos can be caught at compile time, but manages to avoid most of the pitfalls of the way MooseX::Types works because it isn't bolted on top of the string-based Moose type system. This makes life easier.

If you're going to use types in M* code, just use Type::Tiny. Please.

Moops

If you want a more declarative interface to building classes, roles, and type libraries, make sure you have a 5.14+ perl and use Moops. MooseX::Declare has the unfortunate problem of being built on top of Devel::Declare, which is basically a giant bag of crack written by an idiot who knew just enough C to be dangerous.

Moops, OTOH, uses the perl core keyword API that was built by competent people, supports Moo, Moose and Mouse, integrates Type::Tiny and a rather nice method signature system called Kavorka. It claims to be unstable but I think that's more because the author's worried about not being able to fix design mistakes than because it's actually likely to be unsstable.

Throwable

Throwable is basically the sensible standard for building exception classes. It was originally written in Moose, was ported to Moo so it's compatible with both Moo and Moose, and has been widely used to good effect.

If you want a pre-built superclass, Throwable::Error is your friend.

Safe::Isa

I got incredibly bored of having to test blessed+isa or use a type system just to see if I got handed an object of a particular class. This was the result. You may or may not find it useful.

-- mst, out.