bump version to 0.86
[gitmo/Class-MOP.git] / lib / Class / MOP / Attribute.pm
index aaf2e1e..8c04348 100644 (file)
@@ -9,7 +9,7 @@ use Class::MOP::Method::Accessor;
 use Carp         'confess';
 use Scalar::Util 'blessed', 'weaken';
 
-our $VERSION   = '0.78';
+our $VERSION   = '0.86';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -77,6 +77,10 @@ sub _new {
         # and a list of the methods
         # associated with this attr
         'associated_methods' => [],
+        # this let's us keep track of
+        # our order inside the associated
+        # class
+        'insertion_order'    => undef,
     }, $class;
 }
 
@@ -163,6 +167,7 @@ sub has_builder     { defined($_[0]->{'builder'}) }
 sub has_init_arg    { defined($_[0]->{'init_arg'}) }
 sub has_default     { defined($_[0]->{'default'}) }
 sub has_initializer { defined($_[0]->{'initializer'}) }
+sub has_insertion_order { defined($_[0]->{'insertion_order'}) }
 
 sub accessor           { $_[0]->{'accessor'}    }
 sub reader             { $_[0]->{'reader'}      }
@@ -173,6 +178,8 @@ sub builder            { $_[0]->{'builder'}     }
 sub init_arg           { $_[0]->{'init_arg'}    }
 sub initializer        { $_[0]->{'initializer'} }
 sub definition_context { $_[0]->{'definition_context'} }
+sub insertion_order    { $_[0]->{'insertion_order'} }
+sub _set_insertion_order { $_[0]->{'insertion_order'} = $_[1] }
 
 # end bootstrapped away method section.
 # (all methods below here are kept intact)
