Ok, this can be done with a default (but it'd be a bit fuglier)
[gitmo/Moose.git] / lib / Moose.pm
index 5c310be..8776106 100644 (file)
@@ -4,20 +4,20 @@ package Moose;
 use strict;
 use warnings;
 
-our $VERSION   = '0.41';
+our $VERSION   = '0.43';
 our $AUTHORITY = 'cpan:STEVAN';
 
 use Scalar::Util 'blessed', 'reftype';
-use Carp         'confess';
+use Carp         'confess', 'croak';
 use Sub::Name    'subname';
 
 use Sub::Exporter;
 
+use MRO::Compat;
 use Class::MOP;
 
 use Moose::Meta::Class;
 use Moose::Meta::TypeConstraint;
-use Moose::Meta::TypeConstraint::Class;
 use Moose::Meta::TypeCoercion;
 use Moose::Meta::Attribute;
 use Moose::Meta::Instance;
@@ -105,7 +105,7 @@ use Moose::Util ();
             my $class = $CALLER;
             return subname 'Moose::has' => sub ($;%) {
                 my $name    = shift;
-                die 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1;
+                croak 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1;
                 my %options = @_;
                 my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ];
                 $class->meta->add_attribute( $_, %options ) for @$attrs;
@@ -136,13 +136,12 @@ use Moose::Util ();
             };
         },
         super => sub {
-            {
-                our %SUPER_SLOT;
-                no strict 'refs';
-                $SUPER_SLOT{$CALLER} = \*{"${CALLER}::super"};
-            }
-            return subname 'Moose::super' => sub { };
+            # FIXME can be made into goto, might break caller() for existing code
+            return subname 'Moose::super' => sub { return unless our $SUPER_BODY; $SUPER_BODY->(our @SUPER_ARGS) }
         },
+        #next => sub {
+        #    return subname 'Moose::next' => sub { @_ = our @SUPER_ARGS; goto \&next::method };
+        #},
         override => sub {
             my $class = $CALLER;
             return subname 'Moose::override' => sub ($&) {
@@ -151,12 +150,19 @@ use Moose::Util ();
             };
         },
         inner => sub {
-            {
-                our %INNER_SLOT;
-                no strict 'refs';
-                $INNER_SLOT{$CALLER} = \*{"${CALLER}::inner"};
-            }
-            return subname 'Moose::inner' => sub { };
+            return subname 'Moose::inner' => sub {
+                my $pkg = caller();
+                our ( %INNER_BODY, %INNER_ARGS );
+
+                if ( my $body = $INNER_BODY{$pkg} ) {
+                    my @args = @{ $INNER_ARGS{$pkg} };
+                    local $INNER_ARGS{$pkg};
+                    local $INNER_BODY{$pkg};
+                    return $body->(@args);
+                } else {
+                    return;
+                }
+            };
         },
         augment => sub {
             my $class = $CALLER;
@@ -700,8 +706,12 @@ Change if the attribute lazily initializes the slot.
 
 =item I<isa>
 
-You I<are> allowed to change the type, B<if and only if> the new type is a
-subtype of the old type.
+You I<are> allowed to change the type without restriction. 
+
+It is recommended that you use this freedom with caution. We used to 
+only allow for extension only if the type was a subtype of the parent's 
+type, but we felt that was too restrictive and is better left as a 
+policy descision. 
 
 =item I<handles>
 
@@ -713,6 +723,17 @@ allowed to I<change> one.
 You are allowed to B<add> a new C<builder> definition, but you are B<not>
 allowed to I<change> one.
 
+=item I<metaclass>
+
+You are allowed to B<add> a new C<metaclass> definition, but you are
+B<not> allowed to I<change> one.
+
+=item I<traits>
+
+You are allowed to B<add> additional traits to the C<traits> definition.
+These traits will be composed into the attribute, but pre-existing traits
+B<are not> overridden, or removed.
+
 =back
 
 =item B<before $name|@names =E<gt> sub { ... }>