From: Dave Rolsky Date: Mon, 16 Mar 2009 16:13:43 +0000 (-0500) Subject: Add warnings when calling CMOP::Class->{compute_all_applicable_method,alias_method}. X-Git-Tag: 0.80_01~49 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=070cb0d65405aca6c6b275cb05d06cabd4bc0c81;p=gitmo%2FClass-MOP.git Add warnings when calling CMOP::Class->{compute_all_applicable_method,alias_method}. These were both deprecated a while back, but didn't warn when called. --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 883d5fb..7be3421 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -705,9 +705,9 @@ sub add_method { } sub alias_method { - my $self = shift; + warn "The alias_method method is deprecated. Use add_method instead.\n"; - $self->add_method(@_); + goto &add_method; } sub has_method { @@ -768,8 +768,10 @@ sub get_all_methods { return values %methods; } -# compatibility sub compute_all_applicable_methods { + warn 'The compute_all_applicable_methods method is deprecated.' + . " Use get_all_methods instead.\n"; + return map { { name => $_->name, diff --git a/t/003_methods.t b/t/003_methods.t index 5088f50..e518c36 100644 --- a/t/003_methods.t +++ b/t/003_methods.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 67; +use Test::More tests => 65; use Test::Exception; use Scalar::Util qw/reftype/; @@ -137,17 +137,6 @@ for my $method_name (qw/ } } -{ - package Foo::Aliasing; - use metaclass; - sub alias_me { '...' } -} - -$Foo->alias_method('alias_me' => Foo::Aliasing->meta->get_method('alias_me')); - -ok($Foo->has_method('alias_me'), '... Foo->has_method(alias_me) (aliased from Foo::Aliasing)'); -ok(defined &Foo::alias_me, '... Foo does have a symbol table slow for alias_me though'); - ok(!$Foo->has_method('blessed'), '... !Foo->has_method(blessed) (imported into Foo)'); ok(!$Foo->has_method('boom'), '... !Foo->has_method(boom) (defined in main:: using symbol tables and Sub::Name w/out package name)'); @@ -156,7 +145,7 @@ is($Foo->get_method('not_a_real_method'), undef, '... Foo->get_method(not_a_real is_deeply( [ sort $Foo->get_method_list ], - [ qw(FOO_CONSTANT alias_me baaz bang bar baz blah cake evaled_foo floob foo pie) ], + [ qw(FOO_CONSTANT baaz bang bar baz blah cake evaled_foo floob foo pie) ], '... got the right method list for Foo'); is_deeply( @@ -164,7 +153,6 @@ is_deeply( [ map { $Foo->get_method($_) } qw( FOO_CONSTANT - alias_me baaz bang bar @@ -186,7 +174,7 @@ dies_ok { Foo->foo } '... cannot call Foo->foo because it is not there'; is_deeply( [ sort $Foo->get_method_list ], - [ qw(FOO_CONSTANT alias_me baaz bang bar baz blah cake evaled_foo floob pie) ], + [ qw(FOO_CONSTANT baaz bang bar baz blah cake evaled_foo floob pie) ], '... got the right method list for Foo'); @@ -224,7 +212,6 @@ is_deeply( [ sort { $a->name cmp $b->name } $Bar->get_all_methods() ], [ $Foo->get_method('FOO_CONSTANT'), - $Foo->get_method('alias_me'), $Foo->get_method('baaz'), $Foo->get_method('bang'), $Bar->get_method('bar'), diff --git a/t/004_advanced_methods.t b/t/004_advanced_methods.t index 792b353..f598382 100644 --- a/t/004_advanced_methods.t +++ b/t/004_advanced_methods.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 12; +use Test::More tests => 11; use Test::Exception; use Class::MOP; @@ -106,38 +106,6 @@ is_deeply( ], '... got the right list of applicable methods for Foo::Bar'); -# test compute_all_applicable_methods once for compat -is_deeply( - [ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Foo::Bar::Baz')->compute_all_applicable_methods() ], - [ - { - name => 'BUILD', - class => 'Foo::Bar::Baz', - code => Class::MOP::Class->initialize('Foo::Bar::Baz')->get_method('BUILD') - }, - { - name => 'bar', - class => 'Foo::Bar::Baz', - code => Class::MOP::Class->initialize('Foo::Bar::Baz')->get_method('bar') - }, - { - name => 'baz', - class => 'Baz', - code => Class::MOP::Class->initialize('Baz')->get_method('baz') - }, - { - name => 'foo', - class => 'Foo', - code => Class::MOP::Class->initialize('Foo')->get_method('foo') - }, - { - name => 'foobarbaz', - class => 'Foo::Bar::Baz', - code => Class::MOP::Class->initialize('Foo::Bar::Baz')->get_method('foobarbaz') - }, - ], - '... got the right list of applicable methods for Foo::Bar::Baz'); - ## find_all_methods_by_name is_deeply( diff --git a/t/016_class_errors_and_edge_cases.t b/t/016_class_errors_and_edge_cases.t index 7c3b684..df5fe2a 100644 --- a/t/016_class_errors_and_edge_cases.t +++ b/t/016_class_errors_and_edge_cases.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 47; +use Test::More tests => 43; use Test::Exception; use Class::MOP; @@ -80,24 +80,6 @@ use Class::MOP; { dies_ok { - Class::MOP::Class->alias_method(); - } '... alias_method dies as expected'; - - dies_ok { - Class::MOP::Class->alias_method(''); - } '... alias_method dies as expected'; - - dies_ok { - Class::MOP::Class->alias_method('foo' => 'foo'); - } '... alias_method dies as expected'; - - dies_ok { - Class::MOP::Class->alias_method('foo' => []); - } '... alias_method dies as expected'; -} - -{ - dies_ok { Class::MOP::Class->has_method(); } '... has_method dies as expected'; diff --git a/t/050_scala_style_mixin_composition.t b/t/050_scala_style_mixin_composition.t index 7dcc949..2078494 100644 --- a/t/050_scala_style_mixin_composition.t +++ b/t/050_scala_style_mixin_composition.t @@ -101,7 +101,7 @@ sub ::with ($) { # add all the methods in .... foreach my $method_name (keys %methods) { - $metaclass->alias_method($method_name => $methods{$method_name}) + $metaclass->add_method($method_name => $methods{$method_name}) unless $metaclass->has_method($method_name); } } diff --git a/t/073_make_mutable.t b/t/073_make_mutable.t index dca59cd..81143c9 100644 --- a/t/073_make_mutable.t +++ b/t/073_make_mutable.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 114; +use Test::More tests => 101; use Test::Exception; use Scalar::Util; @@ -69,13 +69,6 @@ use Class::MOP; ok( $meta->add_method('xyz', sub{'xxx'}), '... added method'); is( Baz->xyz, 'xxx', '... method xyz works'); - ok(! $meta->has_method('zxy') ,'... we dont have the aliased method yet'); - ok( $meta->alias_method('zxy',sub{'xxx'}),'... aliased method'); - ok( $meta->has_method('zxy') ,'... the aliased method does register'); - is( Baz->zxy, 'xxx', '... method zxy works'); - ok( $meta->remove_method('xyz'), '... removed method'); - ok( $meta->remove_method('zxy'), '... removed aliased method'); - ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute'); ok(Baz->can('fickle'), '... Baz can fickle'); ok($meta->remove_attribute('fickle'), '... removed attribute'); @@ -108,8 +101,6 @@ use Class::MOP; lives_ok { $meta->make_immutable() } '... changed Baz to be immutable'; dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected'; - dies_ok{ $meta->alias_method('zxy',sub{'xxx'}) } '... exception thrown as expected'; - dies_ok{ $meta->remove_method('zxy') } '... exception thrown as expected'; dies_ok { $meta->add_attribute('fickle', accessor => 'fickle') @@ -133,8 +124,8 @@ use Class::MOP; ok(Baz->meta->is_immutable, 'Superclass is immutable'); my $meta = Baz->meta->create_anon_class(superclasses => ['Baz']); my @orig_keys = sort grep { !/^_/ } keys %$meta; - my @orig_meths = sort { $a->{name} cmp $b->{name} } - $meta->compute_all_applicable_methods; + my @orig_meths = sort { $a->name cmp $b->name } + $meta->get_all_methods; ok($meta->is_anon_class, 'We have an anon metaclass'); ok($meta->is_mutable, '... our anon class is mutable'); ok(!$meta->is_immutable, '... our anon class is not immutable'); @@ -157,8 +148,8 @@ use Class::MOP; my $instance = $meta->new_object; my @new_keys = sort grep { !/^_/ } keys %$meta; - my @new_meths = sort { $a->{name} cmp $b->{name} } - $meta->compute_all_applicable_methods; + my @new_meths = sort { $a->name cmp $b->name } + $meta->get_all_methods; is_deeply(\@orig_keys, \@new_keys, '... no straneous hashkeys'); is_deeply(\@orig_meths, \@new_meths, '... no straneous methods'); @@ -166,10 +157,7 @@ use Class::MOP; ok( $meta->add_method('xyz', sub{'xxx'}), '... added method'); is( $instance->xyz , 'xxx', '... method xyz works'); - ok( $meta->alias_method('zxy',sub{'xxx'}),'... aliased method'); - is( $instance->zxy, 'xxx', '... method zxy works'); ok( $meta->remove_method('xyz'), '... removed method'); - ok( $meta->remove_method('zxy'), '... removed aliased method'); ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute'); ok($instance->can('fickle'), '... instance can fickle'); @@ -207,8 +195,6 @@ use Class::MOP; lives_ok {$meta->make_immutable } '... changed class to be immutable'; dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected'; - dies_ok{ $meta->alias_method('zxy',sub{'xxx'}) } '... exception thrown as expected'; - dies_ok{ $meta->remove_method('zxy') } '... exception thrown as expected'; dies_ok { $meta->add_attribute('fickle', accessor => 'fickle')