sub super {
# This check avoids a recursion loop - see
# t/100_bugs/020_super_recursion.t
- return if defined $SUPER_PACKAGE && $SUPER_PACKAGE ne caller();
- return unless $SUPER_BODY; $SUPER_BODY->(@SUPER_ARGS);
+ return if defined $SUPER_PACKAGE && $SUPER_PACKAGE ne caller();
+ return if !defined $SUPER_BODY;
+ $SUPER_BODY->(@SUPER_ARGS);
}
sub override {
- my $meta = Mouse::Meta::Class->initialize(caller);
- my $pkg = $meta->name;
-
- my $name = shift;
- my $code = shift;
-
- my $body = $pkg->can($name)
- or confess "You cannot override '$name' because it has no super method";
-
- $meta->add_method($name => sub {
- local $SUPER_PACKAGE = $pkg;
- local @SUPER_ARGS = @_;
- local $SUPER_BODY = $body;
-
- $code->(@_);
- });
+ # my($name, $method) = @_;
+ Mouse::Meta::Class->initialize(scalar caller)->add_override_method_modifier(@_);
}
sub inner { not_supported }
sub add_override_method_modifier {
my ($self, $name, $code) = @_;
+ if($self->has_method($name)){\r
+ $self->throw_error("Cannot add an override method if a local method is already present");\r
+ }
+
my $package = $self->name;
- my $body = $package->can($name)
+ my $super_body = $package->can($name)
or $self->throw_error("You cannot override '$name' because it has no super method");
- $self->add_method($name => sub { $code->($package, $body, @_) });
+ $self->add_method($name => sub {
+ local $Mouse::SUPER_PACKAGE = $package;
+ local $Mouse::SUPER_BODY = $super_body;
+ local @Mouse::SUPER_ARGS = @_;
+
+ $code->(@_);
+ });
+ return;
}
sub does_role {
sub super {
- return unless $Mouse::SUPER_BODY;
+ return if !defined $Mouse::SUPER_BODY;
$Mouse::SUPER_BODY->(@Mouse::SUPER_ARGS);
}
sub override {
- my $classname = caller;
- my $meta = Mouse::Meta::Role->initialize($classname);
-
- my $name = shift;
- my $code = shift;
- my $fullname = "${classname}::${name}";
-
- defined &$fullname
- && $meta->throw_error("Cannot add an override of method '$fullname' "
- . "because there is a local version of '$fullname'");
-
- $meta->add_override_method_modifier($name => sub {
- local $Mouse::SUPER_PACKAGE = shift;
- local $Mouse::SUPER_BODY = shift;
- local @Mouse::SUPER_ARGS = @_;
-
- $code->(@_);
- });
+ # my($name, $code) = @_;
+ Mouse::Meta::Role->initialize(scalar caller)->add_override_method_modifier(@_);
}
# We keep the same errors messages as Moose::Role emits, here.