File Coverage

blib/lib/Simple/Filter/Macro.pm
Criterion Covered Total %
statement 9 11 81.8
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 14 85.7


line stmt bran cond sub pod time code
1             package Simple::Filter::Macro;
2              
3             # Set the VERSION.
4             $VERSION = "0.06";
5              
6             # Load the Perl pragmas.
7 1     1   68436 use strict;
  1         3  
  1         28  
8 1     1   5 use warnings;
  1         1  
  1         110  
9              
10             # --------------------------------------------------------------------------- #
11             # The outer value of $_ is the content from the module. The inner value of #
12             # $_ is the content from the script. The Perl function caller is used as #
13             # follows. E.g. one can write my ($package, $filename, $line) = caller($i) #
14             # where $i is the level of interest. The elements of the array can be reached #
15             # as it is known by caller(0)[0] which results the package name of level 0. #
16             # caller(5) returns the data from the module and caller(6) returns the data #
17             # from the script. #
18             # --------------------------------------------------------------------------- #
19              
20             # Outer filter starts here.
21             use Filter::Simple::Compile sub {
22             # Remove the module terminator from the module content.
23 0           $_ =~ s/1;\s//g;
24             # Create the modified script content.
25 0           $_ = sprintf(
26             # Create a single-quoted string for output.
27             q(
28             # Inner filter starts here.
29             use Filter::Simple::Compile sub {
30             # Concatenate content from module and script.
31             $_ = join("\n",
32             '# Line %s %s', "%s", '# Line %s %s',
33             $_,
34             );
35             };
36             # Inner filter ends here.
37             1;
38             ), (caller(5))[2], (caller(5))[1],
39             $_,
40             (caller(6))[2], (caller(6))[1]);
41 1     1   469 };
  1         6413  
  1         8  
42             # Outer filter ends here.
43             1;
44              
45             __END__