Call::Immediate - Export subs that are called as soon as they are seen at compile time
package MyModule; sub class { # muck around with symbol tables and stuff } # still have to export manually use Exporter; use base 'Exporter'; our @EXPORT = qw<class>; # Use this module to have them executed immediately # when they are seen. # ALWAYS use this module at the END of your module definition! use Call::Immediate qw<class>;
This module installs a very simple source filter that causes the subs you specify to be called as soon as they are seen, like macros (but ones that don't substitute any text). This allows you to create slightly more natural constructs like:
class Foo => sub { ... };
As soon as this is seen in the user's file, your class sub will be executed, so that you can mess with the symbol table and affect compilation of the rest of the file if you like.
class
This is implemented by scanning for the subs you specify in the left column (permitting optional whitespace before it) and replacing it with a "use" declaration. Specifically, the call you see above would be turned into:
use Call::Immediate::Call class Foo => sub { ... };
Where Call::Immedate::Call is a module that simply does nothing on import.
Call::Immedate::Call
Luke Palmer <lrpalmer at gmail dot com>
To install Call::Immediate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Call::Immediate
CPAN shell
perl -MCPAN -e shell install Call::Immediate
For more information on module installation, please visit the detailed CPAN module installation guide.