Mo - Micro Objects. Mo is less.
package Less; use Mo; extends 'Nothing'; has 'something' => ( is => 'rw', default => sub { my $self = shift; $self->build_something; }, ); sub BUILD { my $self = shift; $self->SUPER::BUILD(); # ... }
use Mo. Mo is less. Much less.
Moose led to Mouse led to Moo led to Mo. M is nothing. Mo is more. Not much.
When Moo is more than you need, drop an 'o' and get some Mo.
This is what you get. Nothing Mo.
new
Mo provides a new object constructor. It will call the BUILD method after creation if it can.
BUILD
can
NOTE: Unlike other Moose modules, BUILD is not called in a chained fashion. You would need to call SUPER::BUILD yourself, if you needed that.
SUPER::BUILD
extends
Mo exports the extends keyword, to name your parent class. Mo itself is your default parent class, of course.
Mo
has
Mo exports a has keyword, to generate accessors.
These accessors support get and set operations and allows a default. That's it.
get
set
default
has 'name'; has 'name' => ( default => sub { 'Joe' } );
has takes arguments after the name. Here is what it currently supports:
Must be a code reference. The object instance is passed in, and it should return the default value for this attribute. default is always called lazily. ie It is called when you try to get the value and it does not(exists()).
Must be a method name. This method should return the default value for this attribute. builder is always called lazily.
builder
Any other arguments are ignored. This lets you switch from Moo to Mo and back, without having to change all your accessors.
strict
warnings
Mo turns on use strict and use warnings for you.
use strict
use warnings
Mo is tiny. It is currently 10 lines, <= 80 chars.
You could easily inline it in your code, if you wanted to.
Ingy döt Net <ingy@cpan.org>
Damien 'dams' Krotkine <dams@cpan.org>
Copyright (c) 2011. Ingy döt Net.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Mo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mo
CPAN shell
perl -MCPAN -e shell install Mo
For more information on module installation, please visit the detailed CPAN module installation guide.