NAME

Devel::CompileLevel - Detect caller level of compiling code

SYNOPSIS

package ExportToCompile;
use strict;
use warnings;
use Devel::CompileLevel qw(compile_caller);

sub import {
  my $target = compile_caller or die "not compiling!";
  strict->import;
  warnings->import;
  no strict 'refs';
  # will export to same level as strict/warnings are applied to
  *{"${target}::exported_sub"} = sub { ... };
}

DESCRIPTION

Detects the caller level where compilation is being performed. When applying pragmas in an import sub, they will be applied to the currently compiling scope. Some modules may want to both apply a pragma, and export functions. This requires knowing the package in that scope. It's usually possible to track this manually, but that won't always be accurate.

This module can provide the caller level where compilation is happening, allowing you to always find the correct package.

FUNCTIONS

compile_level ()

Returns the distance to the code being compiled. This will start at 0 in a BEGIN block and increase for each sub call away. In an import sub, it will be 1 rather than the 0 that would normally be used with caller to find the caller's information. You must subtract 1 from this value to use it with caller.

compile_caller ()

Returns the caller information of the compiling code. This will give all the same information as the normal caller() builtin.

SEE ALSO

AUTHOR

haarg - Graham Knop (cpan:HAARG) <haarg@haarg.org>

CONTRIBUTORS

None yet.

COPYRIGHT

Copyright (c) 2015 the Devel::CompileLevel "AUTHOR" and "CONTRIBUTORS" as listed above.

LICENSE

This library is free software and may be distributed under the same terms as perl itself.