2 subs::auto - Read barewords as subroutine names.
10 foo; # Compile to "foo()" instead of "'foo'"
11 # or croaking on strict subs
12 foo $x; # Compile to "foo($x)" instead of "$x->foo"
13 foo 1; # Compile to "foo(1)" instead of croaking
14 foo 1, 2; # Compile to "foo(1, 2)" instead of croaking
16 foo->meth; # "'foo'->meth" if you have use'd foo somewhere,
17 # or "foo()->meth" otherwise
18 print foo 'wut'; # print to the filehandle foo if it's actually one,
19 # or "foo()->print('wut')" otherwise
20 } # ... but function calls will fail at run-time if you don't
21 # actually define foo somewhere
26 This pragma lexically enables the parsing of any bareword as a
27 subroutine name, except those which corresponds to an entry in %INC
28 (expected to be class names) or whose symbol table entry has a IO slot
29 (expected to be filehandles).
31 You can pass options to "import" as key / value pairs :
35 Specifies on which package the pragma should act. Setting $pkg to
36 "Some::Package" allows you to resolve all functions name of the type
37 "Some::Package::func ..." in the current scope. You can use the
38 pragma several times with different package names to allow
39 resolution of all the corresponding barewords. Defaults to the
46 "*{'::foo'}{CODE}" will appear as defined in a scope where the pragma is
47 enabled, "foo" is used as a bareword, but is never actually defined
48 afterwards. This may or may not be considered as Doing The Right Thing.
49 However, "*{'::foo'}{CODE}" will always return the right value if you
50 fetch it outside the pragma's scope. Actually, you can make it return
51 the right value even in the pragma's scope by reading "*{'::foo'}{CODE}"
52 outside (or by actually defining "foo", which is ultimately why you use
53 this pragma, right ?).
55 You have to open global filehandles outside of the scope of this pragma
56 if you want them not to be treated as function calls. Or just use
57 lexical filehandles and default ones as you should be.
62 Carp (standard since perl 5), Symbol (since 5.002).
64 Variable::Magic with "uvar" magic enabled (this should be assured by the
65 required perl version).
68 Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
70 You can contact me by mail or on #perl @ FreeNode (vincent or
74 Please report any bugs or feature requests to "bug-subs-auto at
75 rt.cpan.org", or through the web interface at
76 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=subs-auto>. I will be
77 notified, and then you'll automatically be notified of progress on your
78 bug as I make changes.
81 You can find documentation for this module with the perldoc command.
85 Tests code coverage report is available at
86 <http://www.profvince.com/perl/cover/subs-auto>.
89 Thanks to Sebastien Aperghis-Tramoni for helping to name this pragma.
92 Copyright 2008 Vincent Pit, all rights reserved.
94 This program is free software; you can redistribute it and/or modify it
95 under the same terms as Perl itself.