}
sub alias_method {
- my $self = shift;
+ 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
+ );
- $self->add_method(@_);
+ $self->update_package_cache_flag; # the method map will not list aliased methods
}
sub has_method {
=item B<add_method ($method_name, $method, %attrs)>
-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.
+This will take a C<$method_name> and CODE reference to that
+C<$method> and install it into the class's package.
B<NOTE>:
This does absolutely nothing special to C<$method>
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
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