@@ -241,7 +248,9 @@ sub get_write_method_ref {
 }
 
 sub is_default_a_coderef {
-    ('CODE' eq ref($_[0]->{'default'}))
+    my ($value) = $_[0]->{'default'};
+    return unless ref($value);
+    return ref($value) eq 'CODE' || (blessed($value) && $value->isa('Class::MOP::Method'));
 }
 
 sub default {
@@ -329,6 +338,12 @@ sub clear_value {
 sub accessor_metaclass { 'Class::MOP::Method::Accessor' }
 
 sub process_accessors {
+    Carp::cluck('The process_accessors method has been made private.'
+        . " The public version is deprecated and will be removed in a future release.\n");
+    shift->_process_accessors(@_);
+}
+
+sub _process_accessors {
     my ($self, $type, $accessor, $generate_as_inline_methods) = @_;
 
     my $method_ctx;
@@ -384,23 +399,23 @@ sub install_accessors {
     my $class  = $self->associated_class;
 
     $class->add_method(
-        $self->process_accessors('accessor' => $self->accessor(), $inline)
+        $self->_process_accessors('accessor' => $self->accessor(), $inline)
     ) if $self->has_accessor();
 
     $class->add_method(
-        $self->process_accessors('reader' => $self->reader(), $inline)
+        $self->_process_accessors('reader' => $self->reader(), $inline)
     ) if $self->has_reader();
 
     $class->add_method(
-        $self->process_accessors('writer' => $self->writer(), $inline)
+        $self->_process_accessors('writer' => $self->writer(), $inline)
     ) if $self->has_writer();
 
     $class->add_method(
-        $self->process_accessors('predicate' => $self->predicate(), $inline)
+        $self->_process_accessors('predicate' => $self->predicate(), $inline)
     ) if $self->has_predicate();
 
     $class->add_method(
-        $self->process_accessors('clearer' => $self->clearer(), $inline)
+        $self->_process_accessors('clearer' => $self->clearer(), $inline)
     ) if $self->has_clearer();
 
     return;
@@ -489,25 +504,25 @@ C<%options> are added as key-value pairs.
 
 =over 8
 
-=item I<init_arg>
+=item * init_arg
 
 This is a string value representing the expected key in an
 initialization hash. For instance, if we have an C<init_arg> value of
 C<-foo>, then the following code will Just Work.
 
-  MyClass->meta->construct_instance( -foo => 'Hello There' );
+  MyClass->meta->new_object( -foo => 'Hello There' );
 
 If an init_arg is not assigned, it will automatically use the
 attribute's name. If C<init_arg> is explicitly set to C<undef>, the
 attribute cannot be specified during initialization.
 
-=item I<builder>
+=item * builder
 
 This provides the name of a method that will be called to initialize
 the attribute. This method will be called on the object after it is
 constructed. It is expected to return a valid value for the attribute.
 
-=item I<default>
+=item * default
 
 This can be used to provide an explicit default for initializing the
 attribute. If the default you provide is a subroutine reference, then
@@ -557,7 +572,7 @@ Note that there is no guarantee that attributes are initialized in any
 particular order, so you cannot rely on the value of some other
 attribute when generating the default.
 
-=item I<initializer>
+=item * initializer
 
 This option can be either a method name or a subroutine
 reference. This method will be called when setting the attribute's
@@ -607,9 +622,9 @@ containing exactly one key (the method name) and one value. The value
 should be a subroutine reference, which will be installed as the
 method itself.
 
-=over 4
+=over 8
 
-=item I<accessor>
+=item * accessor
 
 An C<accessor> is a standard Perl-style read/write accessor. It will
 return the value of the attribute, and if a value is passed as an
@@ -619,12 +634,12 @@ Note that C<undef> is a legitimate value, so this will work:
 
   $object->set_something(undef);
 
-=item I<reader>
+=item * reader
 
 This is a basic read-only accessor. It returns the value of the
 attribute.
 
-=item I<writer>
+=item * writer
 
 This is a basic write accessor, it accepts a single argument, and
 assigns that value to the attribute.
@@ -633,7 +648,7 @@ Note that C<undef> is a legitimate value, so this will work:
 
   $object->set_something(undef);
 
-=item I<predicate>
+=item * predicate
 
 The predicate method returns a boolean indicating whether or not the
 attribute has been explicitly set.
@@ -641,12 +656,12 @@ attribute has been explicitly set.
 Note that the predicate returns true even if the attribute was set to
 a false value (C<0> or C<undef>).
 
-=item I<clearer>
+=item * clearer
 
 This method will uninitialize the attribute. After an attribute is
 cleared, its C<predicate> will return false.
 
-=item I<definition_context>
+=item * definition_context
 
 Mostly, this exists as a hook for the benefit of Moose.
 
@@ -678,6 +693,8 @@ the constructor.
 
 =item B<< $attr->name >>
 
+Returns the attribute's name.
+
 =item B<< $attr->accessor >>
 
 =item B<< $attr->reader >>
@@ -690,11 +707,11 @@ the constructor.
 
 The C<accessor>, C<reader>, C<writer>, C<predicate>, and C<clearer>
 methods all return exactly what was passed to the constructor, so it
-can be either a string containing a method name, or a hash refrence.
+can be either a string containing a method name, or a hash reference.
 
 =item B<< $attr->initializer >>
 
-Returns the intializer as passed to the constructor, so this may be
+Returns the initializer as passed to the constructor, so this may be
 either a method name or a subroutine reference.
 
 =item B<< $attr->init_arg >>
@@ -745,6 +762,11 @@ writing the attribute's value in the associated class. These methods
 always return a subroutine reference, regardless of whether or not the
 attribute is read- or write-only.
 
+=item B<< $attr->insertion_order >>
+
+If this attribute has been inserted into a class, this returns a zero
+based index regarding the order of insertion.
+
 =back
 
 =head2 Informational predicates
@@ -776,11 +798,15 @@ C<undef> is the default C<default> anyway.
 
 =item B<< $attr->has_builder >>
 
+=item B<< $attr->has_insertion_order >>
+
+This will be I<false> if this attribute has not be inserted into a class
+
 =back
 
 =head2 Value management
 
-These methods are basically "backdoors" to the instance, and can be
+These methods are basically "back doors" to the instance, and can be
 used to bypass the regular accessors, but still stay within the MOP.
 
 These methods are not for general use, and should only be used if you
@@ -893,22 +919,6 @@ This method generates and installs code the attributes various
 accessors. It is typically called from the L<Class::MOP::Class>
 C<add_attribute> method.
 
-This method will call C<< $attr->process_accessors >> for each of the
-possible method types (accessor, reader, writer & predicate).
-
-=item B<< $attr->process_accessors($type, $value) >>
-
-This method takes a C<$type> (accessor, reader, writer or predicate), and
-a C<$value> (the value passed into the constructor for each of the
-different types).
-
-It will then either generate the method itself (using the
-C<generate_*_method> methods listed below) or it will use the custom
-method passed through the constructor.
-
-This method is mostly intended for internal use from the C<<
-$attr->install_accessors >> method.
-
 =item B<< $attr->remove_accessors >>
 
 This method removes all of the accessors associated with the
@@ -923,7 +933,7 @@ C<associated_methods>.
 
 =over 4
 
-=item B<< $attr->meta >>
+=item B<< Class::MOP::Attribute->meta >>
 
 This will return a L<Class::MOP::Class> instance for this class.