2 indirect - Lexically warn about using the indirect object syntax.
10 my $x = new Apple 1, 2, 3; # warns
13 my $y = new Pear; # ok
15 no indirect hook => sub { die "You really wanted $_[0]\->$_[1]" };
16 my $z = new Pineapple 'fresh'; # croaks 'You really wanted Pineapple->new'
20 if (defied $foo) { ... } # croaks, note the typo
22 # From the command-line
23 perl -M-indirect -e 'my $x = new Banana;' # warns
25 # Or each time perl is ran
26 export PERL5OPT="-M-indirect"
27 perl -e 'my $y = new Coconut;' # warns
30 When enabled (or disabled as some may prefer to say, since you actually
31 turn it on by calling "no indirect"), this pragma warns about indirect
32 object syntax constructs that may have slipped into your code. This
33 syntax is now considered harmful, since its parsing has many quirks and
34 its use is error prone (when "sub" isn't defined, "sub $x" is actually
35 interpreted as "$x->sub").
37 It currently does not warn when the object is enclosed between braces
38 (like "meth { $obj } @args") or for core functions ("print" or "say").
39 This may change in the future, or may be added as optional features that
40 would be enabled by passing options to "unimport".
42 This module is not a source filter.
45 "unimport [ hook => $hook | ':fatal' ]"
46 Magically called when "no indirect @opts" is encountered. Turns the
47 module on. The policy to apply depends on what is first found in @opts :
49 * If it's the string ':fatal', the compilation will croak on the first
52 * If the key/value pair "hook => $hook" comes first, $hook will be
53 called for each error with the object name as $_[0] and the method
56 * Otherwise, a warning will be emitted for each indirect construct.
59 Magically called at each "use indirect". Turns the module off.
63 True iff the module could have been built when thread-safety features.
66 "meth $obj" (no semicolon) at the end of a file won't be seen as an
67 indirect object syntax, although it will as soon as there is another
68 token before the end (as in "meth $obj;" or "meth $obj 1").
70 With 5.8 perls, the pragma does not propagate into "eval STRING". This
71 is due to a shortcoming in the way perl handles the hints hash, which is
72 addressed in perl 5.10.
77 XSLoader (standard since perl 5.006).
80 Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
82 You can contact me by mail or on "irc.perl.org" (vincent).
85 Please report any bugs or feature requests to "bug-indirect at
86 rt.cpan.org", or through the web interface at
87 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=indirect>. I will be
88 notified, and then you'll automatically be notified of progress on your
89 bug as I make changes.
92 You can find documentation for this module with the perldoc command.
96 Tests code coverage report is available at
97 <http://www.profvince.com/perl/cover/indirect>.
100 Bram, for motivation and advices.
103 Copyright 2008-2009 Vincent Pit, all rights reserved.
105 This program is free software; you can redistribute it and/or modify it
106 under the same terms as Perl itself.