builder => sub{} now installs that as a method
[gitmo/Moo.git] / lib / Moo.pm
index c3788d9..acf7c65 100644 (file)
@@ -5,7 +5,7 @@ use Moo::_Utils;
 use B 'perlstring';
 use Sub::Defer ();
 
-our $VERSION = '1.000003'; # 1.0.3
+our $VERSION = '1.000007'; # 1.0.7
 $VERSION = eval $VERSION;
 
 require Moo::sification;
@@ -22,8 +22,11 @@ sub import {
   my $target = caller;
   my $class = shift;
   strictures->import;
+  if ($Moo::Role::INFO{$target} and $Moo::Role::INFO{$target}{is_role}) {
+    die "Cannot import Moo into a role";
+  }
   return if $MAKERS{$target}; # already exported into this package
-  $MAKERS{$target} = {};
+  $MAKERS{$target} = { is_class => 1 };
   _install_tracked $target => extends => sub {
     $class->_set_superclasses($target, @_);
     $class->_maybe_reset_handlemoose($target);
@@ -75,11 +78,11 @@ sub unimport {
 sub _set_superclasses {
   my $class = shift;
   my $target = shift;
-  for (@_) {
-    _load_module($_);
-    if ($INC{"Role/Tiny.pm"} && $Role::Tiny::INFO{$_}) {
+  foreach my $superclass (@_) {
+    _load_module($superclass);
+    if ($INC{"Role/Tiny.pm"} && $Role::Tiny::INFO{$superclass}) {
       require Carp;
-      Carp::croak("Can't extend role '$_'");
+      Carp::croak("Can't extend role '$superclass'");
     }
   }
   # Can't do *{...} = \@_ or 5.10.0's mro.pm stops seeing @ISA
@@ -92,7 +95,7 @@ sub _set_superclasses {
   no warnings 'once'; # piss off. -- mst
   $Moo::HandleMoose::MOUSE{$target} = [
     grep defined, map Mouse::Util::find_meta($_), @_
-  ] if $INC{"Mouse.pm"};
+  ] if Mouse::Util->can('find_meta');
 }
 
 sub _maybe_reset_handlemoose {
@@ -240,10 +243,10 @@ thirds of L<Moose>.
 
 Unlike L<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>.
+via the metaclass inflation capabilities 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>.
+syntax, see L</INCOMPATIBILITIES WITH MOOSE>.
 
 =head1 WHY MOO EXISTS
 
@@ -553,8 +556,14 @@ Moo will call
 
   $self->$builder;
 
-If you set this to just C<1>, the predicate is automatically named
-C<_build_${attr_name}>.  This feature comes from L<MooseX::AttributeShortcuts>.
+The following features come from L<MooseX::AttributeShortcuts>:
+
+If you set this to just C<1>, the builder is automatically named
+C<_build_${attr_name}>.
+
+If you set this to a coderef or code-convertible object, that variable will be
+installed under C<$class::_build_${attr_name}> and the builder set to the same
+name.
 
 =item * C<clearer>
 
@@ -762,6 +771,9 @@ at the end of your class to get an inlined (i.e. not horribly slow)
 constructor. Moo does it automatically the first time ->new is called
 on your class.
 
+An extension L<MooX::late> exists to ease translating Moose packages
+to Moo by providing a more Moose-like interface.
+
 =head1 SUPPORT
 
 Users' IRC: #moose on irc.perl.org