NAME
Filter::Macro - Make macro modules that are expanded inline
SYNOPSIS
In MyHandyModules.pm:
package MyHandyModules;
use Filter::Macro';
# lines below will be expanded into caller's code
use strict;
use warnings;
use Switch;
use IO::All;
use Quantum::Superpositions;
In your program or module:
use MyHandyModules; # lines above are expanded here
DESCRIPTION
If many of your programs begin with the same six or ten lines, it may make sense to abstract them away into a module, and use
that module instead.
Sadly, it does not work that way, because all lexical pragmas, source filters, subroutines etc defined in MyHandyModules.pm takes effect in that module, not the original program with use MyHandyModules;
.
One way to solve this problem is to use Filter::Include:
use Filter::Include;
include MyHandyModules;
However, it would be really nice if MyHandyModules.pm could define the macro-like semantic itself, instead of placing the burden on the caller.
This module lets you do precisely that. All you need to do is to put one line in MyHandyModules.pm, after the package MyHandyModules;
line:
use Filter::Macro;
With this, any program or module that says use Filter::Macro
will expand everything below use Filter::Macro
into their own code, instead of the default semantic of evaluating them in the MyHandyModules
package.
Line numbers in error and warning messages are unaffected by this semantic change; they still point to the correct file name and line numbers.
SEE ALSO
Filter::Include, Filter::Simple
AUTHORS
Autrijus Tang <autrijus@autrijus.org>
Based on Damian Conway's concept, covered in his excellent Sufficiently Advanced Technology talk.
COPYRIGHT
Copyright 2004 by Autrijus Tang <autrijus@autrijus.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.