If C<$from> is omitted in any of those functions, the current level is used as the reference level.
+=head2 C<SCOPE $stack>
+
+The C<$stack>-th upper frame.
+
=head2 C<CALLER $stack>
The level of the C<$stack>-th upper subroutine/eval/format context.
The functions L</reap>, L</localize>, L</localize_elem>, L</localize_delete>, L</unwind> and L</want_at> are only exported on request, either individually or by the tags C<':funcs'> and C<':all'>.
-Same goes for the words L</TOP>, L</HERE>, L</UP>, L</SUB>, L</EVAL> and L</CALLER> that are only exported on request, individually or by the tags C<':words'> and C<':all'>.
+Same goes for the words L</TOP>, L</HERE>, L</UP>, L</SUB>, L</EVAL>, L</SCOPE> and L</CALLER> that are only exported on request, individually or by the tags C<':words'> and C<':all'>.
=cut
our @EXPORT = ();
our %EXPORT_TAGS = (
funcs => [ qw/reap localize localize_elem localize_delete unwind want_at/ ],
- words => [ qw/TOP HERE UP SUB EVAL CALLER/ ],
+ words => [ qw/TOP HERE UP SUB EVAL SCOPE CALLER/ ],
);
our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
$EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
use strict;
use warnings;
-use Test::More tests => 42;
+use Test::More tests => 29 + 13 * 2;
use Scope::Upper qw/:words/;
} while (0);
{
- is CALLER, 0, '{ } : caller';
- is CALLER(0), 0, '{ } : caller 0';
- is CALLER(1), 0, '{ } : caller 1';
+ is SCOPE, 1, 'block : scope';
+ is SCOPE(0), 1, 'block : scope 0';
+ is SCOPE(1), 0, 'block : scope 1';
+ is CALLER, 0, 'block: caller';
+ is CALLER(0), 0, 'block : caller 0';
+ is CALLER(1), 0, 'block : caller 1';
sub {
- is CALLER, 2, '{ sub { } } : caller';
- is CALLER(0), 2, '{ sub { } } : caller 0';
- is CALLER(1), 0, '{ sub { } } : caller 1';
+ is SCOPE, 2, 'block sub : scope';
+ is SCOPE(0), 2, 'block sub : scope 0';
+ is SCOPE(1), 1, 'block sub : scope 1';
+ is CALLER, 2, 'block sub : caller';
+ is CALLER(0), 2, 'block sub : caller 0';
+ is CALLER(1), 0, 'block sub : caller 1';
for (1) {
- is CALLER, 2, '{ sub { for { } } } : caller';
- is CALLER(0), 2, '{ sub { for { } } } : caller 0';
- is CALLER(1), 0, '{ sub { for { } } } : caller 1';
+ is SCOPE, 3, 'block sub for : scope';
+ is SCOPE(0), 3, 'block sub for : scope 0';
+ is SCOPE(1), 2, 'block sub for : scope 1';
+ is CALLER, 2, 'block sub for : caller';
+ is CALLER(0), 2, 'block sub for : caller 0';
+ is CALLER(1), 0, 'block sub for : caller 1';
eval {
- is CALLER, 4, '{ sub { for { eval { } } } } : caller';
- is CALLER(0), 4, '{ sub { for { eval { } } } } : caller 0';
- is CALLER(1), 2, '{ sub { for { eval { } } } } : caller 1';
- is CALLER(2), 0, '{ sub { for { eval { } } } } : caller 2';
+ is SCOPE, 4, 'block sub for eval : scope';
+ is SCOPE(0), 4, 'block sub for eval : scope 0';
+ is SCOPE(1), 3, 'block sub for eval : scope 1';
+ is SCOPE(2), 2, 'block sub for eval : scope 2';
+ is CALLER, 4, 'block sub for eval : caller';
+ is CALLER(0), 4, 'block sub for eval : caller 0';
+ is CALLER(1), 2, 'block sub for eval : caller 1';
+ is CALLER(2), 0, 'block sub for eval : caller 2';
}
}
}->();