.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "indirect 3pm" .TH indirect 3pm "2014-09-29" "perl v5.20.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" indirect \- Lexically warn about using the indirect method call syntax. .SH "VERSION" .IX Header "VERSION" Version 0.33 .SH "SYNOPSIS" .IX Header "SYNOPSIS" In a script : .PP .Vb 10 \& no indirect; # lexically enables the pragma \& my $x = new Apple 1, 2, 3; # warns \& { \& use indirect; # lexically disables the pragma \& my $y = new Pear; # legit, does not warn \& { \& # lexically specify an hook called for each indirect construct \& no indirect hook => sub { \& die "You really wanted $_[0]\e\->$_[1] at $_[2]:$_[3]" \& }; \& my $z = new Pineapple \*(Aqfresh\*(Aq; # croaks \*(AqYou really wanted...\*(Aq \& } \& } \& try { ... }; # warns if try() hasn\*(Aqt been declared in this package \& \& no indirect \*(Aqfatal\*(Aq; # or \*(Aq:fatal\*(Aq, \*(AqFATAL\*(Aq, \*(Aq:Fatal\*(Aq ... \& if (defied $foo) { ... } # croaks, note the typo .Ve .PP Global uses : .PP .Vb 2 \& # Globally enable the pragma from the command\-line \& perl \-M\-indirect=global \-e \*(Aqmy $x = new Banana;\*(Aq # warns \& \& # Globally enforce the pragma each time perl is executed \& export PERL5OPT="\-M\-indirect=global,fatal" \& perl \-e \*(Aqmy $y = new Coconut;\*(Aq # croaks .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" When enabled, this pragma warns about indirect method calls that are present in your code. .PP The indirect syntax is now considered harmful, since its parsing has many quirks and its use is error prone : when the subroutine \f(CW\*(C`foo\*(C'\fR has not been declared in the current package, \f(CW\*(C`foo $x\*(C'\fR actually compiles to \f(CW\*(C`$x\->foo\*(C'\fR, and \f(CW\*(C`foo { key => 1 }\*(C'\fR to \f(CW\*(C`\*(Aqkey\*(Aq\->foo(1)\*(C'\fR. In , Matt S. Trout gives an example of an undesirable indirect method call on a block that can cause a particularly bewildering error. .PP This pragma currently does not warn for core functions (\f(CW\*(C`print\*(C'\fR, \f(CW\*(C`say\*(C'\fR, \f(CW\*(C`exec\*(C'\fR or \f(CW\*(C`system\*(C'\fR). This may change in the future, or may be added as optional features that would be enabled by passing options to \f(CW\*(C`unimport\*(C'\fR. .PP This module is \fBnot\fR a source filter. .SH "METHODS" .IX Header "METHODS" .ie n .SS """unimport""" .el .SS "\f(CWunimport\fP" .IX Subsection "unimport" .Vb 6 \& no indirect; \& no indirect \*(Aqfatal\*(Aq; \& no indirect hook => sub { my ($obj, $name, $file, $line) = @_; ... }; \& no indirect \*(Aqglobal\*(Aq; \& no indirect \*(Aqglobal, \*(Aqfatal\*(Aq; \& no indirect \*(Aqglobal\*(Aq, hook => sub { ... }; .Ve .PP Magically called when \f(CW\*(C`no indirect @opts\*(C'\fR is encountered. Turns the module on. The policy to apply depends on what is first found in \f(CW@opts\fR : .IP "\(bu" 4 If it is a string that matches \f(CW\*(C`/^:?fatal$/i\*(C'\fR, the compilation will croak when the first indirect method call is found. .Sp This option is mutually exclusive with the \f(CW\*(Aqhook\*(Aq\fR option. .IP "\(bu" 4 If the key/value pair \f(CW\*(C`hook => $hook\*(C'\fR comes first, \f(CW$hook\fR will be called for each error with a string representation of the object as \f(CW$_[0]\fR, the method name as \f(CW$_[1]\fR, the current file as \f(CW$_[2]\fR and the line number as \f(CW$_[3]\fR. If and only if the object is actually a block, \f(CW$_[0]\fR is assured to start by \f(CW\*(Aq{\*(Aq\fR. .Sp This option is mutually exclusive with the \f(CW\*(Aqfatal\*(Aq\fR option. .IP "\(bu" 4 If none of \f(CW\*(C`fatal\*(C'\fR and \f(CW\*(C`hook\*(C'\fR are specified, a warning will be emitted for each indirect method call. .IP "\(bu" 4 If \f(CW@opts\fR contains a string that matches \f(CW\*(C`/^:?global$/i\*(C'\fR, the pragma will be globally enabled for \fBall\fR code compiled after the current \f(CW\*(C`no indirect\*(C'\fR statement, except for code that is in the lexical scope of \f(CW\*(C`use indirect\*(C'\fR. This option may come indifferently before or after the \f(CW\*(C`fatal\*(C'\fR or \f(CW\*(C`hook\*(C'\fR options, in the case they are also passed to \*(L"unimport\*(R". .Sp The global policy applied is the one resulting of the \f(CW\*(C`fatal\*(C'\fR or \f(CW\*(C`hook\*(C'\fR options, thus defaults to a warning when none of those are specified : .Sp .Vb 3 \& no indirect \*(Aqglobal\*(Aq; # warn for any indirect call \& no indirect qw; # die on any indirect call \& no indirect \*(Aqglobal\*(Aq, hook => \e&hook # custom global action .Ve .Sp Note that if another policy is installed by a \f(CW\*(C`no indirect\*(C'\fR statement further in the code, it will overrule the global policy : .Sp .Vb 7 \& no indirect \*(Aqglobal\*(Aq; # warn globally \& { \& no indirect \*(Aqfatal\*(Aq; # throw exceptions for this lexical scope \& ... \& require Some::Module; # the global policy will apply for the \& # compilation phase of this module \& } .Ve .ie n .SS """import""" .el .SS "\f(CWimport\fP" .IX Subsection "import" .Vb 1 \& use indirect; .Ve .PP Magically called at each \f(CW\*(C`use indirect\*(C'\fR. Turns the module off. .PP As explained in \*(L"unimport\*(R"'s description, an \f(CW\*(C`use indirect\*(C'\fR statement will lexically override a global policy previously installed by \f(CW\*(C`no indirect \*(Aqglobal\*(Aq, ...\*(C'\fR (if there's one). .SH "FUNCTIONS" .IX Header "FUNCTIONS" .ie n .SS """msg""" .el .SS "\f(CWmsg\fP" .IX Subsection "msg" .Vb 1 \& my $msg = msg($object, $method, $file, $line); .Ve .PP Returns the default error message that \f(CW\*(C`indirect\*(C'\fR generates when an indirect method call is reported. .SH "CONSTANTS" .IX Header "CONSTANTS" .ie n .SS """I_THREADSAFE""" .el .SS "\f(CWI_THREADSAFE\fP" .IX Subsection "I_THREADSAFE" True iff the module could have been built with thread-safety features enabled. .ie n .SS """I_FORKSAFE""" .el .SS "\f(CWI_FORKSAFE\fP" .IX Subsection "I_FORKSAFE" True iff this module could have been built with fork-safety features enabled. This will always be true except on Windows where it's false for perl 5.10.0 and below . .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" .ie n .SS """Indirect call of method ""%s"" on object ""%s"" at %s line %d.""" .el .SS "\f(CWIndirect call of method ``%s'' on object ``%s'' at %s line %d.\fP" .IX Subsection "Indirect call of method ""%s"" on object ""%s"" at %s line %d." The default warning/exception message thrown when an indirect method call on an object is found. .ie n .SS """Indirect call of method ""%s"" on a block at %s line %d.""" .el .SS "\f(CWIndirect call of method ``%s'' on a block at %s line %d.\fP" .IX Subsection "Indirect call of method ""%s"" on a block at %s line %d." The default warning/exception message thrown when an indirect method call on a block is found. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" .ie n .SS """PERL_INDIRECT_PM_DISABLE""" .el .SS "\f(CWPERL_INDIRECT_PM_DISABLE\fP" .IX Subsection "PERL_INDIRECT_PM_DISABLE" If this environment variable is set to true when the pragma is used for the first time, the \s-1XS\s0 code won't be loaded and, although the \f(CW\*(Aqindirect\*(Aq\fR lexical hint will be set to true in the scope of use, the pragma itself won't do anything. In this case, the pragma will always be considered to be thread-safe, and as such \*(L"I_THREADSAFE\*(R" will be true. This is useful for disabling \f(CW\*(C`indirect\*(C'\fR in production environments. .PP Note that clearing this variable after \f(CW\*(C`indirect\*(C'\fR was loaded has no effect. If you want to re-enable the pragma later, you also need to reload it by deleting the \f(CW\*(Aqindirect.pm\*(Aq\fR entry from \f(CW%INC\fR. .SH "CAVEATS" .IX Header "CAVEATS" The implementation was tweaked to work around several limitations of vanilla \f(CW\*(C`perl\*(C'\fR pragmas : it's thread safe, and does not suffer from a \f(CW\*(C`perl 5.8.x\-5.10.0\*(C'\fR bug that causes all pragmas to propagate into \f(CW\*(C`require\*(C'\fRd scopes. .PP Before \f(CW\*(C`perl\*(C'\fR 5.12, \f(CW\*(C`meth $obj\*(C'\fR (no semicolon) at the end of a file is not seen as an indirect method call, although it is as soon as there is another token before the end (as in \f(CW\*(C`meth $obj;\*(C'\fR or \f(CW\*(C`meth $obj 1\*(C'\fR). If you use \f(CW\*(C`perl\*(C'\fR 5.12 or greater, those constructs are correctly reported. .PP With 5.8 perls, the pragma does not propagate into \f(CW\*(C`eval STRING\*(C'\fR. This is due to a shortcoming in the way perl handles the hints hash, which is addressed in perl 5.10. .PP Indirect constructs that appear in code \f(CW\*(C`eval\*(C'\fR'd during the global destruction phase of a spawned thread or pseudo-fork (the processes used internally for the \f(CW\*(C`fork\*(C'\fR emulation on Windows) are not reported. .PP The search for indirect method calls happens before constant folding. Hence \f(CW\*(C`my $x = new Class if 0\*(C'\fR will be caught. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" perl 5.8.1. .PP A C compiler. This module may happen to build with a \*(C+ compiler as well, but don't rely on it, as no guarantee is made in this regard. .PP Carp (standard since perl 5), XSLoader (since perl 5.6.0). .SH "AUTHOR" .IX Header "AUTHOR" Vincent Pit, \f(CW\*(C`\*(C'\fR, . .PP You can contact me by mail or on \f(CW\*(C`irc.perl.org\*(C'\fR (vincent). .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests to \f(CW\*(C`bug\-indirect at rt.cpan.org\*(C'\fR, or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .SH "SUPPORT" .IX Header "SUPPORT" You can find documentation for this module with the perldoc command. .PP .Vb 1 \& perldoc indirect .Ve .PP Tests code coverage report is available at . .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" Bram, for motivation and advices. .PP Andrew Main and Florian Ragwitz, for testing on real-life code and reporting issues. .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright 2008,2009,2010,2011,2012,2013,2014 Vincent Pit, all rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.