NAME

Safe::Caller - A nicer interface to caller() with code execution restriction

SYNOPSIS

use Safe::Caller;

$safe = Safe::Caller->new;
 
package Foo;

foo();
 
sub foo { bar() }
 
sub bar { 
    print $safe->{sub}->();
    if ($safe->called_from_sub('Foo::foo')) { do something }
}

DESCRIPTION

CONSTRUCTOR

new

$safe = Safe::Caller->new(2);

Supplying how many frames to go back while running caller() is optional. By default (if no suitable value is supplied) 2 will be assumed.

METHODS

called_from_pkg

Checks whether the current sub was called within the appropriate package.

$safe->called_from_pkg('main');

Returns 1 on success, 0 on failure.

called_from_file

Checks whether the current sub was called by the appropriate file.

$safe->called_from_file('foobar.pl');

Returns 1 on success, 0 on failure.

called_from_line

Checks whether the current sub was called on the appropriate line.

$safe->called_from_line(13);

Returns 1 on success, 0 on failure.

called_from_sub

Checks whether the current sub was called by the appropriate subroutine.

$safe->called_from_sub('foo');

Returns 1 on success, 0 on failure.

SEE ALSO

caller

AUTHOR

Steven Schubiger <schubiger@cpan.org>

LICENSE

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

See http://www.perl.com/perl/misc/Artistic.html