X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FAttribute.pm;h=22f87465abd4267823414f57e23dffcbccfd9781;hb=d499b013d778b1880738b23c77ccdfed44b8c568;hp=515aa5ba38b3e652fa9bbda0d1701ae6bed0b5a8;hpb=1550e0820d345fd483382e2b912ba683da3bdc1d;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index 515aa5b..22f8746 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -9,7 +9,7 @@ use Class::MOP::Method::Accessor; use Carp 'confess'; use Scalar::Util 'blessed', 'weaken'; -our $VERSION = '0.78_02'; +our $VERSION = '0.92_01'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -32,7 +32,7 @@ sub new { my $name = $options{name}; - (defined $name && $name) + (defined $name) || confess "You must provide a name for the attribute"; $options{init_arg} = $name @@ -57,6 +57,10 @@ sub new { sub _new { my $class = shift; + + return Class::MOP::Class->initialize($class)->new_object(@_) + if $class ne __PACKAGE__; + my $options = @_ == 1 ? $_[0] : {@_}; bless { @@ -77,6 +81,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 +171,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 +182,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 +252,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 { @@ -328,12 +341,6 @@ sub clear_value { sub accessor_metaclass { 'Class::MOP::Method::Accessor' } -sub process_accessors { - warn 'The process_accessors method has been made private.' - . " The public version is deprecated and will be removed in a future release.\n"; - goto &_process_accessors; -} - sub _process_accessors { my ($self, $type, $accessor, $generate_as_inline_methods) = @_; @@ -501,7 +508,7 @@ This is a string value representing the expected key in an initialization hash. For instance, if we have an C 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 is explicitly set to C, the @@ -753,6 +760,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 @@ -784,6 +796,10 @@ C is the default C anyway. =item B<< $attr->has_builder >> +=item B<< $attr->has_insertion_order >> + +This will be I if this attribute has not be inserted into a class + =back =head2 Value management