From: Dave Rolsky Date: Thu, 11 Sep 2008 14:52:50 +0000 (+0000) Subject: Make alias_method simply call add_method. X-Git-Tag: 0.66~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3a09d885f32b98f31f7df982fe0da98ff3bc4acf;p=gitmo%2FClass-MOP.git Make alias_method simply call add_method. Update docs, tests, and Changes as needed to reflect this. --- diff --git a/Changes b/Changes index 35d04aa..bd8ba74 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,11 @@ Revision history for Perl extension Class-MOP. XS, which should help us catch skew between the XS/pure Perl code (Dave Rolsky) + * Class::MOP::Class + - The alias_method method has been deprecated. It now simply + calls add_method instead. This means there is no distinction + between aliased methods and "real" methods. (Dave Rolsky) + 0.65 Mon September 1, 2008 For those not following the series of dev releases, the changes from 0.64 from 0.65 can mostly be summed up as a lot performance diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 9136f86..c8962f2 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -710,19 +710,9 @@ sub add_method { } sub alias_method { - my ($self, $method_name, $method) = @_; - (defined $method_name && $method_name) - || confess "You must define a method name"; - - my $body = (blessed($method) ? $method->body : $method); - ('CODE' eq ref($body)) - || confess "Your code block must be a CODE reference"; - - $self->add_package_symbol( - { sigil => '&', type => 'CODE', name => $method_name } => $body - ); + my $self = shift; - $self->update_package_cache_flag; # the method map will not list aliased methods + $self->add_method(@_); } sub has_method { @@ -1463,8 +1453,13 @@ Wrap a code ref (C<$attrs{body>) with C. =item B -This will take a C<$method_name> and CODE reference to that -C<$method> and install it into the class's package. +This will take a C<$method_name> and CODE reference or meta method +objectand install it into the class's package. + +You are strongly encouraged to pass a meta method object instead of a +code reference. If you do so, that object gets stored as part of the +class's method map, providing more useful information about the method +for introspection. B: This does absolutely nothing special to C<$method> @@ -1472,16 +1467,6 @@ other than use B to make sure it is tagged with the correct name, and therefore show up correctly in stack traces and such. -=item B - -This will take a C<$method_name> and CODE reference to that -C<$method> and alias the method into the class's package. - -B: -Unlike C, this will B try to name the -C<$method> using B, it only aliases the method in -the class's package. - =item B This just provides a simple way to check if the class implements @@ -1569,6 +1554,11 @@ This will return the first method to match a given C<$method_name> in the superclasses, this is basically equivalent to calling C, but it can be dispatched at runtime. +=item B + +B: This method is now deprecated. Just use C +instead. + =back =head2 Method Modifiers diff --git a/t/003_methods.t b/t/003_methods.t index 6b39b0a..204f882 100644 --- a/t/003_methods.t +++ b/t/003_methods.t @@ -155,7 +155,7 @@ for my $method_name (qw/ $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($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)'); @@ -166,7 +166,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 baaz bang bar baz blah evaled_foo floob foo) ], + [ qw(FOO_CONSTANT alias_me baaz bang bar baz blah evaled_foo floob foo) ], '... got the right method list for Foo'); is_deeply( @@ -174,6 +174,7 @@ is_deeply( [ map { $Foo->get_method($_) } qw( FOO_CONSTANT + alias_me baaz bang bar @@ -192,7 +193,7 @@ dies_ok { Foo->foo } '... cannot call Foo->foo because it is not there'; is_deeply( [ sort $Foo->get_method_list ], - [ qw(FOO_CONSTANT baaz bang bar baz blah evaled_foo floob) ], + [ qw(FOO_CONSTANT alias_me baaz bang bar baz blah evaled_foo floob) ], '... got the right method list for Foo'); @@ -230,6 +231,7 @@ 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/073_make_mutable.t b/t/073_make_mutable.t index 8880f27..0fec326 100644 --- a/t/073_make_mutable.t +++ b/t/073_make_mutable.t @@ -71,10 +71,10 @@ BEGIN { 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 not register (correctly)'); + 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->remove_method('zxy'), '... removed aliased method'); ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute'); ok(Baz->can('fickle'), '... Baz can fickle'); @@ -169,7 +169,7 @@ BEGIN { 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->remove_method('zxy'), '... removed aliased method'); ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute'); ok($instance->can('fickle'), '... instance can fickle');