};
foreach my $type (qw(before after around)) {
*{_getglob "${target}::${type}"} = sub {
+ require Class::Method::Modifiers;
_install_modifier($target, $type, @_);
};
}
return $new_name;
}
-sub _install_modifiers {
- my ($me, $to, $modifiers) = @_;
- foreach my $modifier (@{$modifiers||[]}) {
- _install_modifier($to, @{$modifier});
- }
+sub _install_single_modifier {
+ my ($me, @args) = @_;
+ _install_modifier(@args);
}
sub _handle_constructor {
sub _install_modifier {
my ($into, $type, $name, $code) = @_;
- my $ref = ref(my $to_modify = $into->can($name));
- require Sub::Defer;
- Sub::Defer::undefer_sub($to_modify);
+ if (my $to_modify = $into->can($name)) { # CMM will throw for us if not
+ require Sub::Defer;
+ Sub::Defer::undefer_sub($to_modify);
+ }
- require Class::Method::Modifiers;
Class::Method::Modifiers::install_modifier(@_);
}
sub _install_modifiers {
my ($me, $to, $modifiers) = @_;
- foreach my $modifier (@{$modifiers||[]}) {
- Class::Method::Modifiers::install_modifier($to, @{$modifier});
+ if (my $info = $INFO{$to}) {
+ push @{$info->{modifiers}}, @{$modifiers||[]};
+ } else {
+ foreach my $modifier (@{$modifiers||[]}) {
+ $me->_install_single_modifier($to, @$modifier);
+ }
}
}
+sub _install_single_modifier {
+ my ($me, @args) = @_;
+ Class::Method::Modifiers::install_modifier(@args);
+}
+
sub does_role {
my ($package, $role) = @_;
return exists $APPLIED_TO{$package}{$role};
[ @MyClass3::ISA ], [ 'MyClass2' ], 'extends sets superclass'
);
+{ package WhatTheFlyingFornication; sub wtff {} }
+
{
package MyClass4;