From: Vincent Pit Date: Mon, 5 Nov 2012 14:08:31 +0000 (-0200) Subject: Implement ->yield X-Git-Tag: v0.02~10 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=e8b777e025ed69b121b659618d6d6451541cee5a;p=perl%2Fmodules%2FScope-Context.git Implement ->yield Scope::Upper 0.21 is required. --- diff --git a/Makefile.PL b/Makefile.PL index aff57ea..13a0c2b 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,7 +12,7 @@ my $dist = 'Scope-Context'; $file = "lib/$file.pm"; my %PREREQ_PM = ( - 'Scope::Upper' => '0.18', + 'Scope::Upper' => '0.21', 'Scalar::Util' => 0, ); diff --git a/lib/Scope/Context.pm b/lib/Scope/Context.pm index f455bf1..85fd573 100644 --- a/lib/Scope/Context.pm +++ b/lib/Scope/Context.pm @@ -8,7 +8,7 @@ use warnings; use Carp (); use Scalar::Util (); -use Scope::Upper 0.18 (); +use Scope::Upper 0.21 (); =head1 NAME @@ -425,6 +425,24 @@ sub unwind { Scope::Upper::unwind(@_ => $self->cxt); } +=head2 C + + $cxt->yield(@values); + +Immediately returns the scalars listed in C<@values> from the topic context, whatever it may be (except a substitution eval context). + +See L for details. + +=cut + +sub yield { + my $self = shift; + + $self->assert_valid; + + Scope::Upper::yield(@_ => $self->cxt); +} + =head2 C my @ret = $cxt->uplevel($code, @args); @@ -448,7 +466,7 @@ sub uplevel { L (core module since perl 5), L (since 5.7.3). -L 0.18. +L 0.21. =head1 SEE ALSO diff --git a/t/02-can.t b/t/02-can.t index ecae9f4..5af4e46 100644 --- a/t/02-can.t +++ b/t/02-can.t @@ -11,7 +11,9 @@ my @methods = qw< uid is_valid assert_valid want up sub eval - reap localize localize_elem localize_delete unwind uplevel + reap localize localize_elem localize_delete + unwind yield + uplevel >; plan tests => scalar(@methods); diff --git a/t/12-actions.t b/t/12-actions.t index a8c4b14..7aaec94 100644 --- a/t/12-actions.t +++ b/t/12-actions.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 4 * 3 + 2; +use Test::More tests => 4 * 3 + 3; use Scope::Context; @@ -86,6 +86,19 @@ use Scope::Context; is_deeply \@res, [ 1, 2, 3 ], 'unwind: done'; } +{ + my @res = do { + sub { + my $up = Scope::Context->up; + $up->yield(4, 5, 6); + fail 'yield: not reached 1'; + }->(); + fail 'yield: not reached 2'; + return qw; + }; + is_deeply \@res, [ 4, 5, 6 ], 'yield: done'; +} + { sub outer { inner(@_); diff --git a/t/13-valid.t b/t/13-valid.t index 1a566f0..fa7d30e 100644 --- a/t/13-valid.t +++ b/t/13-valid.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 4 + 9; +use Test::More tests => 4 + 10; use Scope::Context; @@ -23,7 +23,9 @@ my $fail_rx = qr/^Context has expired at \Q$0\E line [0-9]+/; my @methods = qw< up sub eval - reap localize localize_elem localize_delete unwind uplevel + reap localize localize_elem localize_delete + unwind yield + uplevel >; for my $action (@methods) { local $@;