File Coverage

blib/lib/Filter/ExtractSource.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Filter::ExtractSource;
2              
3 1     1   22457 use warnings;
  1         2  
  1         29  
4 1     1   6 use strict;
  1         1  
  1         34  
5 1     1   995 use Filter::Simple;
  1         30413  
  1         7  
6 1     1   708 use Filter::ExtractSource::CodeObj;
  1         2  
  1         160  
7              
8             our $VERSION = '0.02';
9             our $codeobj = Filter::ExtractSource::CodeObj->new;
10              
11             FILTER {
12             s/^(\s*use .*;)/$1\nuse Filter::ExtractSource;/m;
13             $codeobj->merge(split /use Filter::ExtractSource;\n/);
14             };
15              
16             =head1 NAME
17              
18             Filter::ExtractSource - captures Perl code after processing by source filters
19              
20             =head1 SYNOPSIS
21              
22             perl -c -MFilter::ExtractSource input.pl >output.pl
23              
24             Where F contains Perl code which uses source filters,
25             F will be the code post filtering as passed to the
26             Perl parser.
27              
28             =head1 DESCRIPTION
29              
30             The concept of source filtering allows developers to alter and
31             extend the Perl language with relative ease. One disadvantage
32             however, is that some language extensions can break tools which
33             attempt to parse Perl code, such as editors which perform syntax
34             highlighting.
35              
36             For example, the code
37              
38             use Filter::Indent::HereDoc;
39             my $hello = <
40             Hello, World!
41             EOT
42             print $hello;
43              
44             is perfectly valid, but trying to parse it manually (i.e.
45             without using C) will fail as the C here-document
46             terminator will not be found.
47              
48             After processing by Filter::ExtractSource, the code becomes
49              
50             use Filter::Indent::HereDoc;
51             my $hello = <
52             Hello, World!
53             EOT
54             print $hello;
55              
56             which can now be correctly parsed.
57              
58             =head1 DEPENDENCIES
59              
60             Filter::ExtractSource requires the Filter::Simple module to be installed.
61              
62             =head1 BUGS / ISSUES
63              
64             Possibly lots.
65              
66             Filter::ExtractSource has been tested with the Switch.pm and
67             Filter::Indent::HereDoc source filters with good results. However
68             in particular it has not been tested (and is unlikely to work)
69             with any source filters which perform encryption or obfuscation
70             of Perl code.
71              
72             Any BEGIN blocks, CHECK blocks or use statements will be executed at
73             compile-time (i.e. the code will be executed even when the '-c' switch
74             is used). Therefore any data sent to the STDOUT stream by these blocks
75             will be output before the filtered source code, so in the example above
76             the output.pl file may need to be edited. A future release of
77             Filter::ExtractSource will support writing the modified source code
78             to a file instead of STDOUT to fix this problem.
79              
80             Please report any bugs or feature requests to
81             C, or through the web interface at
82             L. I will be notified, and then you'll automatically
83             be notified of progress on your bug as I make changes.
84              
85             =head1 SEE ALSO
86              
87             Filter::ExtractSource homepage - L
88              
89             Filter::Simple - L
90              
91             perlfilter manpage - L
92              
93             =head1 AUTHOR
94              
95             Written by Jon Allen (JJ) / L
96              
97             =head1 COPYRIGHT and LICENCE
98              
99             Copyright 2004 Jon Allen (JJ), All Rights Reserved.
100              
101             This program is free software; you can redistribute it and/or modify it
102             under the same terms as Perl itself.
103              
104             =cut
105              
106             1; # End of Filter::ExtractSource