line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Filter::PPI; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
3798
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
170
|
|
4
|
2
|
|
|
2
|
|
270661
|
use Filter::Util::Call; |
|
2
|
|
|
|
|
3400
|
|
|
2
|
|
|
|
|
189
|
|
5
|
2
|
|
|
2
|
|
2055
|
use PPI::Document; |
|
2
|
|
|
|
|
407952
|
|
|
2
|
|
|
|
|
82
|
|
6
|
2
|
|
|
2
|
|
24
|
use Scalar::Util; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
108
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
9
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
123
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.00_01'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub import { |
14
|
3
|
|
|
3
|
|
2267
|
my $caller = caller; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
{ |
17
|
2
|
|
|
2
|
|
11
|
no warnings qw/redefine/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
86
|
|
|
3
|
|
|
|
|
5
|
|
18
|
2
|
|
|
2
|
|
12
|
no strict qw/refs/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
97
|
|
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
19
|
*{$caller.'::import'} = sub { |
21
|
2
|
|
|
2
|
|
21
|
my ($class,@args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
24
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
487
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
filter_add (sub { |
27
|
3
|
|
|
3
|
|
224
|
my $status; |
28
|
|
|
|
|
|
|
|
29
|
3
|
50
|
|
|
|
35
|
Carp::confess "Filter error ($status) while reading source" |
30
|
|
|
|
|
|
|
if ($status = filter_read (4096)) < 0; |
31
|
|
|
|
|
|
|
|
32
|
3
|
100
|
|
|
|
31
|
return $status unless $status > 0; |
33
|
|
|
|
|
|
|
|
34
|
2
|
50
|
|
|
|
14
|
my $doc = PPI::Document->new (\$_) or Carp::confess "Source could not be understood by PPI"; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
7008
|
$doc = $class->ppi_filter ($doc,@args); |
37
|
|
|
|
|
|
|
|
38
|
2
|
100
|
66
|
|
|
6779
|
Carp::confess "$class->ppi_filter did not return a document" |
39
|
|
|
|
|
|
|
unless Scalar::Util::blessed $doc && $doc->isa ('PPI::Document'); |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
7
|
$_ = $doc->serialize; |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
261
|
return $status; |
44
|
2
|
|
|
|
|
16
|
}); |
45
|
3
|
|
|
|
|
17
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
140
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=pod |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Filter::PPI - PPI based source filtering |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package MyFilter; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
use Filter::PPI; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub ppi_filter { |
66
|
|
|
|
|
|
|
my ($class,$doc) = @_; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Do funny things to $doc here |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return $doc; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
package MyModule; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
use MyFilter; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# This will get filtered |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This module lets you write perl source filters using PPI to process |
82
|
|
|
|
|
|
|
the source. Compared to other modules used for writing source filters, |
83
|
|
|
|
|
|
|
it is quite simple. You only need to have one method in your class, |
84
|
|
|
|
|
|
|
called ppi_filter. This gets passed the class name, a L |
85
|
|
|
|
|
|
|
object, and any arguments given to import. The method is expected to |
86
|
|
|
|
|
|
|
return a L but not neccesarily the same one. The |
87
|
|
|
|
|
|
|
document returned will be what's used by perl to compile the program. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SEE ALSO |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=over 4 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item L |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item L |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=back |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 BUGS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Most software has bugs. This module probably isn't an exception. |
102
|
|
|
|
|
|
|
If you find a bug please either email me, or add the bug to cpan-RT. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Anders Nor Berle Eberle@cpan.orgE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Copyright 2008 by Anders Nor Berle. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
113
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|