Devel::Hints - Access compile-time hints at runtime
This document describes version 0.11 of Devel::Hints, released December 30, 2005.
use Devel::Hints ':all'; LABEL: print cop_label(); # 'LABEL' cop_label(0 => 'FOO'); # "goto FOO;" is valid after this point! print cop_file(); # same as __FILE__ print cop_filegv(); # same as \$::{'_<' . __FILE__} print cop_stashpv(); # same as __PACKAGE__ print cop_stash(); # same as \%{__PACKAGE__ . '::'} print cop_seq(); # an integer print cop_arybase(); # same as $[ print cop_line(); # same as __LINE__ use warnings; print cop_warnings(); # same as compile-time ${^WARNING_BITS} # cop_io() is only available to Perl 5.7 or above use open IO => ':utf8'; print cop_io(); # same as compile-time ${^OPEN} { use IO => ':raw'; print cop_io(1); # access one uplevel; still ":utf8\0:utf8" }
This module exports the cop (code operator) struct as individual functions; callers can call them to find out the lexical-scoped hints that its block (or statement) is compiled under.
cop
No functions are exported by default. Each function may take an optional positive integer as argument, indicating how many blocks it should walk upward to obtain the cop members.
Functions can also take another optional argument, which (if specified) becomes the new value for the hint, affecting the current statement or block's behaviour.
Label for the current construct.
File name for the current source file.
Glob reference to the current source filehandle.
The current package name.
Hash reference to the current symbol table.
Parse sequencial number.
Array base the calling line was compiled with.
The line number.
Lexical warnings bitmask, a.k.a. ${^WARNING_BITS}. If no lexical warnings are in effect, returns the global warning flags as an integer.
${^WARNING_BITS}
Lexical IO defaults, a.k.a. ${^OPEN}. If no lexical IO layers are in effect, an empty string is returned. Always returns undef under pre-5.7 versions of Perl.
${^OPEN}
undef
Thanks to Rafael Garcia-Suarez for demonstrating how to do this with the elegant Inline::C code on p5p, which I adapted to this less elegant XS implementation.
Audrey Tang <autrijus@autrijus.org>
Copyright 2003, 2005 by Audrey Tang <autrijus@autrijus.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Devel::Hints, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Devel::Hints
CPAN shell
perl -MCPAN -e shell install Devel::Hints
For more information on module installation, please visit the detailed CPAN module installation guide.