sub before {
my $meta = Mouse::Meta::Class->initialize(scalar caller);
-
my $code = pop;
-
- for (@_) {
- $meta->add_before_method_modifier($_ => $code);
+ for my $name($meta->_collect_methods(@_)) {
+ $meta->add_before_method_modifier($name => $code);
}
return;
}
sub after {
my $meta = Mouse::Meta::Class->initialize(scalar caller);
-
my $code = pop;
-
- for (@_) {
- $meta->add_after_method_modifier($_ => $code);
+ for my $name($meta->_collect_methods(@_)) {
+ $meta->add_after_method_modifier($name => $code);
}
return;
}
sub around {
my $meta = Mouse::Meta::Class->initialize(scalar caller);
-
my $code = pop;
-
- for (@_) {
- $meta->add_around_method_modifier($_ => $code);
+ for my $name($meta->_collect_methods(@_)) {
+ $meta->add_around_method_modifier($name => $code);
}
return;
}
return grep { $self->has_method($_) } keys %{ $self->namespace };
}
+sub _collect_methods { # Mouse specific
+ my($meta, @args) = @_;
+
+ my @methods;
+ foreach my $arg(@args){
+ if(my $type = ref $arg){
+ if($type eq 'Regexp'){
+ push @methods, grep { $_ =~ $arg } $meta->get_all_method_names;
+ }
+ elsif($type eq 'ARRAY'){
+ push @methods, @{$arg};
+ }
+ else{
+ my $subname = ( caller(1) )[3];
+ $meta->throw_error(
+ sprintf(
+ 'Methods passed to %s must be provided as a list, ArrayRef or regular expression, not %s',
+ $subname,
+ $type,
+ )
+ );
+ }
+ }
+ else{
+ push @methods, $arg;
+ }
+ }
+ return @methods;
+}
+
+
{
my $ANON_SERIAL = 0;
sub before {
my $meta = Mouse::Meta::Role->initialize(scalar caller);
-
my $code = pop;
- for (@_) {
- $meta->add_before_method_modifier($_ => $code);
+ for my $name($meta->_collect_methods(@_)) {
+ $meta->add_before_method_modifier($name => $code);
}
return;
}
sub after {
my $meta = Mouse::Meta::Role->initialize(scalar caller);
-
my $code = pop;
- for (@_) {
- $meta->add_after_method_modifier($_ => $code);
+ for my $name($meta->_collect_methods(@_)) {
+ $meta->add_after_method_modifier($name => $code);
}
return;
}
sub around {
my $meta = Mouse::Meta::Role->initialize(scalar caller);
-
my $code = pop;
- for (@_) {
- $meta->add_around_method_modifier($_ => $code);
+ for my $name($meta->_collect_methods(@_)) {
+ $meta->add_around_method_modifier($name => $code);
}
return;
}