use Sub::Exporter;
use Carp 'confess';
use Scalar::Util 'blessed';
-use Class::Method::Modifiers ();
use Mouse::Meta::Attribute;
use Mouse::Meta::Class;
},
before => sub {
- return \&Class::Method::Modifiers::before;
+ my $caller = $CALLER;
+
+ return sub {
+ my $code = pop;
+ my $class = $caller->meta;
+
+ for (@_) {
+ $class->add_before_method_modifier($_ => $code);
+ }
+ };
},
after => sub {
- return \&Class::Method::Modifiers::after;
+ my $caller = $CALLER;
+
+ return sub {
+ my $code = pop;
+ my $class = $caller->meta;
+
+ for (@_) {
+ $class->add_after_method_modifier($_ => $code);
+ }
+ };
},
around => sub {
- return \&Class::Method::Modifiers::around;
+ my $caller = $CALLER;
+
+ return sub {
+ my $code = pop;
+ my $class = $caller->meta;
+
+ for (@_) {
+ $class->add_around_method_modifier($_ => $code);
+ }
+ };
},
with => sub {
use Carp 'confess';
use MRO::Compat;
+use Class::Method::Modifiers ();
do {
my %METACLASS_CACHE;
sub attribute_metaclass { "Mouse::Meta::Class" }
+sub add_before_method_modifier {
+ my ($self, $name, $code) = @_;
+ Class::Method::Modifiers::_install_modifier(
+ $self->name,
+ 'before',
+ $name,
+ $code,
+ );
+}
+
+sub add_around_method_modifier {
+ my ($self, $name, $code) = @_;
+ Class::Method::Modifiers::_install_modifier(
+ $self->name,
+ 'around',
+ $name,
+ $code,
+ );
+}
+
+sub add_after_method_modifier {
+ my ($self, $name, $code) = @_;
+ Class::Method::Modifiers::_install_modifier(
+ $self->name,
+ 'after',
+ $name,
+ $code,
+ );
+}
+
1;
__END__