/
README
108 lines (81 loc) · 3.49 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
NAME
Devel::Hints - Access compile-time hints at runtime
VERSION
This document describes version 0.21 of Devel::Hints, released November
10, 2010.
SYNOPSIS
use Devel::Hints ':all';
LABEL:
print cop_label(); # 'LABEL'
# cop_label is only settable on Perl 5.8 or below
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__
# cop_warnings() is only available to Perl 5.8 or below
use warnings;
print cop_warnings(); # same as compile-time ${^WARNING_BITS}
# cop_io() is only available to Perl 5.7 and Perl 5.8
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"
}
DESCRIPTION
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.
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.
On perl 5.10 or greater, the first argument to these functions can also
be a coderef. In that case, they return the value for the first
statement in the coderef's body, and if an argument is passed, they set
the value for the entire coderef body. "cop_line" and "cop_file" are
slightly special here - #line directives within the coderef will still
be respected, and the line will be offset by the correct amount within
the sub.
FUNCTIONS
cop_label
Label for the current construct.
cop_file
File name for the current source file.
cop_filegv
Glob reference to the current source filehandle.
cop_stashpv
The current package name.
cop_stash
Hash reference to the current symbol table.
cop_seq
Parse sequencial number.
cop_arybase
Array base the calling line was compiled with.
cop_line
The line number.
cop_warnings
Lexical warnings bitmask, a.k.a. "${^WARNING_BITS}". If no lexical
warnings are in effect, returns the global warning flags as an
integer.
cop_io
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.
ACKNOWLEDGMENTS
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.
AUTHORS
唐鳳 <cpan@audreyt.org>
CC0 1.0 Universal
To the extent possible under law, 唐鳳 has waived all copyright and
related or neighboring rights to Devel-Hints.
This work is published from Taiwan.
<http://creativecommons.org/publicdomain/zero/1.0>