From: Dave Rolsky Date: Sun, 5 Apr 2009 16:17:12 +0000 (-0500) Subject: deprecate compute_all_applicable_attributes X-Git-Tag: 0.80_01~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FClass-MOP.git;a=commitdiff_plain;h=2620be7754ea58a069e7d33228e6ded9cba2c8fa deprecate compute_all_applicable_attributes --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 7ea9965..11f51db 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -352,7 +352,7 @@ sub _construct_instance { my $params = @_ == 1 ? $_[0] : {@_}; my $meta_instance = $class->get_meta_instance(); my $instance = $meta_instance->create_instance(); - foreach my $attr ($class->compute_all_applicable_attributes()) { + foreach my $attr ($class->get_all_attributes()) { $attr->initialize_instance_slot($meta_instance, $instance, $params); } # NOTE: @@ -387,7 +387,7 @@ sub _create_meta_instance { my $instance = $self->instance_metaclass->new( associated_metaclass => $self, - attributes => [ $self->compute_all_applicable_attributes() ], + attributes => [ $self->get_all_attributes() ], ); $self->add_meta_instance_dependencies() @@ -422,7 +422,7 @@ sub _clone_instance { || confess "You can only clone instances, ($instance) is not a blessed instance"; my $meta_instance = $class->get_meta_instance(); my $clone = $meta_instance->clone_instance($instance); - foreach my $attr ($class->compute_all_applicable_attributes()) { + foreach my $attr ($class->get_all_attributes()) { if ( defined( my $init_arg = $attr->init_arg ) ) { if (exists $params{$init_arg}) { $attr->set_value($clone, $params{$init_arg}); @@ -456,7 +456,7 @@ sub rebless_instance { # we use $_[1] here because of t/306_rebless_overload.t regressions on 5.8.8 $meta_instance->rebless_instance_structure($_[1], $self); - foreach my $attr ( $self->compute_all_applicable_attributes ) { + foreach my $attr ( $self->get_all_attributes ) { if ( $attr->has_value($instance) ) { if ( defined( my $init_arg = $attr->init_arg ) ) { $params{$init_arg} = $attr->get_value($instance) @@ -468,7 +468,7 @@ sub rebless_instance { } } - foreach my $attr ($self->compute_all_applicable_attributes) { + foreach my $attr ($self->get_all_attributes) { $attr->initialize_instance_slot($meta_instance, $instance, \%params); } @@ -882,7 +882,7 @@ sub add_meta_instance_dependencies { $self->remove_meta_instance_dependencies; - my @attrs = $self->compute_all_applicable_attributes(); + my @attrs = $self->get_all_attributes(); my %seen; my @classes = grep { not $seen{$_->name}++ } map { $_->associated_class } @attrs; @@ -967,15 +967,18 @@ sub get_attribute_list { } sub get_all_attributes { - shift->compute_all_applicable_attributes(@_); -} - -sub compute_all_applicable_attributes { my $self = shift; my %attrs = map { %{ $self->initialize($_)->get_attribute_map } } reverse $self->linearized_isa; return values %attrs; } +sub compute_all_applicable_attributes { + warn 'The construct_class_instance method has been deprecated.' + . " Use get_all_attributes instead.\n"; + + shift->get_all_attributes; +} + sub find_attribute_by_name { my ($self, $attr_name) = @_; foreach my $class ($self->linearized_isa) { @@ -1503,8 +1506,6 @@ defined in this class. This will traverse the inheritance hierarchy and return a list of all the L objects for this class and its parents. -This method can also be called as C. - =item B<< $metaclass->find_attribute_by_name($attribute_name) >> This will return a L for the specified diff --git a/lib/Class/MOP/Method/Constructor.pm b/lib/Class/MOP/Method/Constructor.pm index 7f0fe51..8de6706 100644 --- a/lib/Class/MOP/Method/Constructor.pm +++ b/lib/Class/MOP/Method/Constructor.pm @@ -74,10 +74,10 @@ sub _meta_instance { sub attributes { warn 'The attributes method is deprecated.' - . " Use ->associated_metaclass->compute_all_applicable_attributes instead.\n"; + . " Use ->associated_metaclass->get_all_attributes instead.\n"; my $self = shift; - $self->{'attributes'} ||= [ $self->associated_metaclass->compute_all_applicable_attributes ] + $self->{'attributes'} ||= [ $self->associated_metaclass->get_all_attributes ] } ## method @@ -129,7 +129,7 @@ sub _generate_constructor_method_inline { $source .= "\n" . 'my $instance = ' . $self->_meta_instance->inline_create_instance('$class'); $source .= ";\n" . (join ";\n" => map { $self->_generate_slot_initializer($_, $close_over) - } $self->associated_metaclass->compute_all_applicable_attributes); + } $self->associated_metaclass->get_all_attributes); $source .= ";\n" . 'return $instance'; $source .= ";\n" . '}'; warn $source if $self->options->{debug}; diff --git a/t/005_attributes.t b/t/005_attributes.t index dad4d54..1429a0a 100644 --- a/t/005_attributes.t +++ b/t/005_attributes.t @@ -113,7 +113,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); is($meta->find_attribute_by_name('$foo'), $FOO_ATTR, '... got the right attribute for "foo"'); is_deeply( - [ sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ $BAR_ATTR, $BAZ_ATTR, @@ -122,7 +122,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); '... got the right list of applicable attributes for Baz'); is_deeply( - [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ Bar->meta, Baz->meta, Foo->meta ], '... got the right list of associated classes from the applicable attributes for Baz'); @@ -139,7 +139,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); ok(!$meta->has_method('set_baz'), '... a writer has been removed'); is_deeply( - [ sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ $BAR_ATTR, $FOO_ATTR, @@ -147,7 +147,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); '... got the right list of applicable attributes for Baz'); is_deeply( - [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ Bar->meta, Foo->meta ], '... got the right list of associated classes from the applicable attributes for Baz'); @@ -164,7 +164,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); } is_deeply( - [ sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ $BAR_ATTR_2, $FOO_ATTR, @@ -172,7 +172,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); '... got the right list of applicable attributes for Baz'); is_deeply( - [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ Foo->meta, Foo->meta ], '... got the right list of associated classes from the applicable attributes for Baz'); diff --git a/t/070_immutable_metaclass.t b/t/070_immutable_metaclass.t index 4ec34fc..2741363 100644 --- a/t/070_immutable_metaclass.t +++ b/t/070_immutable_metaclass.t @@ -135,7 +135,7 @@ use Class::MOP; my @attributes; lives_ok { - @attributes = $meta->compute_all_applicable_attributes; + @attributes = $meta->get_all_attributes; } '... got the attribute list okay'; is_deeply( @@ -207,7 +207,7 @@ use Class::MOP; my @attributes; lives_ok { - @attributes = $meta->compute_all_applicable_attributes; + @attributes = $meta->get_all_attributes; } '... got the attribute list okay'; is_deeply( @@ -279,7 +279,7 @@ use Class::MOP; my @attributes; lives_ok { - @attributes = $meta->compute_all_applicable_attributes; + @attributes = $meta->get_all_attributes; } '... got the attribute list okay'; is_deeply( diff --git a/t/lib/MyMetaClass.pm b/t/lib/MyMetaClass.pm index 0c060cd..b70fe14 100644 --- a/t/lib/MyMetaClass.pm +++ b/t/lib/MyMetaClass.pm @@ -9,7 +9,7 @@ use base 'Class::MOP::Class'; sub mymetaclass_attributes{ my $self = shift; return grep { $_->isa("MyMetaClass::Attribute") } - $self->compute_all_applicable_attributes; + $self->get_all_attributes; } 1; diff --git a/xt/pod_coverage.t b/xt/pod_coverage.t index 38aadce..2918767 100644 --- a/xt/pod_coverage.t +++ b/xt/pod_coverage.t @@ -18,6 +18,7 @@ my %trustme = ( 'Class::MOP::Class' => [ # deprecated 'alias_method', + 'compute_all_applicable_attributes', 'compute_all_applicable_methods', # unfinished feature @@ -41,9 +42,6 @@ my %trustme = ( 'update_package_cache_flag', 'wrap_method_body', - # doc'd under get_all_attributes - 'compute_all_applicable_attributes', - ], 'Class::MOP::Instance' => [