line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Simple::Filter::Macro; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Set the VERSION. |
4
|
|
|
|
|
|
|
$VERSION = "0.08"; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# Load the Perl pragmas. |
7
|
1
|
|
|
1
|
|
69436
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
34
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
119
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- # |
11
|
|
|
|
|
|
|
# Simple::Filter::Macro # |
12
|
|
|
|
|
|
|
# # |
13
|
|
|
|
|
|
|
# In the following code the predefined default input string variable $_ is # |
14
|
|
|
|
|
|
|
# used twice. The outer value of $_ is the content from the module. The inner # |
15
|
|
|
|
|
|
|
# value of $_ is the content from the script. The Perl function caller() is # |
16
|
|
|
|
|
|
|
# used as follows. For example one can write my ($package, $filename, $line) # |
17
|
|
|
|
|
|
|
# = caller($i) where $i is the level in calling of interest. The elements of # |
18
|
|
|
|
|
|
|
# the array can be reached as it is known by e.g. caller(0)[0] which results # |
19
|
|
|
|
|
|
|
# the package name of calling level 0. C returns the data from the # |
20
|
|
|
|
|
|
|
# module and caller(6) returns the data from the script. Data are filename and # |
21
|
|
|
|
|
|
|
# line of appearance in source code. To work as expected the module terminator # |
22
|
|
|
|
|
|
|
# 1; has to be stripped from the module content. In the Perl function join() # |
23
|
|
|
|
|
|
|
# the newline string "\n" is used as separator between module content and # |
24
|
|
|
|
|
|
|
# script content. The Perl function q() simply interprets the merged content # |
25
|
|
|
|
|
|
|
# as a single-quoted string. The Perl function sprintf() creates the new # |
26
|
|
|
|
|
|
|
# content of the compiled file as a multi-line string. # |
27
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- # |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Outer filter starts here. |
30
|
|
|
|
|
|
|
use Filter::Simple::Compile sub { |
31
|
|
|
|
|
|
|
# Remove the module terminator from the module content. |
32
|
0
|
|
|
|
|
|
$_ =~ s/1;\s//g; |
33
|
|
|
|
|
|
|
# Create the modified script content. |
34
|
0
|
|
|
|
|
|
$_ = sprintf( |
35
|
|
|
|
|
|
|
# Create a single-quoted string for output. |
36
|
|
|
|
|
|
|
q( |
37
|
|
|
|
|
|
|
# Inner filter starts here. |
38
|
|
|
|
|
|
|
use Filter::Simple::Compile sub { |
39
|
|
|
|
|
|
|
# Concatenate content from module and script. |
40
|
|
|
|
|
|
|
$_ = join("\n", |
41
|
|
|
|
|
|
|
"#line %s %s", "%s", "#line %s %s", |
42
|
|
|
|
|
|
|
$_, # Script content. |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
# Inner filter ends here. |
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
), (caller(5))[2], (caller(5))[1], |
48
|
|
|
|
|
|
|
$_, # Module content. |
49
|
|
|
|
|
|
|
(caller(6))[2], (caller(6))[1] |
50
|
|
|
|
|
|
|
); |
51
|
1
|
|
|
1
|
|
544
|
}; |
|
1
|
|
|
|
|
6560
|
|
|
1
|
|
|
|
|
10
|
|
52
|
|
|
|
|
|
|
# Outer filter ends here. |
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |