Skip to content

Commit e864f30

Browse files
committed
Update the caller 5-to-6 info
1 parent 8bd9ff0 commit e864f30

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

doc/Language/5to6-perlfunc.pod6

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,28 @@ L<here|/language/control#proceed_and_succeed>.
167167
168168
=item caller EXPR
169169
170-
[NEEDS FURTHER RESEARCH] What C<caller> does in Perl 5 is taken on by
171-
C<callframe>. However, a simple call to C<callframe> will be of little
172-
use, as it will return a CallFrame object, rather than any useful
173-
information. The filename and line number returned as the second and
174-
third values from C<caller> in Perl 5, are in C<callframe.annotations>.
175-
You get them by using C<< callframe().annotations.<file line> >> or,
176-
individually, with C<< callframe().annotations.<file> >> and C<<
177-
callframe().annotations.<line> >>. There does not seem to be a simple
178-
way of getting the package name out of C<callframe> however.
170+
There are a couple different ways to get at caller information in Perl 6.
171+
The basic functionality is provided through L<callframe> now. However, Perl 6
172+
constructs call frames for regular blocks, not just for subroutines, so there
173+
are more frames to look through. The following will retrieve the basic
174+
information that C<caller> can return:
175+
176+
my $frame = callframe(0); # OR just callframe()
177+
my ($subroutine, $package);
178+
if $frame.code ~~ Routine {
179+
$subroutine = $frame.code.name;
180+
$package = $frame.code.package;
181+
}
182+
my $file = $frame.file;
183+
my $line = $frame.line;
184+
185+
Many of the other details returned by C<caller> are specific to Perl 5 and have
186+
no meaning in Perl 6.
187+
188+
You can also get some of the information for the current frame or routine frame
189+
by using the dynamic variables L<&?ROUTINE>, L<&?BLOCK>, L<$?PACKAGE>,
190+
L<$?FILE>, and L<$?LINE>. For many purposes, L<Backtrace> may provide an easier
191+
way to browse through the call stack.
179192
180193
=head2 chdir
181194

0 commit comments

Comments
 (0)