line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Filter::Macro; |
2
|
|
|
|
|
|
|
$Filter::Macro::VERSION = '0.11'; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
12753
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
88
|
|
5
|
|
|
|
|
|
|
use Filter::Simple::Compile sub { |
6
|
0
|
|
|
|
|
|
$_ = quotemeta($_); |
7
|
0
|
|
|
|
|
|
s/\\\n/\n/g; |
8
|
0
|
|
|
|
|
|
$_ = sprintf(q( |
9
|
|
|
|
|
|
|
use Filter::Simple::Compile sub { |
10
|
|
|
|
|
|
|
$_ = join("\n", |
11
|
|
|
|
|
|
|
'#line '.(__LINE__+1).' '.__FILE__, |
12
|
|
|
|
|
|
|
"%s", |
13
|
|
|
|
|
|
|
'#line %s %s', |
14
|
|
|
|
|
|
|
$_, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
1; |
18
|
|
|
|
|
|
|
), $_, (caller(6))[2]+1, (caller(6))[1]); |
19
|
1
|
|
|
1
|
|
1525
|
}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 NAME |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Filter::Macro - Make macro modules that are expanded inline |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 VERSION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This document describes version 0.11 of Filter::Macro, released |
30
|
|
|
|
|
|
|
May 11, 2006. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
In F: |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
package MyHandyModules; |
37
|
|
|
|
|
|
|
use Filter::Macro; |
38
|
|
|
|
|
|
|
# lines below will be expanded into caller's code |
39
|
|
|
|
|
|
|
use strict; |
40
|
|
|
|
|
|
|
use warnings; |
41
|
|
|
|
|
|
|
use Switch; |
42
|
|
|
|
|
|
|
use IO::All; |
43
|
|
|
|
|
|
|
use Quantum::Superpositions; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
In your program or module: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use MyHandyModules; # lines above are expanded here |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 DESCRIPTION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
If many of your programs begin with the same lines, it may make sense to |
52
|
|
|
|
|
|
|
abstract them away into a module, and C |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Sadly, it does not work that way, because by default, all lexical pragmas, |
55
|
|
|
|
|
|
|
source filters and subroutine imports invoked in F takes |
56
|
|
|
|
|
|
|
effect in that module, I the calling programs. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
One way to solve this problem is to use B: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use Filter::Include; |
61
|
|
|
|
|
|
|
include MyHandyModules; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
However, it would be really nice if F could define the |
64
|
|
|
|
|
|
|
macro-like semantic itself, instead of placing the burden on the caller. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This module lets you do precisely that. All you need to do is to put one |
67
|
|
|
|
|
|
|
line in F, after the C line: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
use Filter::Macro; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
With this, a program or module that says C |
72
|
|
|
|
|
|
|
lines below C |
73
|
|
|
|
|
|
|
semantic of evaluating them in the C package. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Line numbers in error and warning messages are unaffected by this module; |
76
|
|
|
|
|
|
|
they still point to the correct file name and line numbers. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SEE ALSO |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
L, L |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHORS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Audrey Tang Ecpan@audreyt.orgE |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Based on Damian Conway's concept, covered in his excellent I
|
87
|
|
|
|
|
|
|
Advanced Technologies> talk. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 COPYRIGHT (The "MIT" License) |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Copyright 2004, 2006 by Audrey Tang Ecpan@audreyt.orgE. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
94
|
|
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal |
95
|
|
|
|
|
|
|
in the Software without restriction, including without limitation the rights |
96
|
|
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
97
|
|
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is fur- |
98
|
|
|
|
|
|
|
nished to do so, subject to the following conditions: |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in |
101
|
|
|
|
|
|
|
all copies or substantial portions of the Software. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
104
|
|
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- |
105
|
|
|
|
|
|
|
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X |
106
|
|
|
|
|
|
|
CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
107
|
|
|
|
|
|
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
108
|
|
|
|
|
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |