Skip to content

Commit

Permalink
hijack next::method in the bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevan Little committed Jul 13, 2013
1 parent c14e891 commit 058bfb2
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 11 deletions.
15 changes: 15 additions & 0 deletions lib/mop.pm
Expand Up @@ -88,6 +88,21 @@ sub bootstrap {
# is true.
@{ $Class_stash->get_symbol('@ISA') } = ('mop::object');
}

{
my $old_next_method = \&next::method;
no warnings 'redefine';
*next::method = sub {
my $invocant = shift;
if ( mop::util::has_meta( $invocant ) ) {
$invocant->mop::next::method( @_ )
} else {
$invocant->$old_next_method( @_ )
}
}

}

$BOOTSTRAPPED = 1;
}

Expand Down
2 changes: 1 addition & 1 deletion t/001-examples/001-point.t
Expand Up @@ -38,7 +38,7 @@ class Point3D extends Point {
}

method pack {
my $data = $self->mop::next::method;
my $data = $self->next::method;
$data->{z} = $z;
$data;
}
Expand Down
2 changes: 1 addition & 1 deletion t/001-examples/002-bank-account.t
Expand Up @@ -31,7 +31,7 @@ class CheckingAccount extends BankAccount {
$self->deposit( $overdraft_amount );
}

$self->mop::next::method( $amount );
$self->next::method( $amount );
}
}

Expand Down
2 changes: 1 addition & 1 deletion t/001-examples/006-logger.t
Expand Up @@ -42,7 +42,7 @@ class MyLogger extends Logger {
given ( $level ) {
when ( 'info' ) { my_warn( '<info> ', $msg ) }
default {
$self->mop::next::method( $level, $msg );
$self->next::method( $level, $msg );
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions t/010-basics/006-next-method.t
Expand Up @@ -13,15 +13,15 @@ class Foo {
}

class FooBar extends Foo {
method foo { $self->mop::next::method . "-FOOBAR" }
method foo { $self->next::method . "-FOOBAR" }
}

class FooBarBaz extends FooBar {
method foo { $self->mop::next::method . "-FOOBARBAZ" }
method foo { $self->next::method . "-FOOBARBAZ" }
}

class FooBarBazGorch extends FooBarBaz {
method foo { $self->mop::next::method . "-FOOBARBAZGORCH" }
method foo { $self->next::method . "-FOOBARBAZGORCH" }
}

my $foo = FooBarBazGorch->new;
Expand Down
2 changes: 1 addition & 1 deletion t/200-meta/010-extension.t
Expand Up @@ -28,7 +28,7 @@ class ClassAccessorMeta extends mop::class {
);
}

$self->mop::next::method;
$self->next::method;
}
}

Expand Down
2 changes: 1 addition & 1 deletion t/200-meta/011-more-extensions.t
Expand Up @@ -40,7 +40,7 @@ class ValidatedAccessorMeta extends mop::class {
);
}

$self->mop::next::method;
$self->next::method;
}
}

Expand Down
6 changes: 3 additions & 3 deletions t/ext/Test-BuilderX/Test/BuilderX/Test.pm
Expand Up @@ -68,7 +68,7 @@ class WithReason extends Test::BuilderX::Test::Base {
has $reason is ro;

method status {
my $status = $self->mop::next::method;
my $status = $self->next::method;
$status->{'reason'} = $reason;
$status;
}
Expand All @@ -81,7 +81,7 @@ class Skip extends Test::BuilderX::Test::WithReason {
}

method status {
my $status = $self->mop::next::method;
my $status = $self->next::method;
$status->{'skip'} = 1;
$status;
}
Expand All @@ -96,7 +96,7 @@ class TODO extends Test::BuilderX::Test::WithReason {
}

method status {
my $status = $self->mop::next::method;
my $status = $self->next::method;
$status->{'TODO'} = 1;
$status->{'passed'} = 1;
$status->{'really_passed'} = $self->passed;
Expand Down

0 comments on commit 058bfb2

Please sign in to comment.