=head1 VERSION
-Version 0.18
+Version 0.19
=cut
our $VERSION;
BEGIN {
- $VERSION = '0.18';
+ $VERSION = '0.19';
}
=head1 SYNOPSIS
If C<$what> is a string pointing to an undeclared variable, the variable will be vivified as soon as the localization occurs and emptied when it ends, although it will still exist in its glob.
-=head2 C<localize_delete $what, $key, $context>
+=head2 C<localize_delete>
+
+ localize_delete $what, $key;
+ localize_delete $what, $key, $context;
Introduces the deletion of a variable or an array/hash element delayed to the time of first return into the upper scope denoted by C<$context>.
C<$what> can be:
=head2 C<unwind>
- unwind @values;
+ unwind;
unwind @values, $context;
-Returns C<@values> I<from> the context pointed by C<$context>, i.e. from the subroutine, eval or format at or just above C<$context>, and immediately restart the program flow at this point - thus effectively returning to an upper scope.
+Returns C<@values> I<from> the subroutine, eval or format context pointed by or just above C<$context>, and immediately restart the program flow at this point - thus effectively returning C<@values> to an upper scope.
+If C<@values> is empty, then the C<$context> parameter is optional and defaults to the current context (making the call equivalent to a bare C<return;>) ; otherwise it is mandatory.
The upper context isn't coerced onto C<@values>, which is hence always evaluated in list context.
This means that
will rightfully set C<$num> to C<26>.
-=head2 C<uplevel $code, @args, $context>
+=head2 C<uplevel>
my @ret = uplevel { ...; return @ret };
- my @ret = uplevel { my @args = @_; ...; return @ret } @args;
- my @ret = uplevel { ... } @args, $context;
+ my @ret = uplevel { my @args = @_; ...; return @ret } @args, $context;
my @ret = &uplevel($callback, @args, $context);
-Executes the code reference C<$code> with arguments C<@args> as if it were located at the subroutine stack frame pointed by C<$context>, effectively fooling C<caller> and C<die> into believing that the call actually happened higher in the stack.
+Executes the code reference C<$callback> with arguments C<@args> as if it were located at the subroutine stack frame pointed by C<$context>, effectively fooling C<caller> and C<die> into believing that the call actually happened higher in the stack.
The code is executed in the context of the C<uplevel> call, and what it returns is returned as-is by C<uplevel>.
sub target {
my @inverses = target(1, 2, 4); # @inverses contains (0, 0.5, 0.25)
my $count = target(1, 2, 4); # $count is 3
+Note that if C<@args> is empty, then the C<$context> parameter is optional and defaults to the current context ; otherwise it is mandatory.
+
L<Sub::Uplevel> also implements a pure-Perl version of C<uplevel>.
Both are identical, with the following caveats :
=head1 COPYRIGHT & LICENSE
-Copyright 2008,2009,2010,2011 Vincent Pit, all rights reserved.
+Copyright 2008,2009,2010,2011,2012 Vincent Pit, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.