use B 'perlstring';
use Sub::Defer ();
-our $VERSION = '0.091011'; # 0.91.11
+our $VERSION = '1.000000'; # 1.0.0
$VERSION = eval $VERSION;
require Moo::sification;
package Cat::Food;
use Moo;
- use Sub::Quote;
sub feed_lion {
my $self = shift;
has pounds => (
is => 'rw',
- isa => quote_sub q{ die "$_[0] is too much cat food!" unless $_[0] < 15 },
+ isa => sub { die "$_[0] is too much cat food!" unless $_[0] < 15 },
);
1;
=head1 DESCRIPTION
-This module is an extremely light-weight, high-performance L<Moose> replacement.
+This module is an extremely light-weight subset of L<Moose> optimised for
+rapid startup and pay for what you use.
+
It also avoids depending on any XS modules to allow simple deployments. The
name C<Moo> is based on the idea that it provides almost -but not quite- two
thirds of L<Moose>.
-Unlike C<Mouse> this module does not aim at full L<Moose> compatibility. See
-L</INCOMPATIBILITIES> for more details.
+Unlike C<Mouse> this module does not aim at full compatibility with
+L<Moose>'s surface syntax, preferring instead of provide full interoperability
+via the metaclass inflation capabilites described in L</MOO AND MOOSE>.
+
+For a full list of the minor differences between L<Moose> and L<Moo>'s surface
+syntax, see L</INCOMPATIBILITIES>.
=head1 WHY MOO EXISTS
If you want a full object system with a rich Metaprotocol, L<Moose> is
already wonderful.
+However, sometimes you're writing a command line script or a CGI script
+where fast startup is essential, or code designed to be deployed as a single
+file via L<App::FatPacker>, or you're writing a CPAN module and you want it
+to be usable by people with those constraints.
+
I've tried several times to use L<Mouse> but it's 3x the size of Moo and
takes longer to load than most of my Moo based CGI scripts take to run.
you want "as little as possible" - which means "no metaprotocol", which is
what Moo provides.
-By Moo 1.0 I intend to have Moo's equivalent of L<Any::Moose> built in -
-if Moose gets loaded, any Moo class or role will act as a Moose equivalent
-if treated as such.
+Better still, if you install and load L<Moose>, we set up metaclasses for your
+L<Moo> classes and L<Moo::Role> roles, so you can use them in L<Moose> code
+without ever noticing that some of your codebase is using L<Moo>.
Hence - Moo exists as its name - Minimal Object Orientation - with a pledge
to make it smooth to upgrade to L<Moose> when you need more than minimal
features.
-=head1 Moo and Moose - NEW, EXPERIMENTAL
+=head1 MOO AND MOOSE
If L<Moo> detects L<Moose> being loaded, it will automatically register
metaclasses for your L<Moo> and L<Moo::Role> packages, so you should be able
-to use them in L<Moose> code without it ever realising you aren't using
+to use them in L<Moose> code without anybody ever noticing you aren't using
L<Moose> everywhere.
-Extending a L<Moose> class or consuming a L<Moose::Role> should also work.
+Extending a L<Moose> class or consuming a L<Moose::Role> will also work.
-So should extending a L<Mouse> class or consuming a L<Mouse::Role>.
+So will extending a L<Mouse> class or consuming a L<Mouse::Role> - but note
+that we don't provide L<Mouse> metaclasses or metaroles so the other way
+around doesn't work. This feature exists for L<Any::Moose> users porting to
+L<Moo>, enabling L<Mouse> users to use L<Moo> classes is not a priority for us.
This means that there is no need for anything like L<Any::Moose> for Moo
code - Moo and Moose code should simply interoperate without problem. To
handle L<Mouse> code, you'll likely need an empty Moo role or class consuming
or extending the L<Mouse> stuff since it doesn't register true L<Moose>
-metaclasses like we do.
+metaclasses like L<Moo> does.
-However, these features are new as of 0.91.0 (0.091000) so while serviceable,
-they are absolutely certain to not be 100% yet; please do report bugs.
+If you want types to be upgraded to the L<Moose> types, use
+L<MooX::Types::MooseLike> and install the L<MooseX::Types> library to
+match the L<MooX::Types::MooseLike> library you're using - L<Moo> will
+load the L<MooseX::Types> library and use that type for the newly created
+metaclass.
If you need to disable the metaclass creation, add:
no Moo::sification;
to your code before Moose is loaded, but bear in mind that this switch is
-currently global and turns the mechanism off entirely, so don't put this
-in library code, only in a top level script as a temporary measure while
-you send a bug report.
+currently global and turns the mechanism off entirely so don't put this
+in library code.
+
+=head1 MOO VERSUS ANY::MOOSE
+
+L<Any::Moose> will load L<Mouse> normally, and L<Moose> in a program using
+L<Moose> - which theoretically allows you to get the startup time of L<Mouse>
+without disadvantaging L<Moose> users.
+
+Sadly, this doesn't entirely work, since the selection is load order dependent
+- L<Moo>'s metaclass inflation system explained above in L</MOO AND MOOSE> is
+significantly more reliable.
+
+So if you want to write a CPAN module that loads fast or has only pure perl
+dependencies but is also fully usable by L<Moose> users, you should be using
+L<Moo>.
+
+For a full explanation, see the article
+L<http://shadow.cat/blog/matt-s-trout/moo-versus-any-moose> which explains
+the differing strategies in more detail and provides a direct example of
+where L<Moo> succeeds and L<Any::Moose> fails.
=head1 IMPORTED METHODS
does not include a basic type system, so instead of doing C<< isa => 'Num' >>,
one should do
- isa => quote_sub q{
+ isa => sub {
die "$_[0] is not a number!" unless looks_like_number $_[0]
},
Takes a coderef which is meant to coerce the attribute. The basic idea is to
do something like the following:
- coerce => quote_sub q{
+ coerce => sub {
$_[0] + 1 unless $_[0] % 2
},
giving us a handy, XS-free speed boost. Any option that is L<Sub::Quote>
aware can take advantage of this.
+To do this, you can write
+
+ use Moo;
+ use Sub::Quote;
+
+ has foo => (
+ is => quote_sub(q{ die "Not <3" unless $_[0] < 3 })
+ );
+
+which will be inlined as
+
+ do {
+ local @_ = ($_[0]->{foo});
+ die "Not <3" unless $_[0] < 3;
+ }
+
+or to avoid localizing @_,
+
+ has foo => (
+ is => quote_sub(q{ my ($val) = @_; die "Not <3" unless $val < 3 })
+ );
+
+which will be inlined as
+
+ do {
+ my ($val) = ($_[0]->{foo});
+ die "Not <3" unless $val < 3;
+ }
+
+See L<Sub::Quote> for more information, including how to pass lexical
+captures that will also be compiled in to the subroutine.
+
=head1 INCOMPATIBILITIES WITH MOOSE
There is no built in type system. C<isa> is verified with a coderef, if you
Mithaldu - Christian Walde (cpan:MITHALDU) <walde.christian@googlemail.com>
+ilmari - Dagfinn Ilmari Mannsåker (cpan:ILMARI) <ilmari@ilmari.org>
+
=head1 COPYRIGHT
Copyright (c) 2010-2011 the Moo L</AUTHOR> and L</CONTRIBUTORS>