Lots of tests fail. Not sure if this is worth doing.
}
sub before {
- Moose::Util::add_method_modifier(shift, 'before', \@_);
+ shift->add_method_modifier('before', \@_);
}
sub after {
- Moose::Util::add_method_modifier(shift, 'after', \@_);
+ shift->add_method_modifier('after', \@_);
}
sub around {
- Moose::Util::add_method_modifier(shift, 'around', \@_);
+ shift->add_method_modifier('around', \@_);
}
our $SUPER_PACKAGE;
use Moose::Meta::Method::Constructor;
use Moose::Meta::Method::Destructor;
-use base 'Class::MOP::Class';
+use base 'Class::MOP::Class', 'Moose::Meta::Mixin::HasMethods';
__PACKAGE__->meta->add_attribute('roles' => (
reader => 'roles',
--- /dev/null
+package Moose::Meta::Mixin::HasMethods;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.99';
+our $AUTHORITY = 'cpan:STEVAN';
+
+use base 'Class::MOP::Mixin::HasMethods';
+
+sub add_method_modifier {
+ my ( $self, $modifier_name, $args ) = @_;
+
+ my $code = pop @{$args};
+ my $add_modifier_method = 'add_' . $modifier_name . '_method_modifier';
+
+ if ( my $method_modifier_type = ref( @{$args}[0] ) ) {
+ if ( $method_modifier_type eq 'Regexp' ) {
+ my @all_methods = $self->get_all_methods;
+ my @matched_methods
+ = grep { $_->name =~ @{$args}[0] } @all_methods;
+ $self->$add_modifier_method( $_->name, $code )
+ for @matched_methods;
+ }
+ elsif ( $method_modifier_type eq 'ARRAY' ) {
+ $self->$add_modifier_method( $_, $code ) for @{ $args->[0] };
+ }
+ else {
+ $self->throw_error(
+ sprintf(
+ "Methods passed to %s must be provided as a list, arrayref or regex, not %s",
+ $modifier_name,
+ $method_modifier_type,
+ )
+ );
+ }
+ }
+ else {
+ $self->$add_modifier_method( $_, $code ) for @{$args};
+ }
+}
+
+1;
use Moose::Meta::Role::Method::Conflicting;
use Moose::Util qw( ensure_all_roles );
-use base 'Class::MOP::Module', 'Class::MOP::Mixin::HasAttributes';
+use base 'Class::MOP::Module', 'Class::MOP::Mixin::HasAttributes', 'Moose::Meta::Mixin::HasMethods';
## ------------------------------------------------------------------
## NOTE:
. ref($_)
. " references for $type method modifiers"
if ref $_;
- my $add_method = "add_${type}_method_modifier";
- $meta->$add_method( $_, $code );
+ $meta->add_method_modifier( $type, $_, $code );
}
}
get_all_attribute_values
resolve_metatrait_alias
resolve_metaclass_alias
- add_method_modifier
english_list
meta_attribute_alias
meta_class_alias
}
}
-sub add_method_modifier {
- my ( $class_or_obj, $modifier_name, $args ) = @_;
- my $meta
- = $class_or_obj->can('add_before_method_modifier')
- ? $class_or_obj
- : find_meta($class_or_obj);
- my $code = pop @{$args};
- my $add_modifier_method = 'add_' . $modifier_name . '_method_modifier';
- if ( my $method_modifier_type = ref( @{$args}[0] ) ) {
- if ( $method_modifier_type eq 'Regexp' ) {
- my @all_methods = $meta->get_all_methods;
- my @matched_methods
- = grep { $_->name =~ @{$args}[0] } @all_methods;
- $meta->$add_modifier_method( $_->name, $code )
- for @matched_methods;
- }
- elsif ($method_modifier_type eq 'ARRAY') {
- $meta->$add_modifier_method( $_, $code ) for @{$args->[0]};
- }
- else {
- $meta->throw_error(
- sprintf(
- "Methods passed to %s must be provided as a list, arrayref or regex, not %s",
- $modifier_name,
- $method_modifier_type,
- )
- );
- }
- }
- else {
- $meta->$add_modifier_method( $_, $code ) for @{$args};
- }
-}
-
sub english_list {
my @items = sort @_;