Perl class builders

I was more than pelasantly surprised today while benchmarking Moo against Mo, Class::Tiny and Mojo::Base. It turns out the latest version of Moo doesn’t have much of a speed penality when compared to Mo or Mojo::Base. Needless to say it’s two times faster than Class::Tiny. All of this without Class::XSAccessor installed. With it installed it’s on par with Mo, sometimes even faster. If I’d start a new project today I’d probably use either Moo or Mojo::Base.

Rate ct moo mo mb
ct 76799/s -45% -50% -61%
moo 139184/s 81% -10% -29%
mo 154844/s 102% 11% -21%
mb 195491/s 155% 40% 26%

Moo only has features that make sense, such as inheritance, roles plus some safeguards that make sloppy programming a headacke. Some of them are rather annoying, for example fatal warnings, which can be defused by using Moo::Lax. If you want type checking with Moo, there are some documented extensions for that, or you can use Type::Tiny. Moo also provides an easy migration path to Moose and in order to use it you only need to install just about eight non-core dependencies, as opposed to half the CPAN.

Mojo::Base is really minimal, has zero core dependencies and is part of the excellent Mojolicious framework. If you’re already using that you probably don’t need another object builder. The syntax is also Moose-like.

Tags: , ,

One Response to “Perl class builders”

  1. Cris Says:

    Too many weird names in these frameworks…

Leave a Reply