Make alias_method simply call add_method.
Dave Rolsky [Thu, 11 Sep 2008 14:52:50 +0000 (14:52 +0000)]
Update docs, tests, and Changes as needed to reflect this.

Changes
lib/Class/MOP/Class.pm
t/003_methods.t
t/073_make_mutable.t

diff --git a/Changes b/Changes
index 35d04aa..bd8ba74 100644 (file)
--- 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
index 9136f86..c8962f2 100644 (file)
@@ -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<method_metaclass>.
 
 =item B<add_method ($method_name, $method, %attrs)>
 
-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<NOTE>:
 This does absolutely nothing special to C<$method>
@@ -1472,16 +1467,6 @@ other than use B<Sub::Name> to make sure it is tagged with the
 correct name, and therefore show up correctly in stack traces and
 such.
 
-=item B<alias_method ($method_name, $method)>
-
-This will take a C<$method_name> and CODE reference to that
-C<$method> and alias the method into the class's package.
-
-B<NOTE>:
-Unlike C<add_method>, this will B<not> try to name the
-C<$method> using B<Sub::Name>, it only aliases the method in
-the class's package.
-
 =item B<has_method ($method_name)>
 
 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<SUPER::$method_name>, but it can be dispatched at runtime.
 
+=item B<alias_method ($method_name, $method)>
+
+B<NOTE>: This method is now deprecated. Just use C<add_method>
+instead.
+
 =back
 
 =head2 Method Modifiers
index 6b39b0a..204f882 100644 (file)
@@ -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'),
index 8880f27..0fec326 100644 (file)
@@ -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');