## Methods
+sub wrap_method_body {
+ my ( $self, %args ) = @_;
+
+ my $body = delete $args{body}; # delete is for compat
+
+ ('CODE' eq ref($body))
+ || confess "Your code block must be a CODE reference";
+
+ $self->method_metaclass->wrap( $body => (
+ package_name => $self->name,
+ %args,
+ ));
+}
+
sub add_method {
my ($self, $method_name, $method) = @_;
(defined $method_name && $method_name)
}
else {
$body = $method;
- ('CODE' eq ref($body))
- || confess "Your code block must be a CODE reference";
- $method = $self->method_metaclass->wrap(
- $body => (
- package_name => $self->name,
- name => $method_name
- )
- );
+ $method = $self->wrap_method_body( body => $body, name => $method_name );
}
$method->attach_to_class($self);
Returns the class name of the method metaclass, see L<Class::MOP::Method>
for more information on the method metaclasses.
-=item B<add_method ($method_name, $method)>
+=item B<wrap_method_body(%attrs)>
+
+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.
use strict;
use warnings;
-use Test::More tests => 232;
+use Test::More tests => 234;
use Test::Exception;
BEGIN {
superclasses subclasses class_precedence_list linearized_isa
- has_method get_method add_method remove_method alias_method
+ has_method get_method add_method remove_method alias_method wrap_method_body
get_method_list get_method_map get_all_methods compute_all_applicable_methods
find_method_by_name find_all_methods_by_name find_next_method_by_name