subs::auto - Read barewords as subroutine names.
Version 0.06
{ use subs::auto; foo; # Compile to "foo()" instead of "'foo'" # or croaking on strict subs foo $x; # Compile to "foo($x)" instead of "$x->foo" foo 1; # Compile to "foo(1)" instead of croaking foo 1, 2; # Compile to "foo(1, 2)" instead of croaking foo(@a); # Still ok foo->meth; # "'foo'->meth" if you have use'd foo somewhere, # or "foo()->meth" otherwise print foo 'wut'; # print to the filehandle foo if it's actually one, # or "print(foo('wut'))" otherwise } # ... but function calls will fail at run-time if you don't # actually define foo somewhere foo; # BANG
This pragma lexically enables the parsing of any bareword as a subroutine name, except those which corresponds to an entry in %INC (expected to be class names) or whose symbol table entry has an IO slot (expected to be filehandles).
%INC
You can pass options to import as key / value pairs :
import
in => $pkg
Specifies on which package the pragma should act. Setting $pkg to Some::Package allows you to resolve all functions name of the type Some::Package::func ... in the current scope. You can use the pragma several times with different package names to allow resolution of all the corresponding barewords.
$pkg
Some::Package
Some::Package::func ...
Defaults to the current package.
This module is not a source filter.
None.
*{'::foo'}{CODE} will appear as defined in a scope where the pragma is enabled, foo is used as a bareword, but is never actually defined afterwards. This may or may not be considered as Doing The Right Thing. However, *{'::foo'}{CODE} will always return the right value if you fetch it outside the pragma's scope. Actually, you can make it return the right value even in the pragma's scope by reading *{'::foo'}{CODE} outside (or by actually defining foo, which is ultimately why you use this pragma, right ?).
*{'::foo'}{CODE}
foo
You have to open global filehandles outside of the scope of this pragma if you want them not to be treated as function calls. Or just use lexical filehandles and default ones as you should be.
This pragma doesn't propagate into eval STRING.
eval STRING
perl 5.10.0.
Variable::Magic with uvar magic enabled (this should be assured by the required perl version).
uvar
B::Keywords.
Carp (standard since perl 5), XSLoader (since 5.006).
Vincent Pit, <perl at profvince.com>, http://www.profvince.com.
<perl at profvince.com>
You can contact me by mail or on irc.perl.org (vincent).
irc.perl.org
Please report any bugs or feature requests to bug-subs-auto at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=subs-auto. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-subs-auto at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc subs::auto
Tests code coverage report is available at http://www.profvince.com/perl/cover/subs-auto.
Thanks to Sebastien Aperghis-Tramoni for helping to name this pragma.
Copyright 2008,2009,2010 Vincent Pit, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install subs::auto, copy and paste the appropriate command in to your terminal.
cpanm
cpanm subs::auto
CPAN shell
perl -MCPAN -e shell install subs::auto
For more information on module installation, please visit the detailed CPAN module installation guide.