View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Curtis "Ovid" Poe > Perl6-Caller > Perl6::Caller



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 0.100   Source  


Perl6::Caller - OO caller() interface


Version 0.04


 use Perl6::Caller;

 my $sub         = caller->subroutine;
 my $line_number = caller->line;
 my $is_require  = caller(3)->is_require;


caller ^

 # standard usage
 print "In ",           caller->subroutine,
       " called from ", caller->file,
       " line ",        caller->line;

 # get a caller object
 my $caller = caller;
 my $caller = caller();   # same thing

 # get a caller object for a different stack from
 my $caller = caller(2);  # two stack frames up
 print $caller->package;  # prints the package name

 # enjoy the original flavor
 my @caller = caller;     # original caller behavior
 print $caller[0],        # prints the package name


This module is experimental. It's also alpha. Bug reports and patches welcome.

By default, this module exports the caller function. This automatically returns a new caller object. An optional argument specifies how many stack frames back to skip, just like the CORE::caller function. This lets you do things like this:

 print "In ",           caller->subroutine,
       " called from ", caller->file,
       " line ",        caller->line;

If you do not wish the caller function imported, specify an empty import list and instantiate a new Perl6::Caller object.

 use Perl6::Caller ();
 my $caller = Perl6::Caller->new;
 print $caller->line;

Note: if the results from the module seem strange, please read perldoc -s caller carefully. It has stranger behavior than you might be aware.


The following methods are available on the caller object. They return the same values as documented in perldoc -f caller.

There are no hints and bitmask methods because those are documented as for internal use only.

Note that each of these values will report correctly for when the caller object was created. For example, the following will probably print different line numbers:

 print caller->line;
 sub foo { 
    print caller->line;

However, the following will print the same line numbers:

 my $caller = Perl6::Caller->new;   # everything is relative to here
 print $caller->line;
 sub foo { 
    my $caller = shift;
    print $caller->line;


Most of the time, this package should just work and not interfere with anything else.


Curtis "Ovid" Poe, <>


Thanks to phaylon for helping me revisit a bad design issue with this.


Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.



Copyright 2007 Curtis "Ovid" Poe, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: