make extends after has work
[gitmo/Moo.git] / lib / Moo.pm
index 1ccc972..1f6300d 100644 (file)
@@ -4,20 +4,10 @@ use strictures 1;
 use Moo::_Utils;
 use B 'perlstring';
 
-our $VERSION = '0.009014'; # 0.9.13
+our $VERSION = '0.009_017'; # 0.9.17
 $VERSION = eval $VERSION;
 
-sub Moo::HandleMoose::AuthorityHack::DESTROY {
-  require Moo::HandleMoose;
-  Moo::HandleMoose->import;
-}
-
-if ($INC{"Moose.pm"}) {
-  require Moo::HandleMoose;
-  Moo::HandleMoose->import;
-} else {
-  $Moose::AUTHORITY = bless({}, 'Moo::HandleMoose::AuthorityHack');
-}
+require Moo::sification;
 
 our %MAKERS;
 
@@ -26,17 +16,22 @@ sub import {
   my $class = shift;
   strictures->import;
   return if $MAKERS{$target}; # already exported into this package
-  *{_getglob("${target}::extends")} = sub {
+  _install_coderef "${target}::extends" => sub {
     _load_module($_) for @_;
     # Can't do *{...} = \@_ or 5.10.0's mro.pm stops seeing @ISA
     @{*{_getglob("${target}::ISA")}{ARRAY}} = @_;
+    if (my $old = delete $Moo::MAKERS{$target}{constructor}) {
+      delete _getstash($target)->{new};
+      Moo->_constructor_maker_for($target)
+         ->register_attribute_specs(%{$old->all_attribute_specs});
+    }
   };
-  *{_getglob("${target}::with")} = sub {
+  _install_coderef "${target}::with" => sub {
     require Moo::Role;
     Moo::Role->apply_roles_to_package($target, $_[0]);
   };
   $MAKERS{$target} = {};
-  *{_getglob("${target}::has")} = sub {
+  _install_coderef "${target}::has" => sub {
     my ($name, %spec) = @_;
     ($MAKERS{$target}{accessor} ||= do {
       require Method::Generate::Accessor;
@@ -46,7 +41,7 @@ sub import {
           ->register_attribute_specs($name, \%spec);
   };
   foreach my $type (qw(before after around)) {
-    *{_getglob "${target}::${type}"} = sub {
+    _install_coderef "${target}::${type}" => sub {
       require Class::Method::Modifiers;
       _install_modifier($target, $type, @_);
     };
@@ -101,8 +96,11 @@ sub _constructor_maker_for {
             ? ($con ? $con->construction_string : undef)
             : ('$class->'.$target.'::SUPER::new(@_)')
         ),
-        subconstructor_generator => (
-          $class.'->_constructor_maker_for($class,'.perlstring($target).')'
+        subconstructor_handler => (
+          '      if ($Moo::MAKERS{$class}) {'."\n"
+          .'        '.$class.'->_constructor_maker_for($class,'.perlstring($target).');'."\n"
+          .'        return $class->new(@_)'.";\n"
+          .'      }'."\n"
         ),
       )
       ->install_delayed
@@ -335,8 +333,9 @@ Takes a hashref
 
 =item * trigger
 
-Takes a coderef which will get called any time the attribute is set. Coderef
-will be invoked against the object with the new value as an argument.
+Takes a coderef which will get called any time the attribute is set. This
+includes the constructor. Coderef will be invoked against the object with the
+new value as an argument.
 
 Note that Moose also passes the old value, if any; this feature is not yet
 supported.
@@ -468,7 +467,8 @@ API will encourage the use of other type systems as well, since it's
 probably the weakest part of Moose design-wise.
 
 C<initializer> is not supported in core since the author considers it to be a
-bad idea but may be supported by an extension in future.
+bad idea but may be supported by an extension in future. Meanwhile C<trigger> or
+C<coerce> are more likely to be able to fulfill your needs.
 
 There is no meta object.  If you need this level of complexity you wanted
 L<Moose> - Moo succeeds at being small because it explicitly does not