1indirect(3)           User Contributed Perl Documentation          indirect(3)
2
3
4

NAME

6       indirect - Lexically warn about using the indirect object syntax.
7

VERSION

9       Version 0.24
10

SYNOPSIS

12           # In a script
13           no indirect;
14           my $x = new Apple 1, 2, 3; # warns
15           {
16            use indirect;
17            my $y = new Pear; # ok
18            {
19             no indirect hook => sub { die "You really wanted $_[0]\->$_[1] at $_[2]:$_[3]" };
20             my $z = new Pineapple 'fresh'; # croaks 'You really wanted Pineapple->new at blurp.pm:13'
21            }
22           }
23           try { ... }; # warns
24
25           no indirect ':fatal';    # or 'FATAL', or ':Fatal' ...
26           if (defied $foo) { ... } # croaks, note the typo
27
28           # From the command-line
29           perl -M-indirect -e 'my $x = new Banana;' # warns
30
31           # Or each time perl is ran
32           export PERL5OPT="-M-indirect"
33           perl -e 'my $y = new Coconut;' # warns
34

DESCRIPTION

36       When enabled (or disabled as some may prefer to say, since you actually
37       turn it on by calling "no indirect"), this pragma warns about indirect
38       object syntax constructs that may have slipped into your code.
39
40       This syntax is now considered harmful, since its parsing has many
41       quirks and its use is error prone (when "swoosh" is not defined,
42       "swoosh $x" actually compiles to "$x->swoosh").  In
43       http://www.shadowcat.co.uk/blog/matt-s-trout/indirect-but-still-fatal
44       <http://www.shadowcat.co.uk/blog/matt-s-trout/indirect-but-still-
45       fatal>, Matt S. Trout gives an example of an indirect construct that
46       can cause a particularly bewildering error.
47
48       It currently does not warn for core functions ("print", "say", "exec"
49       or "system").  This may change in the future, or may be added as
50       optional features that would be enabled by passing options to
51       "unimport".
52
53       This module is not a source filter.
54

METHODS

56   "unimport [ hook => $hook | ':fatal', 'FATAL', ... ]"
57       Magically called when "no indirect @opts" is encountered.  Turns the
58       module on.  The policy to apply depends on what is first found in @opts
59       :
60
61       ·   If it is a string that matches "/^:?fatal$/i", the compilation will
62           croak on the first indirect syntax met.
63
64       ·   If the key/value pair "hook => $hook" comes first, $hook will be
65           called for each error with a string representation of the object as
66           $_[0], the method name as $_[1], the current file as $_[2] and the
67           line number as $_[3].  If and only if the object is actually a
68           block, $_[0] is assured to start by '{'.
69
70       ·   Otherwise, a warning will be emitted for each indirect construct.
71
72   "import"
73       Magically called at each "use indirect". Turns the module off.
74

FUNCTIONS

76   "msg $object, $method, $file, $line"
77       Returns the default error message generated by "indirect" when an
78       invalid construct is reported.
79

CONSTANTS

81   "I_THREADSAFE"
82       True iff the module could have been built with thread-safety features
83       enabled.
84
85   "I_FORKSAFE"
86       True iff this module could have been built with fork-safety features
87       enabled.  This will always be true except on Windows where it's false
88       for perl 5.10.0 and below .
89

DIAGNOSTICS

91   "Indirect call of method "%s" on object "%s" at %s line %d."
92       The default warning/exception message thrown when an indirect call on
93       an object is found.
94
95   "Indirect call of method "%s" on a block at %s line %d."
96       The default warning/exception message thrown when an indirect call on a
97       block is found.
98

ENVIRONMENT

100   "PERL_INDIRECT_PM_DISABLE"
101       If this environment variable is set to true when the pragma is used for
102       the first time, the XS code won't be loaded and, although the
103       'indirect' lexical hint will be set to true in the scope of use, the
104       pragma itself won't do anything.  In this case, the pragma will always
105       be considered to be thread-safe, and as such "I_THREADSAFE" will be
106       true.  This is useful for disabling "indirect" in production
107       environments.
108
109       Note that clearing this variable after "indirect" was loaded has no
110       effect.  If you want to re-enable the pragma later, you also need to
111       reload it by deleting the 'indirect.pm' entry from %INC.
112

CAVEATS

114       The implementation was tweaked to work around several limitations of
115       vanilla "perl" pragmas : it's thread safe, and does not suffer from a
116       "perl 5.8.x-5.10.0" bug that causes all pragmas to propagate into
117       "require"d scopes.
118
119       Before "perl" 5.12, "meth $obj" (no semicolon) at the end of a file is
120       not seen as an indirect object syntax, although it is as soon as there
121       is another token before the end (as in "meth $obj;" or "meth $obj 1").
122       If you use "perl" 5.12 or greater, those constructs are correctly
123       reported.
124
125       With 5.8 perls, the pragma does not propagate into "eval STRING".  This
126       is due to a shortcoming in the way perl handles the hints hash, which
127       is addressed in perl 5.10.
128
129       The search for indirect method calls happens before constant folding.
130       Hence "my $x = new Class if 0" will be caught.
131

DEPENDENCIES

133       perl 5.8.1.
134
135       A C compiler.  This module may happen to build with a C++ compiler as
136       well, but don't rely on it, as no guarantee is made in this regard.
137
138       XSLoader (standard since perl 5.006).
139

AUTHOR

141       Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
142
143       You can contact me by mail or on "irc.perl.org" (vincent).
144

BUGS

146       Please report any bugs or feature requests to "bug-indirect at
147       rt.cpan.org", or through the web interface at
148       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=indirect>.  I will be
149       notified, and then you'll automatically be notified of progress on your
150       bug as I make changes.
151

SUPPORT

153       You can find documentation for this module with the perldoc command.
154
155           perldoc indirect
156
157       Tests code coverage report is available at
158       <http://www.profvince.com/perl/cover/indirect>.
159

ACKNOWLEDGEMENTS

161       Bram, for motivation and advices.
162
163       Andrew Main and Florian Ragwitz, for testing on real-life code and
164       reporting issues.
165
167       Copyright 2008,2009,2010,2011 Vincent Pit, all rights reserved.
168
169       This program is free software; you can redistribute it and/or modify it
170       under the same terms as Perl itself.
171
172
173
174perl v5.12.3                      2011-07-17                       indirect(3)
Impressum