Skip to content
Browse files

preserve original context

  • Loading branch information...
1 parent be9e336 commit 68b448f4cf8b059ceea6204335cb2a7dcc2e9cb8 @clkao committed Jan 16, 2011
Showing with 110 additions and 0 deletions.
  1. +1 −0 invoker.xs
  2. +109 −0 t/02context.t
View
1 invoker.xs
@@ -75,6 +75,7 @@ invoker_ck_gt(pTHX_ OP *o, void *ud) {
}
// warn("self next = %p %s", self->op_next, PL_op_name[self->op_next->op_type]);
+ right->op_flags &= (~OPf_WANT | ( o->op_flags & OPf_WANT));
return right;
}
View
109 t/02context.t
@@ -0,0 +1,109 @@
+#!/usr/bin/perl -w
+use strict;
+
+use Test::More;
+
+our @foo;
+
+sub foo {
+ my $c = defined wantarray ? wantarray ? 'list' : 'scalar'
+ : 'void';
+ push @foo, [$c, @_];
+}
+{
+ my $sub = eval q{ sub {
+ use invoker;
+ sub {
+ my $self = shift;
+ $->foo("x", @_);
+ }
+ } };
+ ok($sub);
+ diag $@ if $@;
+
+ my $self = bless {}, 'main';
+ $sub->()->($self, 1,2);
+ scalar $sub->()->($self, 3, 4);
+ map { $_ } $sub->()->($self, 5,6);
+
+ is_deeply(\@foo, [['void', $self, 'x', 1,2],
+ ['scalar', $self, 'x', 3,4],
+ ['list', $self, 'x', 5,6],
+ ]);
+
+}
+
+{
+ @foo = ();
+ my $sub = eval q{ sub {
+ use invoker;
+ sub {
+ my $self = shift;
+ scalar($->foo("x", @_));
+ }
+ } };
+ ok($sub);
+ diag $@ if $@;
+
+ my $self = bless {}, 'main';
+ $sub->()->($self, 1,2);
+ scalar $sub->()->($self, 3, 4);
+ map { $_ } $sub->()->($self, 5,6);
+
+ is_deeply(\@foo, [['scalar', $self, 'x', 1,2],
+ ['scalar', $self, 'x', 3,4],
+ ['scalar', $self, 'x', 5,6],
+ ]);
+}
+
+{
+ @foo = ();
+ my $sub = eval q{ sub {
+ use invoker;
+ sub {
+ my $self = shift;
+ $->foo;
+ }
+ } };
+ ok($sub);
+ diag $@ if $@;
+
+ my $self = bless {}, 'main';
+ $sub->()->($self, 1,2);
+ scalar $sub->()->($self, 3, 4);
+ map { $_ } $sub->()->($self, 5,6);
+
+ is_deeply(\@foo, [['void', $self],
+ ['scalar', $self],
+ ['list', $self],
+ ]);
+
+}
+
+{
+ @foo = ();
+ my $sub = eval q{ sub {
+ use invoker;
+ my $name = "foo";
+ sub {
+ my $self = shift;
+ $->$name;
+ }
+ } };
+ ok($sub);
+ diag $@ if $@;
+
+ my $self = bless {}, 'main';
+ $sub->()->($self, 1,2);
+ scalar $sub->()->($self, 3, 4);
+ map { $_ } $sub->()->($self, 5,6);
+
+ is_deeply(\@foo, [['void', $self],
+ ['scalar', $self],
+ ['list', $self],
+ ]);
+
+}
+
+
+done_testing;

0 comments on commit 68b448f

Please sign in to comment.
Something went wrong with that request. Please try again.